/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 brzlib/tests/test_script.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
from breezy import (
 
18
from brzlib import (
19
19
    commands,
20
20
    osutils,
21
21
    tests,
22
22
    trace,
23
23
    ui,
24
24
    )
25
 
from breezy.tests import script
 
25
from brzlib.tests import script
26
26
 
27
27
 
28
28
class TestSyntax(tests.TestCase):
44
44
    def test_trim_blank_lines(self):
45
45
        """Blank lines are respected, but trimmed at the start and end.
46
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
 
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
49
        need special syntax to avoid them.
50
50
 
51
51
        However we do want to be able to match commands that emit blank lines.
60
60
 
61
61
    def test_simple_command(self):
62
62
        self.assertEqual([(['cd', 'trunk'], None, None, None)],
63
 
                         script._script_to_commands('$ cd trunk'))
 
63
                           script._script_to_commands('$ cd trunk'))
64
64
 
65
65
    def test_command_with_single_quoted_param(self):
66
 
        story = """$ brz commit -m 'two words'"""
67
 
        self.assertEqual([(['brz', 'commit', '-m', "'two words'"],
68
 
                           None, None, None)],
69
 
                         script._script_to_commands(story))
 
66
        story = """$ bzr commit -m 'two words'"""
 
67
        self.assertEqual([(['bzr', 'commit', '-m', "'two words'"],
 
68
                            None, None, None)],
 
69
                           script._script_to_commands(story))
70
70
 
71
71
    def test_command_with_double_quoted_param(self):
72
 
        story = """$ brz commit -m "two words" """
73
 
        self.assertEqual([(['brz', 'commit', '-m', '"two words"'],
74
 
                           None, None, None)],
75
 
                         script._script_to_commands(story))
 
72
        story = """$ bzr commit -m "two words" """
 
73
        self.assertEqual([(['bzr', 'commit', '-m', '"two words"'],
 
74
                            None, None, None)],
 
75
                           script._script_to_commands(story))
76
76
 
77
77
    def test_command_with_input(self):
78
78
        self.assertEqual(
83
83
        # scripts are commonly given indented within the test source code, and
84
84
        # common indentation is stripped off
85
85
        story = """
86
 
            $ brz add
 
86
            $ bzr add
87
87
            adding file
88
88
            adding file2
89
89
            """
90
 
        self.assertEqual([(['brz', 'add'], None,
91
 
                           'adding file\nadding file2\n', None)],
92
 
                         script._script_to_commands(story))
 
90
        self.assertEqual([(['bzr', 'add'], None,
 
91
                            'adding file\nadding file2\n', None)],
 
92
                          script._script_to_commands(story))
93
93
 
94
94
    def test_command_with_output(self):
95
95
        story = """
96
 
$ brz add
 
96
$ bzr add
97
97
adding file
98
98
adding file2
99
99
"""
100
 
        self.assertEqual([(['brz', 'add'], None,
101
 
                           'adding file\nadding file2\n', None)],
102
 
                         script._script_to_commands(story))
 
100
        self.assertEqual([(['bzr', 'add'], None,
 
101
                            'adding file\nadding file2\n', None)],
 
102
                          script._script_to_commands(story))
103
103
 
104
104
    def test_command_with_error(self):
105
105
        story = """
106
 
$ brz branch foo
107
 
2>brz: ERROR: Not a branch: "foo"
 
106
$ bzr branch foo
 
107
2>bzr: ERROR: Not a branch: "foo"
108
108
"""
109
 
        self.assertEqual([(['brz', 'branch', 'foo'],
110
 
                           None, None, 'brz: ERROR: Not a branch: "foo"\n')],
111
 
                         script._script_to_commands(story))
 
109
        self.assertEqual([(['bzr', 'branch', 'foo'],
 
110
                            None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
 
111
                          script._script_to_commands(story))
112
112
 
113
113
    def test_input_without_command(self):
114
114
        self.assertRaises(SyntaxError, script._script_to_commands, '<input')
118
118
 
119
119
    def test_command_with_backquotes(self):
120
120
        story = """
121
 
$ foo = `brz file-id toto`
 
121
$ foo = `bzr file-id toto`
122
122
"""
123
 
        self.assertEqual([(['foo', '=', '`brz file-id toto`'],
124
 
                           None, None, None)],
125
 
                         script._script_to_commands(story))
 
123
        self.assertEqual([(['foo', '=', '`bzr file-id toto`'],
 
124
                            None, None, None)],
 
125
                          script._script_to_commands(story))
126
126
 
127
127
 
128
128
class TestRedirections(tests.TestCase):
143
143
        self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz'])
144
144
 
145
145
    def test_output_redirection(self):
146
 
        self._check(None, 'foo', 'w+', [], ['>foo'])
147
 
        self._check(None, 'foo', 'w+', ['bar'], ['bar', '>foo'])
148
 
        self._check(None, 'foo', 'w+', ['bar'], ['bar', '>', 'foo'])
149
 
        self._check(None, 'foo', 'a+', [], ['>>foo'])
150
 
        self._check(None, 'foo', 'a+', ['bar'], ['bar', '>>foo'])
151
 
        self._check(None, 'foo', 'a+', ['bar'], ['bar', '>>', 'foo'])
 
146
        self._check(None, 'foo', 'wb+', [], ['>foo'])
 
147
        self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo'])
 
148
        self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo'])
 
149
        self._check(None, 'foo', 'ab+', [], ['>>foo'])
 
150
        self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo'])
 
151
        self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo'])
152
152
 
153
153
    def test_redirection_syntax_errors(self):
154
154
        self._check('', None, None, [], ['<'])
155
 
        self._check(None, '', 'w+', [], ['>'])
156
 
        self._check(None, '', 'a+', [], ['>>'])
157
 
        self._check('>', '', 'a+', [], ['<', '>', '>>'])
 
155
        self._check(None, '', 'wb+', [], ['>'])
 
156
        self._check(None, '', 'ab+', [], ['>>'])
 
157
        self._check('>', '', 'ab+', [], ['<', '>', '>>'])
 
158
 
158
159
 
159
160
 
160
161
class TestExecution(script.TestCaseWithTransportAndScript):
175
176
 
176
177
    def test_blank_output_mismatches_output(self):
177
178
        """If you give output, the output must actually be blank.
178
 
 
 
179
        
179
180
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
180
181
        output was a wildcard.  Now you must say ... if you want that.
181
182
        """
182
183
        self.assertRaises(AssertionError,
183
 
                          self.run_script,
184
 
                          """
 
184
            self.run_script,
 
185
            """
185
186
            $ echo foo
186
187
            """)
187
188
 
188
189
    def test_null_output_matches_option(self):
189
 
        """If you want null output to be a wild card, you can pass
 
190
        """If you want null output to be a wild card, you can pass 
190
191
        null_output_matches_anything to run_script"""
191
192
        self.run_script(
192
193
            """
218
219
        story = """
219
220
$ cat
220
221
<Hello
221
 
$ brz not-a-command
 
222
$ bzr not-a-command
222
223
"""
223
224
        self.assertRaises(AssertionError, self.run_script, story)
224
225
 
225
226
    def test_continue_on_expected_error(self):
226
227
        story = """
227
 
$ brz not-a-command
 
228
$ bzr not-a-command
228
229
2>..."not-a-command"
229
230
"""
230
231
        self.run_script(story)
232
233
    def test_continue_on_error_output(self):
233
234
        # The status matters, not the output
234
235
        story = """
235
 
$ brz init
 
236
$ bzr init
236
237
...
237
238
$ cat >file
238
239
<Hello
239
 
$ brz add file
 
240
$ bzr add file
240
241
...
241
 
$ brz commit -m 'adding file'
 
242
$ bzr commit -m 'adding file'
242
243
2>...
243
244
"""
244
245
        self.run_script(story)
255
256
"""
256
257
        self.run_script(story)
257
258
        story = """
258
 
$ brz not-a-command
 
259
$ bzr not-a-command
259
260
2>..."not-a-command"
260
261
"""
261
262
        self.run_script(story)
262
263
 
263
264
        story = """
264
 
$ brz branch not-a-branch
265
 
2>brz: ERROR: Not a branch...not-a-branch/".
 
265
$ bzr branch not-a-branch
 
266
2>bzr: ERROR: Not a branch...not-a-branch/".
266
267
"""
267
268
        self.run_script(story)
268
269
 
296
297
        """
297
298
        # see also 656694; we should get rid of global verbosity
298
299
        self.run_script("""
299
 
        $ brz init --quiet a
 
300
        $ bzr init --quiet a
300
301
        """)
301
302
        self.assertEqual(trace.is_quiet(), False)
302
303
 
313
314
        self.assertEqual(None, err)
314
315
 
315
316
    def test_cat_file_to_output(self):
316
 
        self.build_tree_contents([('file', b'content\n')])
 
317
        self.build_tree_contents([('file', 'content\n')])
317
318
        retcode, out, err = self.run_command(['cat', 'file'],
318
319
                                             None, 'content\n', None)
319
320
        self.assertEqual('content\n', out)
332
333
        self.assertEqual(None, err)
333
334
 
334
335
    def test_cat_file_to_file(self):
335
 
        self.build_tree_contents([('file', b'content\n')])
 
336
        self.build_tree_contents([('file', 'content\n')])
336
337
        retcode, out, err = self.run_command(['cat', 'file', '>file2'],
337
338
                                             None, None, None)
338
 
        self.assertFileEqual(b'content\n', 'file2')
 
339
        self.assertFileEqual('content\n', 'file2')
339
340
 
340
341
    def test_cat_files_to_file(self):
341
 
        self.build_tree_contents([('cat', b'cat\n')])
342
 
        self.build_tree_contents([('dog', b'dog\n')])
 
342
        self.build_tree_contents([('cat', 'cat\n')])
 
343
        self.build_tree_contents([('dog', 'dog\n')])
343
344
        retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],
344
345
                                             None, None, None)
345
 
        self.assertFileEqual(b'cat\ndog\n', 'file')
 
346
        self.assertFileEqual('cat\ndog\n', 'file')
346
347
 
347
348
    def test_cat_bogus_input_file(self):
348
349
        self.run_script("""
373
374
 
374
375
    def test_mkdir_jailed(self):
375
376
        self.assertRaises(ValueError, self.run_script, '$ mkdir /out-of-jail')
376
 
        self.assertRaises(ValueError, self.run_script,
377
 
                          '$ mkdir ../out-of-jail')
 
377
        self.assertRaises(ValueError, self.run_script, '$ mkdir ../out-of-jail')
378
378
 
379
379
    def test_mkdir_in_jail(self):
380
380
        self.run_script("""
403
403
$ cd dir
404
404
""")
405
405
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
406
 
                         osutils.getcwd())
 
406
                          osutils.getcwd())
407
407
 
408
408
        self.run_script('$ cd')
409
409
        self.assertEqual(self.test_dir, osutils.getcwd())
410
410
 
411
411
 
412
 
class TestBrz(script.TestCaseWithTransportAndScript):
 
412
class TestBzr(script.TestCaseWithTransportAndScript):
413
413
 
414
 
    def test_brz_smoke(self):
 
414
    def test_bzr_smoke(self):
415
415
        self.run_script("""
416
 
            $ brz init branch
 
416
            $ bzr init branch
417
417
            Created a standalone tree (format: ...)
418
418
            """)
419
419
        self.assertPathExists('branch')
456
456
                                             None, None, None)
457
457
        self.assertEqual(None, out)
458
458
        self.assertEqual(None, err)
459
 
        self.assertFileEqual(b'hello\n', 'file')
 
459
        self.assertFileEqual('hello\n', 'file')
460
460
        retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
461
461
                                             None, None, None)
462
462
        self.assertEqual(None, out)
463
463
        self.assertEqual(None, err)
464
 
        self.assertFileEqual(b'hello\nhappy\n', 'file')
 
464
        self.assertFileEqual('hello\nhappy\n', 'file')
465
465
 
466
466
    def test_empty_line_in_output_is_respected(self):
467
467
        self.run_script("""
558
558
 
559
559
    def run(self):
560
560
        if ui.ui_factory.get_boolean(
561
 
                u'Really do it',
562
 
                # 'breezy.tests.test_script.confirm',
563
 
                # {}
564
 
                ):
 
561
            u'Really do it',
 
562
            # 'brzlib.tests.test_script.confirm',
 
563
            # {}
 
564
            ):
565
565
            self.outf.write('Do it!\n')
566
566
        else:
567
 
            print('ok, no')
 
567
            print 'ok, no'
568
568
 
569
569
 
570
570
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
571
571
 
572
572
    def test_confirm_action(self):
573
573
        """You can write tests that demonstrate user confirmation.
574
 
 
 
574
        
575
575
        Specifically, ScriptRunner does't care if the output line for the
576
576
        prompt isn't terminated by a newline from the program; it's implicitly
577
577
        terminated by the input.
578
578
        """
579
579
        commands.builtin_command_registry.register(cmd_test_confirm)
580
 
        self.addCleanup(
581
 
            commands.builtin_command_registry.remove, 'test-confirm')
 
580
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
582
581
        self.run_script("""
583
 
            $ brz test-confirm
 
582
            $ bzr test-confirm
584
583
            2>Really do it? ([y]es, [n]o): yes
585
584
            <y
586
585
            Do it!
587
 
            $ brz test-confirm
 
586
            $ bzr test-confirm
588
587
            2>Really do it? ([y]es, [n]o): no
589
588
            <n
590
589
            ok, no
591
590
            """)
592
591
 
593
 
 
594
592
class TestShelve(script.TestCaseWithTransportAndScript):
595
593
 
596
594
    def setUp(self):
597
595
        super(TestShelve, self).setUp()
598
596
        self.run_script("""
599
 
            $ brz init test
 
597
            $ bzr init test
600
598
            Created a standalone tree (format: 2a)
601
599
            $ cd test
602
600
            $ echo foo > file
603
 
            $ brz add
 
601
            $ bzr add
604
602
            adding file
605
 
            $ brz commit -m 'file added'
 
603
            $ bzr commit -m 'file added'
606
604
            2>Committing to:...test/
607
605
            2>added file
608
606
            2>Committed revision 1.
611
609
 
612
610
    def test_shelve(self):
613
611
        self.run_script("""
614
 
            $ brz shelve -m 'shelve bar'
 
612
            $ bzr shelve -m 'shelve bar'
615
613
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): yes
616
614
            <y
617
615
            2>Selected changes:
622
620
            """,
623
621
                        null_output_matches_anything=True)
624
622
        self.run_script("""
625
 
            $ brz shelve --list
 
623
            $ bzr shelve --list
626
624
              1: shelve bar
627
625
            """)
628
626
 
629
627
    def test_dont_shelve(self):
630
628
        # We intentionally provide no input here to test EOF
631
 
        self.run_script((
632
 
            "$ brz shelve -m 'shelve bar'\n"
633
 
            "2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): \n"
634
 
            "2>No changes to shelve.\n"
635
 
            ), null_output_matches_anything=True)
636
 
        self.run_script("""
637
 
            $ brz st
 
629
        self.run_script("""
 
630
            $ bzr shelve -m 'shelve bar'
 
631
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): 
 
632
            2>No changes to shelve.
 
633
            """,
 
634
                        null_output_matches_anything=True)
 
635
        self.run_script("""
 
636
            $ bzr st
638
637
            modified:
639
638
              file
640
639
            """)