61
61
def test_simple_command(self):
62
62
self.assertEqual([(['cd', 'trunk'], None, None, None)],
63
script._script_to_commands('$ cd trunk'))
63
script._script_to_commands('$ cd trunk'))
65
65
def test_command_with_single_quoted_param(self):
66
66
story = """$ brz commit -m 'two words'"""
67
67
self.assertEqual([(['brz', 'commit', '-m', "'two words'"],
69
script._script_to_commands(story))
69
script._script_to_commands(story))
71
71
def test_command_with_double_quoted_param(self):
72
72
story = """$ brz commit -m "two words" """
73
73
self.assertEqual([(['brz', 'commit', '-m', '"two words"'],
75
script._script_to_commands(story))
75
script._script_to_commands(story))
77
77
def test_command_with_input(self):
107
107
2>brz: ERROR: Not a branch: "foo"
109
109
self.assertEqual([(['brz', 'branch', 'foo'],
110
None, None, 'brz: ERROR: Not a branch: "foo"\n')],
111
script._script_to_commands(story))
110
None, None, 'brz: ERROR: Not a branch: "foo"\n')],
111
script._script_to_commands(story))
113
113
def test_input_without_command(self):
114
114
self.assertRaises(SyntaxError, script._script_to_commands, '<input')
143
143
self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz'])
145
145
def test_output_redirection(self):
146
self._check(None, 'foo', 'w+', [], ['>foo'])
147
self._check(None, 'foo', 'w+', ['bar'], ['bar', '>foo'])
148
self._check(None, 'foo', 'w+', ['bar'], ['bar', '>', 'foo'])
149
self._check(None, 'foo', 'a+', [], ['>>foo'])
150
self._check(None, 'foo', 'a+', ['bar'], ['bar', '>>foo'])
151
self._check(None, 'foo', 'a+', ['bar'], ['bar', '>>', 'foo'])
146
self._check(None, 'foo', 'wb+', [], ['>foo'])
147
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo'])
148
self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo'])
149
self._check(None, 'foo', 'ab+', [], ['>>foo'])
150
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo'])
151
self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo'])
153
153
def test_redirection_syntax_errors(self):
154
154
self._check('', None, None, [], ['<'])
155
self._check(None, '', 'w+', [], ['>'])
156
self._check(None, '', 'a+', [], ['>>'])
157
self._check('>', '', 'a+', [], ['<', '>', '>>'])
155
self._check(None, '', 'wb+', [], ['>'])
156
self._check(None, '', 'ab+', [], ['>>'])
157
self._check('>', '', 'ab+', [], ['<', '>', '>>'])
160
161
class TestExecution(script.TestCaseWithTransportAndScript):
176
177
def test_blank_output_mismatches_output(self):
177
178
"""If you give output, the output must actually be blank.
179
180
See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
180
181
output was a wildcard. Now you must say ... if you want that.
182
183
self.assertRaises(AssertionError,
188
189
def test_null_output_matches_option(self):
189
"""If you want null output to be a wild card, you can pass
190
"""If you want null output to be a wild card, you can pass
190
191
null_output_matches_anything to run_script"""
332
333
self.assertEqual(None, err)
334
335
def test_cat_file_to_file(self):
335
self.build_tree_contents([('file', b'content\n')])
336
self.build_tree_contents([('file', 'content\n')])
336
337
retcode, out, err = self.run_command(['cat', 'file', '>file2'],
337
338
None, None, None)
338
self.assertFileEqual(b'content\n', 'file2')
339
self.assertFileEqual('content\n', 'file2')
340
341
def test_cat_files_to_file(self):
341
self.build_tree_contents([('cat', b'cat\n')])
342
self.build_tree_contents([('dog', b'dog\n')])
342
self.build_tree_contents([('cat', 'cat\n')])
343
self.build_tree_contents([('dog', 'dog\n')])
343
344
retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],
344
345
None, None, None)
345
self.assertFileEqual(b'cat\ndog\n', 'file')
346
self.assertFileEqual('cat\ndog\n', 'file')
347
348
def test_cat_bogus_input_file(self):
348
349
self.run_script("""
456
456
None, None, None)
457
457
self.assertEqual(None, out)
458
458
self.assertEqual(None, err)
459
self.assertFileEqual(b'hello\n', 'file')
459
self.assertFileEqual('hello\n', 'file')
460
460
retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
461
461
None, None, None)
462
462
self.assertEqual(None, out)
463
463
self.assertEqual(None, err)
464
self.assertFileEqual(b'hello\nhappy\n', 'file')
464
self.assertFileEqual('hello\nhappy\n', 'file')
466
466
def test_empty_line_in_output_is_respected(self):
467
467
self.run_script("""
572
572
def test_confirm_action(self):
573
573
"""You can write tests that demonstrate user confirmation.
575
575
Specifically, ScriptRunner does't care if the output line for the
576
576
prompt isn't terminated by a newline from the program; it's implicitly
577
577
terminated by the input.
579
579
commands.builtin_command_registry.register(cmd_test_confirm)
581
commands.builtin_command_registry.remove, 'test-confirm')
580
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
582
581
self.run_script("""
583
582
$ brz test-confirm
584
583
2>Really do it? ([y]es, [n]o): yes
629
627
def test_dont_shelve(self):
630
628
# We intentionally provide no input here to test EOF
632
"$ brz shelve -m 'shelve bar'\n"
633
"2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): \n"
634
"2>No changes to shelve.\n"
635
), null_output_matches_anything=True)
630
$ brz shelve -m 'shelve bar'
631
2>Shelve? ([y]es, [N]o, [f]inish, [q]uit):
632
2>No changes to shelve.
634
null_output_matches_anything=True)
636
635
self.run_script("""