160
161
class TestExecution(script.TestCaseWithTransportAndScript):
162
163
def test_unknown_command(self):
163
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):
165
210
def test_stops_on_unexpected_output(self):
245
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)
249
305
class TestCat(script.TestCaseWithTransportAndScript):
330
self.failUnlessExists('dir')
331
self.failUnlessExists('dir2')
386
self.assertPathExists('dir')
387
self.assertPathExists('dir2')
334
390
class TestCd(script.TestCaseWithTransportAndScript):
356
412
class TestBzr(script.TestCaseWithTransportAndScript):
358
414
def test_bzr_smoke(self):
359
self.run_script('$ bzr init branch')
360
self.failUnlessExists('branch')
417
Created a standalone tree (format: ...)
419
self.assertPathExists('branch')
363
422
class TestEcho(script.TestCaseWithMemoryTransportAndScript):
422
481
def test_rm_file(self):
423
482
self.run_script('$ echo content >file')
424
self.failUnlessExists('file')
483
self.assertPathExists('file')
425
484
self.run_script('$ rm file')
426
self.failIfExists('file')
485
self.assertPathDoesNotExist('file')
428
487
def test_rm_file_force(self):
429
self.failIfExists('file')
488
self.assertPathDoesNotExist('file')
430
489
self.run_script('$ rm -f file')
431
self.failIfExists('file')
490
self.assertPathDoesNotExist('file')
433
492
def test_rm_files(self):
434
493
self.run_script("""
435
494
$ echo content >file
436
495
$ echo content >file2
438
self.failUnlessExists('file2')
497
self.assertPathExists('file2')
439
498
self.run_script('$ rm file file2')
440
self.failIfExists('file2')
499
self.assertPathDoesNotExist('file2')
442
501
def test_rm_dir(self):
443
502
self.run_script('$ mkdir dir')
444
self.failUnlessExists('dir')
503
self.assertPathExists('dir')
445
504
self.run_script("""
447
506
2>rm: cannot remove 'dir': Is a directory
449
self.failUnlessExists('dir')
508
self.assertPathExists('dir')
451
510
def test_rm_dir_recursive(self):
452
511
self.run_script("""
456
self.failIfExists('dir')
515
self.assertPathDoesNotExist('dir')
459
518
class TestMv(script.TestCaseWithTransportAndScript):
466
525
def test_move_file(self):
467
526
self.run_script('$ echo content >file')
468
self.failUnlessExists('file')
527
self.assertPathExists('file')
469
528
self.run_script('$ mv file new_name')
470
self.failIfExists('file')
471
self.failUnlessExists('new_name')
529
self.assertPathDoesNotExist('file')
530
self.assertPathExists('new_name')
473
532
def test_move_unknown_file(self):
474
533
self.assertRaises(AssertionError,
480
539
$ echo content >dir/file
482
541
self.run_script('$ mv dir new_name')
483
self.failIfExists('dir')
484
self.failUnlessExists('new_name')
485
self.failUnlessExists('new_name/file')
542
self.assertPathDoesNotExist('dir')
543
self.assertPathExists('new_name')
544
self.assertPathExists('new_name/file')
487
546
def test_move_file_into_dir(self):
488
547
self.run_script("""
490
549
$ echo content > file
492
551
self.run_script('$ mv file dir')
493
self.failUnlessExists('dir')
494
self.failIfExists('file')
495
self.failUnlessExists('dir/file')
552
self.assertPathExists('dir')
553
self.assertPathDoesNotExist('file')
554
self.assertPathExists('dir/file')
498
557
class cmd_test_confirm(commands.Command):
501
560
if ui.ui_factory.get_boolean(
503
562
# 'bzrlib.tests.test_script.confirm',