/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: John Arbash Meinel
  • Date: 2010-11-05 20:54:32 UTC
  • mfrom: (5526 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5527.
  • Revision ID: john@arbash-meinel.com-20101105205432-rmyozu8sthyhmri8
Merge bzr.dev to resolve bzr-2.3.txt (aka NEWS)

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
    trace,
 
23
    ui,
21
24
    )
22
25
from bzrlib.tests import script
23
26
 
27
30
    def test_comment_is_ignored(self):
28
31
        self.assertEquals([], script._script_to_commands('#comment\n'))
29
32
 
30
 
    def test_empty_line_is_ignored(self):
31
 
        self.assertEquals([], script._script_to_commands('\n'))
 
33
    def test_comment_multiple_lines(self):
 
34
        self.assertEquals([
 
35
            (['bar'], None, None, None),
 
36
            ],
 
37
            script._script_to_commands("""
 
38
            # this comment is ignored
 
39
            # so is this
 
40
            # no we run bar
 
41
            $ bar
 
42
            """))
 
43
 
 
44
    def test_trim_blank_lines(self):
 
45
        """Blank lines are respected, but trimmed at the start and end.
 
46
 
 
47
        Python triple-quoted syntax is going to give stubby/empty blank lines 
 
48
        right at the start and the end.  These are cut off so that callers don't 
 
49
        need special syntax to avoid them.
 
50
 
 
51
        However we do want to be able to match commands that emit blank lines.
 
52
        """
 
53
        self.assertEquals([
 
54
            (['bar'], None, '\n', None),
 
55
            ],
 
56
            script._script_to_commands("""
 
57
            $bar
 
58
 
 
59
            """))
32
60
 
33
61
    def test_simple_command(self):
34
62
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
51
79
            [(['cat', '>file'], 'content\n', None, None)],
52
80
            script._script_to_commands('$ cat >file\n<content\n'))
53
81
 
 
82
    def test_indented(self):
 
83
        # scripts are commonly given indented within the test source code, and
 
84
        # common indentation is stripped off
 
85
        story = """
 
86
            $ bzr add
 
87
            adding file
 
88
            adding file2
 
89
            """
 
90
        self.assertEquals([(['bzr', 'add'], None,
 
91
                            'adding file\nadding file2\n', None)],
 
92
                          script._script_to_commands(story))
 
93
 
54
94
    def test_command_with_output(self):
55
95
        story = """
56
96
$ bzr add
121
161
class TestExecution(script.TestCaseWithTransportAndScript):
122
162
 
123
163
    def test_unknown_command(self):
124
 
        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_ellipsis_everything(self):
 
190
        """A simple ellipsis matches everything."""
 
191
        self.run_script("""
 
192
        $ echo foo
 
193
        ...
 
194
        """)
 
195
 
 
196
    def test_ellipsis_matches_empty(self):
 
197
        self.run_script("""
 
198
        $ cd .
 
199
        ...
 
200
        """)
125
201
 
126
202
    def test_stops_on_unexpected_output(self):
127
203
        story = """
131
207
"""
132
208
        self.assertRaises(AssertionError, self.run_script, story)
133
209
 
134
 
 
135
210
    def test_stops_on_unexpected_error(self):
136
211
        story = """
137
212
$ cat
151
226
        # The status matters, not the output
152
227
        story = """
153
228
$ bzr init
 
229
...
154
230
$ cat >file
155
231
<Hello
156
232
$ bzr add file
 
233
...
157
234
$ bzr commit -m 'adding file'
 
235
2>...
158
236
"""
159
237
        self.run_script(story)
160
238
 
206
284
cat dog "chicken" 'dragon'
207
285
""")
208
286
 
 
287
    def test_verbosity_isolated(self):
 
288
        """Global verbosity is isolated from commands run in scripts.
 
289
        """
 
290
        # see also 656694; we should get rid of global verbosity
 
291
        self.run_script("""
 
292
        $ bzr init --quiet a
 
293
        """)
 
294
        self.assertEquals(trace.is_quiet(), False)
 
295
 
209
296
 
210
297
class TestCat(script.TestCaseWithTransportAndScript):
211
298
 
317
404
class TestBzr(script.TestCaseWithTransportAndScript):
318
405
 
319
406
    def test_bzr_smoke(self):
320
 
        self.run_script('$ bzr init branch')
 
407
        self.run_script("""
 
408
            $ bzr init branch
 
409
            Created a standalone tree (format: ...)
 
410
            """)
321
411
        self.failUnlessExists('branch')
322
412
 
323
413
 
365
455
        self.assertEquals(None, err)
366
456
        self.assertFileEqual('hello\nhappy\n', 'file')
367
457
 
 
458
    def test_empty_line_in_output_is_respected(self):
 
459
        self.run_script("""
 
460
            $ echo
 
461
 
 
462
            $ echo bar
 
463
            bar
 
464
            """)
 
465
 
368
466
 
369
467
class TestRm(script.TestCaseWithTransportAndScript):
370
468
 
447
545
        self.failIfExists('file')
448
546
        self.failUnlessExists('dir/file')
449
547
 
 
548
 
 
549
class cmd_test_confirm(commands.Command):
 
550
 
 
551
    def run(self):
 
552
        if ui.ui_factory.get_boolean(
 
553
            'Really do it',
 
554
            # 'bzrlib.tests.test_script.confirm',
 
555
            # {}
 
556
            ):
 
557
            self.outf.write('Do it!\n')
 
558
        else:
 
559
            print 'ok, no'
 
560
 
 
561
 
 
562
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
563
 
 
564
    def test_confirm_action(self):
 
565
        """You can write tests that demonstrate user confirmation.
 
566
        
 
567
        Specifically, ScriptRunner does't care if the output line for the prompt
 
568
        isn't terminated by a newline from the program; it's implicitly terminated 
 
569
        by the input.
 
570
        """
 
571
        commands.builtin_command_registry.register(cmd_test_confirm)
 
572
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
573
        self.run_script("""
 
574
            $ bzr test-confirm
 
575
            2>Really do it? [y/n]: 
 
576
            <yes
 
577
            Do it!
 
578
            $ bzr test-confirm
 
579
            2>Really do it? [y/n]: 
 
580
            <no
 
581
            ok, no
 
582
            """)
 
583