/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-09-13 08:14:44 UTC
  • mto: (5416.1.8 ui-factory)
  • mto: This revision was merged to the branch mainline in revision 5422.
  • Revision ID: mbp@sourcefrog.net-20100913081444-63v2l3wqb9e45ab3
Better handling of blank lines in test scripts

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_trim_blank_lines(self):
 
33
        """Blank lines are respected, but trimmed at the start and end.
 
34
 
 
35
        Python triple-quoted syntax is going to give stubby/empty blank lines 
 
36
        right at the start and the end.  These are cut off so that callers don't 
 
37
        need special syntax to avoid them.
 
38
 
 
39
        However we do want to be able to match commands that emit blank lines.
 
40
        """
 
41
        self.assertEquals([
 
42
            (['bar'], None, '\n', None),
 
43
            ],
 
44
            script._script_to_commands("""
 
45
            $bar
 
46
 
 
47
            """))
32
48
 
33
49
    def test_simple_command(self):
34
50
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
51
67
            [(['cat', '>file'], 'content\n', None, None)],
52
68
            script._script_to_commands('$ cat >file\n<content\n'))
53
69
 
 
70
    def test_indented(self):
 
71
        # scripts are commonly given indented within the test source code, and
 
72
        # common indentation is stripped off
 
73
        story = """
 
74
            $ bzr add
 
75
            adding file
 
76
            adding file2
 
77
            """
 
78
        self.assertEquals([(['bzr', 'add'], None,
 
79
                            'adding file\nadding file2\n', None)],
 
80
                          script._script_to_commands(story))
 
81
 
54
82
    def test_command_with_output(self):
55
83
        story = """
56
84
$ bzr add
365
393
        self.assertEquals(None, err)
366
394
        self.assertFileEqual('hello\nhappy\n', 'file')
367
395
 
 
396
    def test_empty_line_in_output_is_respected(self):
 
397
        self.run_script("""
 
398
            $ echo
 
399
 
 
400
            $ echo bar
 
401
            bar
 
402
            """)
 
403
 
368
404
 
369
405
class TestRm(script.TestCaseWithTransportAndScript):
370
406
 
447
483
        self.failIfExists('file')
448
484
        self.failUnlessExists('dir/file')
449
485
 
 
486
 
 
487
class cmd_test_confirm(commands.Command):
 
488
 
 
489
    def run(self):
 
490
        if ui.ui_factory.get_boolean(
 
491
            'Really do it',
 
492
            # 'bzrlib.tests.test_script.confirm',
 
493
            # {}
 
494
            ):
 
495
            self.outf.write('Do it!\n')
 
496
        else:
 
497
            print 'ok, no'
 
498
 
 
499
 
 
500
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
501
 
 
502
    def test_confirm_action(self):
 
503
        """You can write tests that demonstrate user confirmation.
 
504
        
 
505
        Specifically, ScriptRunner does't care if the output line for the prompt
 
506
        isn't terminated by a newline from the program; it's implicitly terminated 
 
507
        by the input.
 
508
        """
 
509
        commands.builtin_command_registry.register(cmd_test_confirm)
 
510
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
511
        self.run_script("""
 
512
            $ bzr test-confirm
 
513
            2>Really do it? [y/n]: 
 
514
            <yes
 
515
            Do it!
 
516
            $ bzr test-confirm
 
517
            2>Really do it? [y/n]: 
 
518
            <no
 
519
            ok, no
 
520
            """)
 
521