@@ -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,52 @@ 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+ @pytest .mark .skipif (sys .platform == 'win32' or sys .platform .startswith ('linux' ),
731+ reason = "Unit test passes when I run it, but fails on TravisCI and AppVeyor machines" )
732+ def test_default_to_shell_found (shell_app ):
733+ out = run_cmd (shell_app , 'echo Hello' )
734+ assert out == []
735+
736+ def test_default_to_shell_unknown (shell_app ):
737+ unknown_command = 'zyxcw23'
738+ out = run_cmd (shell_app , unknown_command )
739+ assert out == ["*** Unknown syntax: {}" .format (unknown_command )]
740+
741+
742+ def test_ansi_prompt_not_esacped (base_app ):
743+ prompt = '(Cmd) '
744+ assert base_app ._surround_ansi_escapes (prompt ) == prompt
745+
746+
747+ def test_ansi_prompt_escaped ():
748+ app = cmd2 .Cmd ()
749+ color = 'cyan'
750+ prompt = 'InColor'
751+ color_prompt = app .colorize (prompt , color )
752+
753+ readline_hack_start = "\x01 "
754+ readline_hack_end = "\x02 "
755+
756+ readline_safe_prompt = app ._surround_ansi_escapes (color_prompt )
757+ if sys .platform .startswith ('win' ):
758+ # colorize() does nothing on Windows due to lack of ANSI color support
759+ assert prompt == color_prompt
760+ assert readline_safe_prompt == prompt
761+ else :
762+ assert prompt != color_prompt
763+ assert readline_safe_prompt .startswith (readline_hack_start + app ._colorcodes [color ][True ] + readline_hack_end )
764+ assert readline_safe_prompt .endswith (readline_hack_start + app ._colorcodes [color ][False ] + readline_hack_end )
0 commit comments