/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
from breezy import (
 
18
from bzrlib 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 bzrlib.tests import script
26
26
 
27
27
 
28
28
class TestSyntax(tests.TestCase):
29
29
 
30
30
    def test_comment_is_ignored(self):
31
 
        self.assertEqual([], script._script_to_commands('#comment\n'))
 
31
        self.assertEquals([], script._script_to_commands('#comment\n'))
32
32
 
33
33
    def test_comment_multiple_lines(self):
34
 
        self.assertEqual([
 
34
        self.assertEquals([
35
35
            (['bar'], None, None, None),
36
36
            ],
37
37
            script._script_to_commands("""
50
50
 
51
51
        However we do want to be able to match commands that emit blank lines.
52
52
        """
53
 
        self.assertEqual([
 
53
        self.assertEquals([
54
54
            (['bar'], None, '\n', None),
55
55
            ],
56
56
            script._script_to_commands("""
59
59
            """))
60
60
 
61
61
    def test_simple_command(self):
62
 
        self.assertEqual([(['cd', 'trunk'], None, None, None)],
 
62
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
63
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'"],
 
66
        story = """$ bzr commit -m 'two words'"""
 
67
        self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],
68
68
                            None, None, None)],
69
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"'],
 
72
        story = """$ bzr commit -m "two words" """
 
73
        self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],
74
74
                            None, None, None)],
75
75
                           script._script_to_commands(story))
76
76
 
77
77
    def test_command_with_input(self):
78
 
        self.assertEqual(
 
78
        self.assertEquals(
79
79
            [(['cat', '>file'], 'content\n', None, None)],
80
80
            script._script_to_commands('$ cat >file\n<content\n'))
81
81
 
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,
 
90
        self.assertEquals([(['bzr', 'add'], None,
91
91
                            'adding file\nadding file2\n', None)],
92
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,
 
100
        self.assertEquals([(['bzr', 'add'], None,
101
101
                            'adding file\nadding file2\n', None)],
102
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')],
 
109
        self.assertEquals([(['bzr', 'branch', 'foo'],
 
110
                            None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
111
111
                          script._script_to_commands(story))
112
112
 
113
113
    def test_input_without_command(self):
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`'],
 
123
        self.assertEquals([(['foo', '=', '`bzr file-id toto`'],
124
124
                            None, None, None)],
125
125
                          script._script_to_commands(story))
126
126
 
172
172
        """
173
173
        e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
174
        self.assertContainsRe(e.msg, "not found.*foo")
175
 
        self.assertEqual(e.text, "foo --frob")
 
175
        self.assertEquals(e.text, "foo --frob")
176
176
 
177
177
    def test_blank_output_mismatches_output(self):
178
178
        """If you give output, the output must actually be blank.
219
219
        story = """
220
220
$ cat
221
221
<Hello
222
 
$ brz not-a-command
 
222
$ bzr not-a-command
223
223
"""
224
224
        self.assertRaises(AssertionError, self.run_script, story)
225
225
 
226
226
    def test_continue_on_expected_error(self):
227
227
        story = """
228
 
$ brz not-a-command
 
228
$ bzr not-a-command
229
229
2>..."not-a-command"
230
230
"""
231
231
        self.run_script(story)
233
233
    def test_continue_on_error_output(self):
234
234
        # The status matters, not the output
235
235
        story = """
236
 
$ brz init
 
236
$ bzr init
237
237
...
238
238
$ cat >file
239
239
<Hello
240
 
$ brz add file
 
240
$ bzr add file
241
241
...
242
 
$ brz commit -m 'adding file'
 
242
$ bzr commit -m 'adding file'
243
243
2>...
244
244
"""
245
245
        self.run_script(story)
256
256
"""
257
257
        self.run_script(story)
258
258
        story = """
259
 
$ brz not-a-command
 
259
$ bzr not-a-command
260
260
2>..."not-a-command"
261
261
"""
262
262
        self.run_script(story)
263
263
 
264
264
        story = """
265
 
$ brz branch not-a-branch
266
 
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/".
267
267
"""
268
268
        self.run_script(story)
269
269
 
297
297
        """
298
298
        # see also 656694; we should get rid of global verbosity
299
299
        self.run_script("""
300
 
        $ brz init --quiet a
 
300
        $ bzr init --quiet a
301
301
        """)
302
 
        self.assertEqual(trace.is_quiet(), False)
 
302
        self.assertEquals(trace.is_quiet(), False)
303
303
 
304
304
 
305
305
class TestCat(script.TestCaseWithTransportAndScript):
310
310
    def test_cat_input_to_output(self):
311
311
        retcode, out, err = self.run_command(['cat'],
312
312
                                             'content\n', 'content\n', None)
313
 
        self.assertEqual('content\n', out)
314
 
        self.assertEqual(None, err)
 
313
        self.assertEquals('content\n', out)
 
314
        self.assertEquals(None, err)
315
315
 
316
316
    def test_cat_file_to_output(self):
317
 
        self.build_tree_contents([('file', b'content\n')])
 
317
        self.build_tree_contents([('file', 'content\n')])
318
318
        retcode, out, err = self.run_command(['cat', 'file'],
319
319
                                             None, 'content\n', None)
320
 
        self.assertEqual('content\n', out)
321
 
        self.assertEqual(None, err)
 
320
        self.assertEquals('content\n', out)
 
321
        self.assertEquals(None, err)
322
322
 
323
323
    def test_cat_input_to_file(self):
324
324
        retcode, out, err = self.run_command(['cat', '>file'],
325
325
                                             'content\n', None, None)
326
326
        self.assertFileEqual('content\n', 'file')
327
 
        self.assertEqual(None, out)
328
 
        self.assertEqual(None, err)
 
327
        self.assertEquals(None, out)
 
328
        self.assertEquals(None, err)
329
329
        retcode, out, err = self.run_command(['cat', '>>file'],
330
330
                                             'more\n', None, None)
331
331
        self.assertFileEqual('content\nmore\n', 'file')
332
 
        self.assertEqual(None, out)
333
 
        self.assertEqual(None, err)
 
332
        self.assertEquals(None, out)
 
333
        self.assertEquals(None, err)
334
334
 
335
335
    def test_cat_file_to_file(self):
336
 
        self.build_tree_contents([('file', b'content\n')])
 
336
        self.build_tree_contents([('file', 'content\n')])
337
337
        retcode, out, err = self.run_command(['cat', 'file', '>file2'],
338
338
                                             None, None, None)
339
339
        self.assertFileEqual('content\n', 'file2')
340
340
 
341
341
    def test_cat_files_to_file(self):
342
 
        self.build_tree_contents([('cat', b'cat\n')])
343
 
        self.build_tree_contents([('dog', b'dog\n')])
 
342
        self.build_tree_contents([('cat', 'cat\n')])
 
343
        self.build_tree_contents([('dog', 'dog\n')])
344
344
        retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],
345
345
                                             None, None, None)
346
346
        self.assertFileEqual('cat\ndog\n', 'file')
397
397
        self.assertRaises(ValueError, self.run_script, '$ cd ..')
398
398
 
399
399
    def test_cd_dir_and_back_home(self):
400
 
        self.assertEqual(self.test_dir, osutils.getcwd())
 
400
        self.assertEquals(self.test_dir, osutils.getcwd())
401
401
        self.run_script("""
402
402
$ mkdir dir
403
403
$ cd dir
404
404
""")
405
 
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
 
405
        self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),
406
406
                          osutils.getcwd())
407
407
 
408
408
        self.run_script('$ cd')
409
 
        self.assertEqual(self.test_dir, osutils.getcwd())
410
 
 
411
 
 
412
 
class TestBrz(script.TestCaseWithTransportAndScript):
413
 
 
414
 
    def test_brz_smoke(self):
 
409
        self.assertEquals(self.test_dir, osutils.getcwd())
 
410
 
 
411
 
 
412
class TestBzr(script.TestCaseWithTransportAndScript):
 
413
 
 
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')
435
435
 
436
436
    def test_echo_to_output(self):
437
437
        retcode, out, err = self.run_command(['echo'], None, '\n', None)
438
 
        self.assertEqual('\n', out)
439
 
        self.assertEqual(None, err)
 
438
        self.assertEquals('\n', out)
 
439
        self.assertEquals(None, err)
440
440
 
441
441
    def test_echo_some_to_output(self):
442
442
        retcode, out, err = self.run_command(['echo', 'hello'],
443
443
                                             None, 'hello\n', None)
444
 
        self.assertEqual('hello\n', out)
445
 
        self.assertEqual(None, err)
 
444
        self.assertEquals('hello\n', out)
 
445
        self.assertEquals(None, err)
446
446
 
447
447
    def test_echo_more_output(self):
448
448
        retcode, out, err = self.run_command(
449
449
            ['echo', 'hello', 'happy', 'world'],
450
450
            None, 'hello happy world\n', None)
451
 
        self.assertEqual('hello happy world\n', out)
452
 
        self.assertEqual(None, err)
 
451
        self.assertEquals('hello happy world\n', out)
 
452
        self.assertEquals(None, err)
453
453
 
454
454
    def test_echo_appended(self):
455
455
        retcode, out, err = self.run_command(['echo', 'hello', '>file'],
456
456
                                             None, None, None)
457
 
        self.assertEqual(None, out)
458
 
        self.assertEqual(None, err)
 
457
        self.assertEquals(None, out)
 
458
        self.assertEquals(None, err)
459
459
        self.assertFileEqual('hello\n', 'file')
460
460
        retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
461
461
                                             None, None, None)
462
 
        self.assertEqual(None, out)
463
 
        self.assertEqual(None, err)
 
462
        self.assertEquals(None, out)
 
463
        self.assertEquals(None, err)
464
464
        self.assertFileEqual('hello\nhappy\n', 'file')
465
465
 
466
466
    def test_empty_line_in_output_is_respected(self):
559
559
    def run(self):
560
560
        if ui.ui_factory.get_boolean(
561
561
            u'Really do it',
562
 
            # 'breezy.tests.test_script.confirm',
 
562
            # 'bzrlib.tests.test_script.confirm',
563
563
            # {}
564
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):
579
579
        commands.builtin_command_registry.register(cmd_test_confirm)
580
580
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
581
581
        self.run_script("""
582
 
            $ brz test-confirm
 
582
            $ bzr test-confirm
583
583
            2>Really do it? ([y]es, [n]o): yes
584
584
            <y
585
585
            Do it!
586
 
            $ brz test-confirm
 
586
            $ bzr test-confirm
587
587
            2>Really do it? ([y]es, [n]o): no
588
588
            <n
589
589
            ok, no
594
594
    def setUp(self):
595
595
        super(TestShelve, self).setUp()
596
596
        self.run_script("""
597
 
            $ brz init test
 
597
            $ bzr init test
598
598
            Created a standalone tree (format: 2a)
599
599
            $ cd test
600
600
            $ echo foo > file
601
 
            $ brz add
 
601
            $ bzr add
602
602
            adding file
603
 
            $ brz commit -m 'file added'
 
603
            $ bzr commit -m 'file added'
604
604
            2>Committing to:...test/
605
605
            2>added file
606
606
            2>Committed revision 1.
609
609
 
610
610
    def test_shelve(self):
611
611
        self.run_script("""
612
 
            $ brz shelve -m 'shelve bar'
 
612
            $ bzr shelve -m 'shelve bar'
613
613
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): yes
614
614
            <y
615
615
            2>Selected changes:
620
620
            """,
621
621
                        null_output_matches_anything=True)
622
622
        self.run_script("""
623
 
            $ brz shelve --list
 
623
            $ bzr shelve --list
624
624
              1: shelve bar
625
625
            """)
626
626
 
627
627
    def test_dont_shelve(self):
628
628
        # We intentionally provide no input here to test EOF
629
629
        self.run_script("""
630
 
            $ brz shelve -m 'shelve bar'
 
630
            $ bzr shelve -m 'shelve bar'
631
631
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): 
632
632
            2>No changes to shelve.
633
633
            """,
634
634
                        null_output_matches_anything=True)
635
635
        self.run_script("""
636
 
            $ brz st
 
636
            $ bzr st
637
637
            modified:
638
638
              file
639
639
            """)