~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
class TestExecution(script.TestCaseWithTransportAndScript):
162
162
 
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
 
165
 
 
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
 
169
            foo --frob
 
170
            ^
 
171
        SyntaxError: Command not found "foo"
 
172
        """
 
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")
165
176
 
166
177
    def test_blank_output_mismatches_output(self):
167
178
        """If you give output, the output must actually be blank.
175
186
            $ echo foo
176
187
            """)
177
188
 
 
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"""
 
192
        self.run_script(
 
193
            """
 
194
            $ echo foo
 
195
            """, null_output_matches_anything=True)
 
196
 
178
197
    def test_ellipsis_everything(self):
179
198
        """A simple ellipsis matches everything."""
180
199
        self.run_script("""
364
383
$ mkdir ../dir2
365
384
$ cd ..
366
385
""")
367
 
        self.failUnlessExists('dir')
368
 
        self.failUnlessExists('dir2')
 
386
        self.assertPathExists('dir')
 
387
        self.assertPathExists('dir2')
369
388
 
370
389
 
371
390
class TestCd(script.TestCaseWithTransportAndScript):
397
416
            $ bzr init branch
398
417
            Created a standalone tree (format: ...)
399
418
            """)
400
 
        self.failUnlessExists('branch')
 
419
        self.assertPathExists('branch')
401
420
 
402
421
 
403
422
class TestEcho(script.TestCaseWithMemoryTransportAndScript):
461
480
 
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')
467
486
 
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')
472
491
 
473
492
    def test_rm_files(self):
474
493
        self.run_script("""
475
494
$ echo content >file
476
495
$ echo content >file2
477
496
""")
478
 
        self.failUnlessExists('file2')
 
497
        self.assertPathExists('file2')
479
498
        self.run_script('$ rm file file2')
480
 
        self.failIfExists('file2')
 
499
        self.assertPathDoesNotExist('file2')
481
500
 
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("""
486
505
$ rm dir
487
506
2>rm: cannot remove 'dir': Is a directory
488
507
""")
489
 
        self.failUnlessExists('dir')
 
508
        self.assertPathExists('dir')
490
509
 
491
510
    def test_rm_dir_recursive(self):
492
511
        self.run_script("""
493
512
$ mkdir dir
494
513
$ rm -r dir
495
514
""")
496
 
        self.failIfExists('dir')
 
515
        self.assertPathDoesNotExist('dir')
497
516
 
498
517
 
499
518
class TestMv(script.TestCaseWithTransportAndScript):
505
524
 
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')
512
531
 
513
532
    def test_move_unknown_file(self):
514
533
        self.assertRaises(AssertionError,
520
539
$ echo content >dir/file
521
540
""")
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')
526
545
 
527
546
    def test_move_file_into_dir(self):
528
547
        self.run_script("""
530
549
$ echo content > file
531
550
""")
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')
536
555
 
537
556
 
538
557
class cmd_test_confirm(commands.Command):
539
558
 
540
559
    def run(self):
541
560
        if ui.ui_factory.get_boolean(
542
 
            'Really do it',
 
561
            u'Really do it',
543
562
            # 'bzrlib.tests.test_script.confirm',
544
563
            # {}
545
564
            ):
553
572
    def test_confirm_action(self):
554
573
        """You can write tests that demonstrate user confirmation.
555
574
        
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 
558
 
        by the input.
 
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.
559
578
        """
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]: 
565
 
            <yes
 
583
            2>Really do it? ([y]es, [n]o): yes
 
584
            <y
566
585
            Do it!
567
586
            $ bzr test-confirm
568
 
            2>Really do it? [y/n]: 
569
 
            <no
 
587
            2>Really do it? ([y]es, [n]o): no
 
588
            <n
570
589
            ok, no
571
590
            """)
572
591
 
 
592
class TestShelve(script.TestCaseWithTransportAndScript):
 
593
 
 
594
    def setUp(self):
 
595
        super(TestShelve, self).setUp()
 
596
        self.run_script("""
 
597
            $ bzr init test
 
598
            Created a standalone tree (format: 2a)
 
599
            $ cd test
 
600
            $ echo foo > file
 
601
            $ bzr add
 
602
            adding file
 
603
            $ bzr commit -m 'file added'
 
604
            2>Committing to:...test/
 
605
            2>added file
 
606
            2>Committed revision 1.
 
607
            $ echo bar > file
 
608
            """)
 
609
 
 
610
    def test_shelve(self):
 
611
        self.run_script("""
 
612
            $ bzr shelve -m 'shelve bar'
 
613
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): yes
 
614
            <y
 
615
            2>Selected changes:
 
616
            2> M  file
 
617
            2>Shelve 1 change(s)? ([y]es, [N]o, [f]inish, [q]uit): yes
 
618
            <y
 
619
            2>Changes shelved with id "1".
 
620
            """,
 
621
                        null_output_matches_anything=True)
 
622
        self.run_script("""
 
623
            $ bzr shelve --list
 
624
              1: shelve bar
 
625
            """)
 
626
 
 
627
    def test_dont_shelve(self):
 
628
        # We intentionally provide no input here to test EOF
 
629
        self.run_script("""
 
630
            $ bzr shelve -m 'shelve bar'
 
631
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): 
 
632
            2>No changes to shelve.
 
633
            """,
 
634
                        null_output_matches_anything=True)
 
635
        self.run_script("""
 
636
            $ bzr st
 
637
            modified:
 
638
              file
 
639
            """)