~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Kit Randel
  • Date: 2014-12-15 20:24:42 UTC
  • mto: This revision was merged to the branch mainline in revision 6602.
  • Revision ID: kit.randel@canonical.com-20141215202442-usf2ixhypqg8yh6q
added a note for bug-1400567 to the 2.7b release notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    commands,
20
20
    osutils,
21
21
    tests,
 
22
    trace,
22
23
    ui,
23
24
    )
24
25
from bzrlib.tests import script
160
161
class TestExecution(script.TestCaseWithTransportAndScript):
161
162
 
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
 
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")
 
176
 
 
177
    def test_blank_output_mismatches_output(self):
 
178
        """If you give output, the output must actually be blank.
 
179
        
 
180
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
 
181
        output was a wildcard.  Now you must say ... if you want that.
 
182
        """
 
183
        self.assertRaises(AssertionError,
 
184
            self.run_script,
 
185
            """
 
186
            $ echo foo
 
187
            """)
 
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
 
 
197
    def test_ellipsis_everything(self):
 
198
        """A simple ellipsis matches everything."""
 
199
        self.run_script("""
 
200
        $ echo foo
 
201
        ...
 
202
        """)
 
203
 
 
204
    def test_ellipsis_matches_empty(self):
 
205
        self.run_script("""
 
206
        $ cd .
 
207
        ...
 
208
        """)
164
209
 
165
210
    def test_stops_on_unexpected_output(self):
166
211
        story = """
170
215
"""
171
216
        self.assertRaises(AssertionError, self.run_script, story)
172
217
 
173
 
 
174
218
    def test_stops_on_unexpected_error(self):
175
219
        story = """
176
220
$ cat
190
234
        # The status matters, not the output
191
235
        story = """
192
236
$ bzr init
 
237
...
193
238
$ cat >file
194
239
<Hello
195
240
$ bzr add file
 
241
...
196
242
$ bzr commit -m 'adding file'
 
243
2>...
197
244
"""
198
245
        self.run_script(story)
199
246
 
245
292
cat dog "chicken" 'dragon'
246
293
""")
247
294
 
 
295
    def test_verbosity_isolated(self):
 
296
        """Global verbosity is isolated from commands run in scripts.
 
297
        """
 
298
        # see also 656694; we should get rid of global verbosity
 
299
        self.run_script("""
 
300
        $ bzr init --quiet a
 
301
        """)
 
302
        self.assertEquals(trace.is_quiet(), False)
 
303
 
248
304
 
249
305
class TestCat(script.TestCaseWithTransportAndScript):
250
306
 
327
383
$ mkdir ../dir2
328
384
$ cd ..
329
385
""")
330
 
        self.failUnlessExists('dir')
331
 
        self.failUnlessExists('dir2')
 
386
        self.assertPathExists('dir')
 
387
        self.assertPathExists('dir2')
332
388
 
333
389
 
334
390
class TestCd(script.TestCaseWithTransportAndScript):
356
412
class TestBzr(script.TestCaseWithTransportAndScript):
357
413
 
358
414
    def test_bzr_smoke(self):
359
 
        self.run_script('$ bzr init branch')
360
 
        self.failUnlessExists('branch')
 
415
        self.run_script("""
 
416
            $ bzr init branch
 
417
            Created a standalone tree (format: ...)
 
418
            """)
 
419
        self.assertPathExists('branch')
361
420
 
362
421
 
363
422
class TestEcho(script.TestCaseWithMemoryTransportAndScript):
421
480
 
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')
427
486
 
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')
432
491
 
433
492
    def test_rm_files(self):
434
493
        self.run_script("""
435
494
$ echo content >file
436
495
$ echo content >file2
437
496
""")
438
 
        self.failUnlessExists('file2')
 
497
        self.assertPathExists('file2')
439
498
        self.run_script('$ rm file file2')
440
 
        self.failIfExists('file2')
 
499
        self.assertPathDoesNotExist('file2')
441
500
 
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("""
446
505
$ rm dir
447
506
2>rm: cannot remove 'dir': Is a directory
448
507
""")
449
 
        self.failUnlessExists('dir')
 
508
        self.assertPathExists('dir')
450
509
 
451
510
    def test_rm_dir_recursive(self):
452
511
        self.run_script("""
453
512
$ mkdir dir
454
513
$ rm -r dir
455
514
""")
456
 
        self.failIfExists('dir')
 
515
        self.assertPathDoesNotExist('dir')
457
516
 
458
517
 
459
518
class TestMv(script.TestCaseWithTransportAndScript):
465
524
 
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')
472
531
 
473
532
    def test_move_unknown_file(self):
474
533
        self.assertRaises(AssertionError,
480
539
$ echo content >dir/file
481
540
""")
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')
486
545
 
487
546
    def test_move_file_into_dir(self):
488
547
        self.run_script("""
490
549
$ echo content > file
491
550
""")
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')
496
555
 
497
556
 
498
557
class cmd_test_confirm(commands.Command):
499
558
 
500
559
    def run(self):
501
560
        if ui.ui_factory.get_boolean(
502
 
            'Really do it',
 
561
            u'Really do it',
503
562
            # 'bzrlib.tests.test_script.confirm',
504
563
            # {}
505
564
            ):
513
572
    def test_confirm_action(self):
514
573
        """You can write tests that demonstrate user confirmation.
515
574
        
516
 
        Specifically, ScriptRunner does't care if the output line for the prompt
517
 
        isn't terminated by a newline from the program; it's implicitly terminated 
518
 
        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.
519
578
        """
520
579
        commands.builtin_command_registry.register(cmd_test_confirm)
521
580
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
522
581
        self.run_script("""
523
582
            $ bzr test-confirm
524
 
            2>Really do it? [y/n]: 
525
 
            <yes
 
583
            2>Really do it? ([y]es, [n]o): yes
 
584
            <y
526
585
            Do it!
527
586
            $ bzr test-confirm
528
 
            2>Really do it? [y/n]: 
529
 
            <no
 
587
            2>Really do it? ([y]es, [n]o): no
 
588
            <n
530
589
            ok, no
531
590
            """)
532
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
            """)