1616def parser ():
1717 parser = StatementParser (
1818 allow_redirection = True ,
19- terminators = [';' ],
19+ terminators = [';' , '&' ],
2020 multiline_commands = ['multiline' ],
2121 aliases = {'helpalias' : 'help' ,
2222 '42' : 'theanswer' ,
@@ -40,6 +40,9 @@ def test_parse_empty_string(parser):
4040 ('42 arg1 arg2' , ['theanswer' , 'arg1' , 'arg2' ]),
4141 ('l' , ['shell' , 'ls' , '-al' ]),
4242 ('termbare ; > /tmp/output' , ['termbare' , ';' , '>' , '/tmp/output' ]),
43+ ('termbare; > /tmp/output' , ['termbare' , ';' , '>' , '/tmp/output' ]),
44+ ('termbare & > /tmp/output' , ['termbare' , '&' , '>' , '/tmp/output' ]),
45+ ('termbare& > /tmp/output' , ['termbare' , '&' , '>' , '/tmp/output' ]),
4346 ('help|less' , ['help' , '|' , 'less' ]),
4447 ('l|less' , ['shell' , 'ls' , '-al' , '|' , 'less' ]),
4548])
@@ -72,24 +75,28 @@ def test_parse_single_word(parser, line):
7275 assert not statement .args
7376 assert statement .argv == [utils .strip_quotes (line )]
7477
75- @pytest .mark .parametrize ('line' , [
76- 'termbare;' ,
77- 'termbare ;' ,
78+ @pytest .mark .parametrize ('line,terminator' , [
79+ ('termbare;' , ';' ),
80+ ('termbare ;' , ';' ),
81+ ('termbare&' , '&' ),
82+ ('termbare &' , '&' ),
7883])
79- def test_parse_word_plus_terminator (parser , line ):
84+ def test_parse_word_plus_terminator (parser , line , terminator ):
8085 statement = parser .parse (line )
8186 assert statement .command == 'termbare'
82- assert statement .terminator == ';'
87+ assert statement .terminator == terminator
8388 assert statement .argv == ['termbare' ]
8489
85- @pytest .mark .parametrize ('line' , [
86- 'termbare; suffx' ,
87- 'termbare ;suffx' ,
90+ @pytest .mark .parametrize ('line,terminator' , [
91+ ('termbare; suffx' , ';' ),
92+ ('termbare ;suffx' , ';' ),
93+ ('termbare& suffx' , '&' ),
94+ ('termbare &suffx' , '&' ),
8895])
89- def test_parse_suffix_after_terminator (parser , line ):
96+ def test_parse_suffix_after_terminator (parser , line , terminator ):
9097 statement = parser .parse (line )
9198 assert statement .command == 'termbare'
92- assert statement .terminator == ';'
99+ assert statement .terminator == terminator
93100 assert statement .suffix == 'suffx'
94101 assert statement .argv == ['termbare' ]
95102
@@ -163,12 +170,12 @@ def test_parse_double_pipe_is_not_a_pipe(parser):
163170 assert not statement .pipe_to
164171
165172def test_parse_complex_pipe (parser ):
166- line = 'command with args, terminator; sufx | piped'
173+ line = 'command with args, terminator& sufx | piped'
167174 statement = parser .parse (line )
168175 assert statement .command == 'command'
169176 assert statement .args == "with args, terminator"
170177 assert statement .argv == ['command' , 'with' , 'args,' , 'terminator' ]
171- assert statement .terminator == '; '
178+ assert statement .terminator == '& '
172179 assert statement .suffix == 'sufx'
173180 assert statement .pipe_to == 'piped'
174181
@@ -251,13 +258,16 @@ def test_parse_unfinished_multiliine_command(parser):
251258 assert statement .argv == ['multiline' , 'has' , '>' , 'inside' , 'an' , 'unfinished' , 'command' ]
252259 assert not statement .terminator
253260
254- def test_parse_multiline_command_ignores_redirectors_within_it (parser ):
255- line = 'multiline has > inside;'
261+ @pytest .mark .parametrize ('line,terminator' ,[
262+ ('multiline has > inside;' , ';' ),
263+ ('multiline has > inside &' , '&' ),
264+ ])
265+ def test_parse_multiline_command_ignores_redirectors_within_it (parser , line , terminator ):
256266 statement = parser .parse (line )
257267 assert statement .multiline_command == 'multiline'
258268 assert statement .args == 'has > inside'
259269 assert statement .argv == ['multiline' , 'has' , '>' , 'inside' ]
260- assert statement .terminator == ';'
270+ assert statement .terminator == terminator
261271
262272def test_parse_multiline_with_incomplete_comment (parser ):
263273 """A terminator within a comment will be ignored and won't terminate a multiline command.
0 commit comments