27
30
def test_comment_is_ignored(self):
28
31
self.assertEquals([], script._script_to_commands('#comment\n'))
30
def test_empty_line_is_ignored(self):
31
self.assertEquals([], script._script_to_commands('\n'))
33
def test_comment_multiple_lines(self):
35
(['bar'], None, None, None),
37
script._script_to_commands("""
38
# this comment is ignored
44
def test_trim_blank_lines(self):
45
"""Blank lines are respected, but trimmed at the start and end.
47
Python triple-quoted syntax is going to give stubby/empty blank lines
48
right at the start and the end. These are cut off so that callers don't
49
need special syntax to avoid them.
51
However we do want to be able to match commands that emit blank lines.
54
(['bar'], None, '\n', None),
56
script._script_to_commands("""
33
61
def test_simple_command(self):
34
62
self.assertEquals([(['cd', 'trunk'], None, None, None)],
133
161
class TestExecution(script.TestCaseWithTransportAndScript):
135
163
def test_unknown_command(self):
136
self.assertRaises(SyntaxError, self.run_script, 'foo')
164
"""A clear error is reported for commands that aren't recognised
166
Testing the attributes of the SyntaxError instance is equivalent to
167
using traceback.format_exception_only and comparing with:
168
File "<string>", line 1
171
SyntaxError: Command not found "foo"
173
e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
self.assertContainsRe(e.msg, "not found.*foo")
175
self.assertEquals(e.text, "foo --frob")
177
def test_blank_output_mismatches_output(self):
178
"""If you give output, the output must actually be blank.
180
See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
181
output was a wildcard. Now you must say ... if you want that.
183
self.assertRaises(AssertionError,
189
def test_null_output_matches_option(self):
190
"""If you want null output to be a wild card, you can pass
191
null_output_matches_anything to run_script"""
195
""", null_output_matches_anything=True)
197
def test_ellipsis_everything(self):
198
"""A simple ellipsis matches everything."""
204
def test_ellipsis_matches_empty(self):
138
210
def test_stops_on_unexpected_output(self):
218
292
cat dog "chicken" 'dragon'
295
def test_verbosity_isolated(self):
296
"""Global verbosity is isolated from commands run in scripts.
298
# see also 656694; we should get rid of global verbosity
302
self.assertEquals(trace.is_quiet(), False)
222
305
class TestCat(script.TestCaseWithTransportAndScript):
329
412
class TestBzr(script.TestCaseWithTransportAndScript):
331
414
def test_bzr_smoke(self):
332
self.run_script('$ bzr init branch')
417
Created a standalone tree (format: ...)
333
419
self.failUnlessExists('branch')
377
463
self.assertEquals(None, err)
378
464
self.assertFileEqual('hello\nhappy\n', 'file')
466
def test_empty_line_in_output_is_respected(self):
381
475
class TestRm(script.TestCaseWithTransportAndScript):
459
553
self.failIfExists('file')
460
554
self.failUnlessExists('dir/file')
557
class cmd_test_confirm(commands.Command):
560
if ui.ui_factory.get_boolean(
562
# 'bzrlib.tests.test_script.confirm',
565
self.outf.write('Do it!\n')
570
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
572
def test_confirm_action(self):
573
"""You can write tests that demonstrate user confirmation.
575
Specifically, ScriptRunner does't care if the output line for the prompt
576
isn't terminated by a newline from the program; it's implicitly terminated
579
commands.builtin_command_registry.register(cmd_test_confirm)
580
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
583
2>Really do it? [y/n]:
587
2>Really do it? [y/n]: