/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Martin Pool
  • Date: 2010-10-08 05:36:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5476.
  • Revision ID: mbp@sourcefrog.net-20101008053617-tbgqy042stu7zko4
Try for a better failure message in test_delta

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
123
162
    def test_unknown_command(self):
124
163
        self.assertRaises(SyntaxError, self.run_script, 'foo')
125
164
 
 
165
    def test_blank_output_mismatches_output(self):
 
166
        """If you give output, the output must actually be blank.
 
167
        
 
168
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
 
169
        output was a wildcard.  Now you must say ... if you want that.
 
170
        """
 
171
        self.assertRaises(AssertionError,
 
172
            self.run_script,
 
173
            """
 
174
            $ echo foo
 
175
            """)
 
176
 
 
177
    def test_ellipsis_everything(self):
 
178
        """A simple ellipsis matches everything."""
 
179
        self.run_script("""
 
180
        $ echo foo
 
181
        ...
 
182
        """)
 
183
 
 
184
    def test_ellipsis_matches_empty(self):
 
185
        self.run_script("""
 
186
        $ cd .
 
187
        ...
 
188
        """)
 
189
 
126
190
    def test_stops_on_unexpected_output(self):
127
191
        story = """
128
192
$ mkdir dir
131
195
"""
132
196
        self.assertRaises(AssertionError, self.run_script, story)
133
197
 
134
 
 
135
198
    def test_stops_on_unexpected_error(self):
136
199
        story = """
137
200
$ cat
151
214
        # The status matters, not the output
152
215
        story = """
153
216
$ bzr init
 
217
...
154
218
$ cat >file
155
219
<Hello
156
220
$ bzr add file
 
221
...
157
222
$ bzr commit -m 'adding file'
 
223
2>...
158
224
"""
159
225
        self.run_script(story)
160
226
 
317
383
class TestBzr(script.TestCaseWithTransportAndScript):
318
384
 
319
385
    def test_bzr_smoke(self):
320
 
        self.run_script('$ bzr init branch')
 
386
        self.run_script("""
 
387
            $ bzr init branch
 
388
            Created a standalone tree (format: ...)
 
389
            """)
321
390
        self.failUnlessExists('branch')
322
391
 
323
392
 
365
434
        self.assertEquals(None, err)
366
435
        self.assertFileEqual('hello\nhappy\n', 'file')
367
436
 
 
437
    def test_empty_line_in_output_is_respected(self):
 
438
        self.run_script("""
 
439
            $ echo
 
440
 
 
441
            $ echo bar
 
442
            bar
 
443
            """)
 
444
 
368
445
 
369
446
class TestRm(script.TestCaseWithTransportAndScript):
370
447
 
447
524
        self.failIfExists('file')
448
525
        self.failUnlessExists('dir/file')
449
526
 
 
527
 
 
528
class cmd_test_confirm(commands.Command):
 
529
 
 
530
    def run(self):
 
531
        if ui.ui_factory.get_boolean(
 
532
            'Really do it',
 
533
            # 'bzrlib.tests.test_script.confirm',
 
534
            # {}
 
535
            ):
 
536
            self.outf.write('Do it!\n')
 
537
        else:
 
538
            print 'ok, no'
 
539
 
 
540
 
 
541
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
542
 
 
543
    def test_confirm_action(self):
 
544
        """You can write tests that demonstrate user confirmation.
 
545
        
 
546
        Specifically, ScriptRunner does't care if the output line for the prompt
 
547
        isn't terminated by a newline from the program; it's implicitly terminated 
 
548
        by the input.
 
549
        """
 
550
        commands.builtin_command_registry.register(cmd_test_confirm)
 
551
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
552
        self.run_script("""
 
553
            $ bzr test-confirm
 
554
            2>Really do it? [y/n]: 
 
555
            <yes
 
556
            Do it!
 
557
            $ bzr test-confirm
 
558
            2>Really do it? [y/n]: 
 
559
            <no
 
560
            ok, no
 
561
            """)
 
562