/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: Vincent Ladeuil
  • Date: 2010-10-15 12:35:00 UTC
  • mto: This revision was merged to the branch mainline in revision 5502.
  • Revision ID: v.ladeuil+lp@free.fr-20101015123500-iyqj7e0r62ie6qfy
Unbreak pqm by commenting out the bogus use of doctest +SKIP not supported by python2.4

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
123
163
    def test_unknown_command(self):
124
164
        self.assertRaises(SyntaxError, self.run_script, 'foo')
125
165
 
 
166
    def test_blank_output_mismatches_output(self):
 
167
        """If you give output, the output must actually be blank.
 
168
        
 
169
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
 
170
        output was a wildcard.  Now you must say ... if you want that.
 
171
        """
 
172
        self.assertRaises(AssertionError,
 
173
            self.run_script,
 
174
            """
 
175
            $ echo foo
 
176
            """)
 
177
 
 
178
    def test_ellipsis_everything(self):
 
179
        """A simple ellipsis matches everything."""
 
180
        self.run_script("""
 
181
        $ echo foo
 
182
        ...
 
183
        """)
 
184
 
 
185
    def test_ellipsis_matches_empty(self):
 
186
        self.run_script("""
 
187
        $ cd .
 
188
        ...
 
189
        """)
 
190
 
126
191
    def test_stops_on_unexpected_output(self):
127
192
        story = """
128
193
$ mkdir dir
131
196
"""
132
197
        self.assertRaises(AssertionError, self.run_script, story)
133
198
 
134
 
 
135
199
    def test_stops_on_unexpected_error(self):
136
200
        story = """
137
201
$ cat
151
215
        # The status matters, not the output
152
216
        story = """
153
217
$ bzr init
 
218
...
154
219
$ cat >file
155
220
<Hello
156
221
$ bzr add file
 
222
...
157
223
$ bzr commit -m 'adding file'
 
224
2>...
158
225
"""
159
226
        self.run_script(story)
160
227
 
206
273
cat dog "chicken" 'dragon'
207
274
""")
208
275
 
 
276
    def test_verbosity_isolated(self):
 
277
        """Global verbosity is isolated from commands run in scripts.
 
278
        """
 
279
        # see also 656694; we should get rid of global verbosity
 
280
        self.run_script("""
 
281
        $ bzr init --quiet a
 
282
        """)
 
283
        self.assertEquals(trace.is_quiet(), False)
 
284
 
209
285
 
210
286
class TestCat(script.TestCaseWithTransportAndScript):
211
287
 
317
393
class TestBzr(script.TestCaseWithTransportAndScript):
318
394
 
319
395
    def test_bzr_smoke(self):
320
 
        self.run_script('$ bzr init branch')
 
396
        self.run_script("""
 
397
            $ bzr init branch
 
398
            Created a standalone tree (format: ...)
 
399
            """)
321
400
        self.failUnlessExists('branch')
322
401
 
323
402
 
365
444
        self.assertEquals(None, err)
366
445
        self.assertFileEqual('hello\nhappy\n', 'file')
367
446
 
 
447
    def test_empty_line_in_output_is_respected(self):
 
448
        self.run_script("""
 
449
            $ echo
 
450
 
 
451
            $ echo bar
 
452
            bar
 
453
            """)
 
454
 
368
455
 
369
456
class TestRm(script.TestCaseWithTransportAndScript):
370
457
 
447
534
        self.failIfExists('file')
448
535
        self.failUnlessExists('dir/file')
449
536
 
 
537
 
 
538
class cmd_test_confirm(commands.Command):
 
539
 
 
540
    def run(self):
 
541
        if ui.ui_factory.get_boolean(
 
542
            'Really do it',
 
543
            # 'bzrlib.tests.test_script.confirm',
 
544
            # {}
 
545
            ):
 
546
            self.outf.write('Do it!\n')
 
547
        else:
 
548
            print 'ok, no'
 
549
 
 
550
 
 
551
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
552
 
 
553
    def test_confirm_action(self):
 
554
        """You can write tests that demonstrate user confirmation.
 
555
        
 
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.
 
559
        """
 
560
        commands.builtin_command_registry.register(cmd_test_confirm)
 
561
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
562
        self.run_script("""
 
563
            $ bzr test-confirm
 
564
            2>Really do it? [y/n]: 
 
565
            <yes
 
566
            Do it!
 
567
            $ bzr test-confirm
 
568
            2>Really do it? [y/n]: 
 
569
            <no
 
570
            ok, no
 
571
            """)
 
572