~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

Implement globbing and enhance cat to accept multiple files.

* bzrlib/tests/test_script.py:
(TestSyntax.test_command_with_single_quoted_param,
TestSyntax.test_command_with_double_quoted_param): Quotes are left
in place during command splitting.
(TestArgumentProcessing): Test quote removal and globbing.
(TestCat.test_cat_files_to_file): Cat accepts multiple files now.

* bzrlib/tests/script.py:
(split): Delay quote removal until the command is ready to be
executed.
(ScriptRunner._pre_process_args): Globbing should happen just
before command execution, which imply that quotes removal should
happen at the same time.
(ScriptRunner.run_command): Process arguments for quote and
globbing just before execution or globbing will not be correct.
(ScriptRunner.do_cat): Allow multiple files to be specified.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.tests import script
23
23
 
24
24
 
25
 
class TestScriptSyntax(tests.TestCase):
 
25
class TestSyntax(tests.TestCase):
26
26
 
27
27
    def test_comment_is_ignored(self):
28
28
        self.assertEquals([], script._script_to_commands('#comment\n'))
36
36
 
37
37
    def test_command_with_single_quoted_param(self):
38
38
        story = """bzr commit -m 'two words'"""
39
 
        self.assertEquals([(['bzr', 'commit', '-m', 'two words'],
 
39
        self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],
40
40
                            None, None, None)],
41
41
                           script._script_to_commands(story))
42
42
 
43
43
    def test_command_with_double_quoted_param(self):
44
44
        story = """bzr commit -m "two words" """
45
 
        self.assertEquals([(['bzr', 'commit', '-m', 'two words'],
 
45
        self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],
46
46
                            None, None, None)],
47
47
                           script._script_to_commands(story))
48
48
 
117
117
 
118
118
 
119
119
 
120
 
class TestScriptExecution(script.TestCaseWithTransportAndScript):
 
120
class TestExecution(script.TestCaseWithTransportAndScript):
121
121
 
122
122
    def test_unknown_command(self):
123
123
        self.assertRaises(SyntaxError, self.run_script, 'foo')
181
181
        self.run_script(story)
182
182
 
183
183
 
 
184
class TestArgumentProcessing(script.TestCaseWithTransportAndScript):
 
185
 
 
186
    def test_globing(self):
 
187
        self.run_script("""
 
188
echo cat >cat
 
189
echo dog >dog
 
190
cat *
 
191
>cat
 
192
>dog
 
193
""")
 
194
 
 
195
    def test_quoted_globbing(self):
 
196
        self.run_script("""
 
197
echo cat >cat
 
198
cat '*'
 
199
2>*: No such file or directory
 
200
""")
 
201
 
 
202
    def test_quotes_removal(self):
 
203
        self.run_script("""
 
204
echo 'cat' "dog" '"chicken"' "'dragon'"
 
205
>catdog"chicken"'dragon'
 
206
""")
 
207
 
 
208
 
184
209
class TestCat(script.TestCaseWithTransportAndScript):
185
210
 
186
211
    def test_cat_usage(self):
187
 
        self.assertRaises(SyntaxError, self.run_script, 'cat foo bar baz')
188
212
        self.assertRaises(SyntaxError, self.run_script, 'cat foo <bar')
189
213
 
190
214
    def test_cat_input_to_output(self):
218
242
                                             None, None, None)
219
243
        self.assertFileEqual('content\n', 'file2')
220
244
 
 
245
    def test_cat_files_to_file(self):
 
246
        self.build_tree_contents([('cat', 'cat\n')])
 
247
        self.build_tree_contents([('dog', 'dog\n')])
 
248
        retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],
 
249
                                             None, None, None)
 
250
        self.assertFileEqual('cat\ndog\n', 'file')
 
251
 
221
252
    def test_cat_bogus_input_file(self):
222
253
        self.run_script("""
223
254
cat <file