161
161
class TestExecution(script.TestCaseWithTransportAndScript):
163
163
def test_unknown_command(self):
164
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")
166
177
def test_blank_output_mismatches_output(self):
167
178
"""If you give output, the output must actually be blank.
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)
178
197
def test_ellipsis_everything(self):
179
198
"""A simple ellipsis matches everything."""
180
199
self.run_script("""
367
self.failUnlessExists('dir')
368
self.failUnlessExists('dir2')
386
self.assertPathExists('dir')
387
self.assertPathExists('dir2')
371
390
class TestCd(script.TestCaseWithTransportAndScript):
462
481
def test_rm_file(self):
463
482
self.run_script('$ echo content >file')
464
self.failUnlessExists('file')
483
self.assertPathExists('file')
465
484
self.run_script('$ rm file')
466
self.failIfExists('file')
485
self.assertPathDoesNotExist('file')
468
487
def test_rm_file_force(self):
469
self.failIfExists('file')
488
self.assertPathDoesNotExist('file')
470
489
self.run_script('$ rm -f file')
471
self.failIfExists('file')
490
self.assertPathDoesNotExist('file')
473
492
def test_rm_files(self):
474
493
self.run_script("""
475
494
$ echo content >file
476
495
$ echo content >file2
478
self.failUnlessExists('file2')
497
self.assertPathExists('file2')
479
498
self.run_script('$ rm file file2')
480
self.failIfExists('file2')
499
self.assertPathDoesNotExist('file2')
482
501
def test_rm_dir(self):
483
502
self.run_script('$ mkdir dir')
484
self.failUnlessExists('dir')
503
self.assertPathExists('dir')
485
504
self.run_script("""
487
506
2>rm: cannot remove 'dir': Is a directory
489
self.failUnlessExists('dir')
508
self.assertPathExists('dir')
491
510
def test_rm_dir_recursive(self):
492
511
self.run_script("""
496
self.failIfExists('dir')
515
self.assertPathDoesNotExist('dir')
499
518
class TestMv(script.TestCaseWithTransportAndScript):
506
525
def test_move_file(self):
507
526
self.run_script('$ echo content >file')
508
self.failUnlessExists('file')
527
self.assertPathExists('file')
509
528
self.run_script('$ mv file new_name')
510
self.failIfExists('file')
511
self.failUnlessExists('new_name')
529
self.assertPathDoesNotExist('file')
530
self.assertPathExists('new_name')
513
532
def test_move_unknown_file(self):
514
533
self.assertRaises(AssertionError,
520
539
$ echo content >dir/file
522
541
self.run_script('$ mv dir new_name')
523
self.failIfExists('dir')
524
self.failUnlessExists('new_name')
525
self.failUnlessExists('new_name/file')
542
self.assertPathDoesNotExist('dir')
543
self.assertPathExists('new_name')
544
self.assertPathExists('new_name/file')
527
546
def test_move_file_into_dir(self):
528
547
self.run_script("""
530
549
$ echo content > file
532
551
self.run_script('$ mv file dir')
533
self.failUnlessExists('dir')
534
self.failIfExists('file')
535
self.failUnlessExists('dir/file')
552
self.assertPathExists('dir')
553
self.assertPathDoesNotExist('file')
554
self.assertPathExists('dir/file')
538
557
class cmd_test_confirm(commands.Command):
541
560
if ui.ui_factory.get_boolean(
543
562
# 'bzrlib.tests.test_script.confirm',
553
572
def test_confirm_action(self):
554
573
"""You can write tests that demonstrate user confirmation.
556
Specifically, ScriptRunner does't care if the output line for the prompt
557
isn't terminated by a newline from the program; it's implicitly terminated
575
Specifically, ScriptRunner does't care if the output line for the
576
prompt isn't terminated by a newline from the program; it's implicitly
577
terminated by the input.
560
579
commands.builtin_command_registry.register(cmd_test_confirm)
561
580
self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
562
581
self.run_script("""
563
582
$ bzr test-confirm
564
2>Really do it? [y/n]:
583
2>Really do it? ([y]es, [n]o): yes
567
586
$ bzr test-confirm
568
2>Really do it? [y/n]:
587
2>Really do it? ([y]es, [n]o): no
592
class TestShelve(script.TestCaseWithTransportAndScript):
595
super(TestShelve, self).setUp()
598
Created a standalone tree (format: 2a)
603
$ bzr commit -m 'file added'
604
2>Committing to:...test/
606
2>Committed revision 1.
610
def test_shelve(self):
612
$ bzr shelve -m 'shelve bar'
613
2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): yes
617
2>Shelve 1 change(s)? ([y]es, [N]o, [f]inish, [q]uit): yes
619
2>Changes shelved with id "1".
621
null_output_matches_anything=True)
627
def test_dont_shelve(self):
628
# We intentionally provide no input here to test EOF
630
$ bzr 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)