summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-02-24 02:35:52 -0500
committerGitHub <noreply@github.com>2017-02-24 02:35:52 -0500
commit233dc435f3b99b71c48b5f3ecdbafe7718807571 (patch)
tree0ba5ea307d9c4db633233b0a5e14e0b7521647aa
parentb9ac44f889c42631808a4149a81f2e271990b75b (diff)
parent6ad77bed288403b6baa55c781737674f7f7dc49b (diff)
downloadcmd2-git-233dc435f3b99b71c48b5f3ecdbafe7718807571.tar.gz
Merge pull request #56 from python-cmd2/input_redirection_parsing_bug
Input redirection parsing bug
-rwxr-xr-xcmd2.py2
-rw-r--r--tests/test_cmd2.py3
-rw-r--r--tests/test_parsing.py52
3 files changed, 48 insertions, 9 deletions
diff --git a/cmd2.py b/cmd2.py
index 0ac73d9b..057b6390 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -515,7 +515,7 @@ class Cmd(cmd.Cmd):
excludeFromHistory = '''run r list l history hi ed edit li eof'''.split()
kept_state = None
# make sure your terminators are not in legalChars!
- legalChars = u'!#$%.:?@_' + pyparsing.alphanums + pyparsing.alphas8bit
+ legalChars = u'!#$%.:?@_-' + pyparsing.alphanums + pyparsing.alphas8bit
multilineCommands = []
noSpecialParse = 'set ed edit exit'.split()
prefixParser = pyparsing.Empty()
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 6f9afd4d..71757971 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -5,7 +5,6 @@ Cmd2 unit/functional testing
Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com>
Released under MIT license, see LICENSE file
"""
-import getpass
import os
import sys
@@ -347,8 +346,6 @@ def test_allow_redirection(base_app):
assert not os.path.exists(filename)
-@pytest.mark.skipif(sys.platform.startswith('linux') and getpass.getuser() == 'travis',
- reason="Unit test passes on Ubuntu 16.04 and Debian 8.7, but fails on TravisCI Linux containers")
def test_input_redirection(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
filename = os.path.join(test_dir, 'redirect.txt')
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 7186a143..b3b1543d 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -43,6 +43,12 @@ def parser():
c._init_parser()
return c.parser
+@fixture
+def input_parser():
+ c = cmd2.Cmd()
+ c._init_parser()
+ return c.inputParser
+
def test_remaining_args():
assert cmd2.remaining_args('-f bar bar cow', ['bar', 'cow']) == 'bar cow'
@@ -179,16 +185,16 @@ def test_parse_simple_piped(parser):
- command: {0}""".format(command, pipe)
assert parser.parseString('simple | piped').dump() == expected
-def test_parse_doulbe_pipe_is_not_a_pipe(parser):
- command = "double"
- args = "-pipe || is not a pipe"
+def test_parse_double_pipe_is_not_a_pipe(parser):
+ command = "double-pipe"
+ args = "|| is not a pipe"
if new_pyparsing:
command = repr(command)
args = repr(args)
- expected = """['double', '-pipe || is not a pipe']
+ expected = """['double-pipe', '|| is not a pipe']
- args: {1}
- command: {0}
-- statement: ['double', '-pipe || is not a pipe']
+- statement: ['double-pipe', '|| is not a pipe']
- args: {1}
- command: {0}""".format(command, args)
assert parser.parseString('double-pipe || is not a pipe').dump() == expected
@@ -237,6 +243,42 @@ def test_parse_output_redirect(parser):
- command: {0}""".format(command, args, redirect, output)
assert parser.parseString('output into > afile.txt').dump() == expected
+def test_parse_output_redirect_with_dash_in_path(parser):
+ command = "output"
+ args = "into"
+ redirect = ">"
+ output = "python-cmd2/afile.txt"
+ if new_pyparsing:
+ command = repr(command)
+ args = repr(args)
+ redirect = repr(redirect)
+ output = repr(output)
+ expected = """['output', 'into', '>', 'python-cmd2/afile.txt']
+- args: {1}
+- command: {0}
+- output: {2}
+- outputTo: {3}
+- statement: ['output', 'into']
+ - args: {1}
+ - command: {0}""".format(command, args, redirect, output)
+ assert parser.parseString('output into > python-cmd2/afile.txt').dump() == expected
+
+def test_parse_input_redirect(input_parser):
+ input_from = "< afile.txt"
+ if new_pyparsing:
+ input_from = repr(input_from)
+ expected = """['', '< afile.txt']
+- inputFrom: {0}""".format(input_from)
+ assert input_parser.parseString('< afile.txt').dump() == expected
+
+def test_parse_input_redirect_with_dash_in_path(input_parser):
+ input_from = "< python-cmd2/afile.txt"
+ if new_pyparsing:
+ input_from = repr(input_from)
+ expected = """['', '< python-cmd2/afile.txt']
+- inputFrom: {0}""".format(input_from)
+ assert input_parser.parseString('< python-cmd2/afile.txt').dump() == expected
+
def test_parse_pipe_and_redirect(parser):
command = "output"
args = "into"