@@ -2462,6 +2462,16 @@ def test_alias_create(base_app) -> None:
24622462 assert base_app .last_result ['fake' ] == "help"
24632463
24642464
2465+ def test_nested_alias_usage (base_app ) -> None :
2466+ run_cmd (base_app , 'alias create nested help' )
2467+ run_cmd (base_app , 'alias create wrapper nested' )
2468+ nested_out = run_cmd (base_app , "nested" )
2469+ wrapper_out = run_cmd (base_app , "wrapper" )
2470+ help_out = run_cmd (base_app , "help" )
2471+
2472+ assert nested_out == wrapper_out == help_out
2473+
2474+
24652475def test_alias_create_with_quoted_tokens (base_app ) -> None :
24662476 """Demonstrate that quotes in alias value will be preserved"""
24672477 alias_name = "fake"
@@ -2676,6 +2686,19 @@ def test_macro_usage_with_exta_args(base_app) -> None:
26762686 assert "Usage: alias create" in out [0 ]
26772687
26782688
2689+ def test_nested_macro_usage (base_app ) -> None :
2690+ run_cmd (base_app , 'macro create nested help' )
2691+ run_cmd (base_app , 'macro create wrapper nested {1}' )
2692+ nested_out = run_cmd (base_app , "nested" )
2693+ help_out = run_cmd (base_app , "help" )
2694+ assert nested_out == help_out
2695+
2696+ wrapper_out = run_cmd (base_app , "wrapper alias" )
2697+ help_alias_out = run_cmd (base_app , "help alias" )
2698+
2699+ assert wrapper_out == help_alias_out
2700+
2701+
26792702def test_macro_create_with_missing_arg_nums (base_app ) -> None :
26802703 # Create the macro
26812704 _out , err = run_cmd (base_app , 'macro create fake help {1} {3}' )
@@ -2784,25 +2807,35 @@ def test_nonexistent_macro(base_app) -> None:
27842807 # The line of text and whether to continue prompting to finish a multiline command.
27852808 ('line' , 'should_continue' ),
27862809 [
2810+ # Empty lines
27872811 ("" , False ),
27882812 (" " , False ),
2813+ # Single-line commands
27892814 ("help" , False ),
27902815 ("help alias" , False ),
2816+ # Multi-line commands
27912817 ("orate" , True ),
27922818 ("orate;" , False ),
27932819 ("orate\n " , False ),
27942820 ("orate\n arg" , True ),
27952821 ("orate\n arg;" , False ),
27962822 ("orate\n arg\n " , False ),
2823+ # Single-line macros
27972824 ("single_mac" , False ), # macro resolution error returns False (no arg passed)
27982825 ("single_mac arg" , False ),
2826+ # Multi-line macros
27992827 ("multi_mac" , False ), # macro resolution error returns False (no arg passed)
28002828 ("multi_mac arg" , True ),
28012829 ("multi_mac arg;" , False ),
28022830 ("multi_mac arg\n " , False ),
28032831 ("multi_mac\n arg" , True ),
28042832 ("multi_mac\n arg;" , False ),
28052833 ("multi_mac\n arg\n " , False ),
2834+ # Nested multi-line macros
2835+ ("wrapper_mac" , False ), # macro resolution error returns False (no args passed)
2836+ ("wrapper_mac arg" , False ), # macro resolution error returns False (not enough args passed)
2837+ ("wrapper_mac arg arg2" , True ),
2838+ ("wrapper_mac arg\n arg2;" , False ),
28062839 ],
28072840)
28082841def test_should_continue_multiline (multiline_app : MultilineApp , line : str , should_continue : bool ) -> None :
@@ -2814,6 +2847,7 @@ def test_should_continue_multiline(multiline_app: MultilineApp, line: str, shoul
28142847
28152848 run_cmd (multiline_app , "macro create single_mac help {1}" )
28162849 run_cmd (multiline_app , "macro create multi_mac orate {1}" )
2850+ run_cmd (multiline_app , "macro create wrapper_mac multi_mac {1} {2}" )
28172851
28182852 with mock .patch ('cmd2.cmd2.get_app' , return_value = mock_app ):
28192853 assert multiline_app ._should_continue_multiline () is should_continue
0 commit comments