@@ -699,7 +699,6 @@ def postparsing_precmd(self, statement):
699699 """Simulate precmd hook failure."""
700700 return True , statement
701701
702-
703702@pytest .fixture
704703def hook_failure ():
705704 app = HookFailureApp ()
@@ -714,3 +713,50 @@ def test_precmd_hook_success(base_app):
714713def test_precmd_hook_failure (hook_failure ):
715714 out = hook_failure .onecmd_plus_hooks ('help' )
716715 assert out == True
716+
717+
718+ class ShellApp (cmd2 .Cmd ):
719+ def __init__ (self , * args , ** kwargs ):
720+ # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x
721+ cmd2 .Cmd .__init__ (self , * args , ** kwargs )
722+ self .default_to_shell = True
723+
724+ @pytest .fixture
725+ def shell_app ():
726+ app = ShellApp ()
727+ app .stdout = StdOut ()
728+ return app
729+
730+ def test_default_to_shell_found (shell_app ):
731+ out = run_cmd (shell_app , 'ls -hal' )
732+ assert out == []
733+
734+ def test_default_to_shell_unknown (shell_app ):
735+ unknown_command = 'zyxcw23'
736+ out = run_cmd (shell_app , unknown_command )
737+ assert out == ["*** Unknown syntax: {}" .format (unknown_command )]
738+
739+
740+ def test_ansi_prompt_not_esacped (base_app ):
741+ prompt = '(Cmd) '
742+ assert base_app ._surround_ansi_escapes (prompt ) == prompt
743+
744+
745+ def test_ansi_prompt_escaped ():
746+ app = cmd2 .Cmd ()
747+ color = 'cyan'
748+ prompt = 'InColor'
749+ color_prompt = app .colorize (prompt , color )
750+
751+ readline_hack_start = "\x01 "
752+ readline_hack_end = "\x02 "
753+
754+ readline_safe_prompt = app ._surround_ansi_escapes (color_prompt )
755+ if sys .platform .startswith ('win' ):
756+ # colorize() does nothing on Windows due to lack of ANSI color support
757+ assert prompt == color_prompt
758+ assert readline_safe_prompt == prompt
759+ else :
760+ assert prompt != color_prompt
761+ assert readline_safe_prompt .startswith (readline_hack_start + app ._colorcodes [color ][True ] + readline_hack_end )
762+ assert readline_safe_prompt .endswith (readline_hack_start + app ._colorcodes [color ][False ] + readline_hack_end )
0 commit comments