~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Vincent Ladeuil
  • Date: 2010-06-17 16:54:26 UTC
  • mto: This revision was merged to the branch mainline in revision 5306.
  • Revision ID: v.ladeuil+lp@free.fr-20100617165426-741tbmgwi62a9zub
Pass BZR_PLUGINS_AT and BZR_DISABLE_PLINGS to the subprocess fpr test_import_tariff

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
from bzrlib import (
19
 
    commands,
20
19
    osutils,
21
20
    tests,
22
 
    trace,
23
 
    ui,
24
21
    )
25
22
from bzrlib.tests import script
26
23
 
30
27
    def test_comment_is_ignored(self):
31
28
        self.assertEquals([], script._script_to_commands('#comment\n'))
32
29
 
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
 
            """))
 
30
    def test_empty_line_is_ignored(self):
 
31
        self.assertEquals([], script._script_to_commands('\n'))
60
32
 
61
33
    def test_simple_command(self):
62
34
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
163
135
    def test_unknown_command(self):
164
136
        self.assertRaises(SyntaxError, self.run_script, 'foo')
165
137
 
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
 
 
191
138
    def test_stops_on_unexpected_output(self):
192
139
        story = """
193
140
$ mkdir dir
196
143
"""
197
144
        self.assertRaises(AssertionError, self.run_script, story)
198
145
 
 
146
 
199
147
    def test_stops_on_unexpected_error(self):
200
148
        story = """
201
149
$ cat
215
163
        # The status matters, not the output
216
164
        story = """
217
165
$ bzr init
218
 
...
219
166
$ cat >file
220
167
<Hello
221
168
$ bzr add file
222
 
...
223
169
$ bzr commit -m 'adding file'
224
 
2>...
225
170
"""
226
171
        self.run_script(story)
227
172
 
273
218
cat dog "chicken" 'dragon'
274
219
""")
275
220
 
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
 
 
285
221
 
286
222
class TestCat(script.TestCaseWithTransportAndScript):
287
223
 
393
329
class TestBzr(script.TestCaseWithTransportAndScript):
394
330
 
395
331
    def test_bzr_smoke(self):
396
 
        self.run_script("""
397
 
            $ bzr init branch
398
 
            Created a standalone tree (format: ...)
399
 
            """)
 
332
        self.run_script('$ bzr init branch')
400
333
        self.failUnlessExists('branch')
401
334
 
402
335
 
444
377
        self.assertEquals(None, err)
445
378
        self.assertFileEqual('hello\nhappy\n', 'file')
446
379
 
447
 
    def test_empty_line_in_output_is_respected(self):
448
 
        self.run_script("""
449
 
            $ echo
450
 
 
451
 
            $ echo bar
452
 
            bar
453
 
            """)
454
 
 
455
380
 
456
381
class TestRm(script.TestCaseWithTransportAndScript):
457
382
 
534
459
        self.failIfExists('file')
535
460
        self.failUnlessExists('dir/file')
536
461
 
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