~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
from bzrlib import (
 
19
    commands,
19
20
    osutils,
20
21
    tests,
 
22
    ui,
21
23
    )
22
24
from bzrlib.tests import script
23
25
 
27
29
    def test_comment_is_ignored(self):
28
30
        self.assertEquals([], script._script_to_commands('#comment\n'))
29
31
 
30
 
    def test_empty_line_is_ignored(self):
31
 
        self.assertEquals([], script._script_to_commands('\n'))
 
32
    def test_comment_multiple_lines(self):
 
33
        self.assertEquals([
 
34
            (['bar'], None, None, None),
 
35
            ],
 
36
            script._script_to_commands("""
 
37
            # this comment is ignored
 
38
            # so is this
 
39
            # no we run bar
 
40
            $ bar
 
41
            """))
 
42
 
 
43
    def test_trim_blank_lines(self):
 
44
        """Blank lines are respected, but trimmed at the start and end.
 
45
 
 
46
        Python triple-quoted syntax is going to give stubby/empty blank lines 
 
47
        right at the start and the end.  These are cut off so that callers don't 
 
48
        need special syntax to avoid them.
 
49
 
 
50
        However we do want to be able to match commands that emit blank lines.
 
51
        """
 
52
        self.assertEquals([
 
53
            (['bar'], None, '\n', None),
 
54
            ],
 
55
            script._script_to_commands("""
 
56
            $bar
 
57
 
 
58
            """))
32
59
 
33
60
    def test_simple_command(self):
34
61
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
51
78
            [(['cat', '>file'], 'content\n', None, None)],
52
79
            script._script_to_commands('$ cat >file\n<content\n'))
53
80
 
 
81
    def test_indented(self):
 
82
        # scripts are commonly given indented within the test source code, and
 
83
        # common indentation is stripped off
 
84
        story = """
 
85
            $ bzr add
 
86
            adding file
 
87
            adding file2
 
88
            """
 
89
        self.assertEquals([(['bzr', 'add'], None,
 
90
                            'adding file\nadding file2\n', None)],
 
91
                          script._script_to_commands(story))
 
92
 
54
93
    def test_command_with_output(self):
55
94
        story = """
56
95
$ bzr add
365
404
        self.assertEquals(None, err)
366
405
        self.assertFileEqual('hello\nhappy\n', 'file')
367
406
 
 
407
    def test_empty_line_in_output_is_respected(self):
 
408
        self.run_script("""
 
409
            $ echo
 
410
 
 
411
            $ echo bar
 
412
            bar
 
413
            """)
 
414
 
368
415
 
369
416
class TestRm(script.TestCaseWithTransportAndScript):
370
417
 
447
494
        self.failIfExists('file')
448
495
        self.failUnlessExists('dir/file')
449
496
 
 
497
 
 
498
class cmd_test_confirm(commands.Command):
 
499
 
 
500
    def run(self):
 
501
        if ui.ui_factory.get_boolean(
 
502
            'Really do it',
 
503
            # 'bzrlib.tests.test_script.confirm',
 
504
            # {}
 
505
            ):
 
506
            self.outf.write('Do it!\n')
 
507
        else:
 
508
            print 'ok, no'
 
509
 
 
510
 
 
511
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
512
 
 
513
    def test_confirm_action(self):
 
514
        """You can write tests that demonstrate user confirmation.
 
515
        
 
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.
 
519
        """
 
520
        commands.builtin_command_registry.register(cmd_test_confirm)
 
521
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
522
        self.run_script("""
 
523
            $ bzr test-confirm
 
524
            2>Really do it? [y/n]: 
 
525
            <yes
 
526
            Do it!
 
527
            $ bzr test-confirm
 
528
            2>Really do it? [y/n]: 
 
529
            <no
 
530
            ok, no
 
531
            """)
 
532