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

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011, 2016 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 bzrlib import (
 
18
from breezy import (
 
19
    commands,
19
20
    osutils,
20
21
    tests,
 
22
    trace,
 
23
    ui,
21
24
    )
22
 
from bzrlib.tests import script
 
25
from breezy.tests import script
23
26
 
24
27
 
25
28
class TestSyntax(tests.TestCase):
26
29
 
27
30
    def test_comment_is_ignored(self):
28
 
        self.assertEquals([], script._script_to_commands('#comment\n'))
29
 
 
30
 
    def test_empty_line_is_ignored(self):
31
 
        self.assertEquals([], script._script_to_commands('\n'))
 
31
        self.assertEqual([], script._script_to_commands('#comment\n'))
 
32
 
 
33
    def test_comment_multiple_lines(self):
 
34
        self.assertEqual([
 
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.assertEqual([
 
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
 
        self.assertEquals([(['cd', 'trunk'], None, None, None)],
35
 
                           script._script_to_commands('$ cd trunk'))
 
62
        self.assertEqual([(['cd', 'trunk'], None, None, None)],
 
63
                         script._script_to_commands('$ cd trunk'))
36
64
 
37
65
    def test_command_with_single_quoted_param(self):
38
 
        story = """$ bzr commit -m 'two words'"""
39
 
        self.assertEquals([(['bzr', 'commit', '-m', "'two words'"],
40
 
                            None, None, None)],
41
 
                           script._script_to_commands(story))
 
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))
42
70
 
43
71
    def test_command_with_double_quoted_param(self):
44
 
        story = """$ bzr commit -m "two words" """
45
 
        self.assertEquals([(['bzr', 'commit', '-m', '"two words"'],
46
 
                            None, None, None)],
47
 
                           script._script_to_commands(story))
 
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))
48
76
 
49
77
    def test_command_with_input(self):
50
 
        self.assertEquals(
 
78
        self.assertEqual(
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
            $ brz add
 
87
            adding file
 
88
            adding file2
 
89
            """
 
90
        self.assertEqual([(['brz', '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
 
$ bzr add
 
96
$ brz add
57
97
adding file
58
98
adding file2
59
99
"""
60
 
        self.assertEquals([(['bzr', 'add'], None,
61
 
                            'adding file\nadding file2\n', None)],
62
 
                          script._script_to_commands(story))
 
100
        self.assertEqual([(['brz', 'add'], None,
 
101
                           'adding file\nadding file2\n', None)],
 
102
                         script._script_to_commands(story))
63
103
 
64
104
    def test_command_with_error(self):
65
105
        story = """
66
 
$ bzr branch foo
67
 
2>bzr: ERROR: Not a branch: "foo"
 
106
$ brz branch foo
 
107
2>brz: ERROR: Not a branch: "foo"
68
108
"""
69
 
        self.assertEquals([(['bzr', 'branch', 'foo'],
70
 
                            None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
71
 
                          script._script_to_commands(story))
 
109
        self.assertEqual([(['brz', 'branch', 'foo'],
 
110
                           None, None, 'brz: ERROR: Not a branch: "foo"\n')],
 
111
                         script._script_to_commands(story))
72
112
 
73
113
    def test_input_without_command(self):
74
114
        self.assertRaises(SyntaxError, script._script_to_commands, '<input')
78
118
 
79
119
    def test_command_with_backquotes(self):
80
120
        story = """
81
 
$ foo = `bzr file-id toto`
 
121
$ foo = `brz file-id toto`
82
122
"""
83
 
        self.assertEquals([(['foo', '=', '`bzr file-id toto`'],
84
 
                            None, None, None)],
85
 
                          script._script_to_commands(story))
 
123
        self.assertEqual([(['foo', '=', '`brz file-id toto`'],
 
124
                           None, None, None)],
 
125
                         script._script_to_commands(story))
86
126
 
87
127
 
88
128
class TestRedirections(tests.TestCase):
103
143
        self._check('foo', None, None, ['bar', 'baz'], ['bar', '<foo', 'baz'])
104
144
 
105
145
    def test_output_redirection(self):
106
 
        self._check(None, 'foo', 'wb+', [], ['>foo'])
107
 
        self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>foo'])
108
 
        self._check(None, 'foo', 'wb+', ['bar'], ['bar', '>', 'foo'])
109
 
        self._check(None, 'foo', 'ab+', [], ['>>foo'])
110
 
        self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>foo'])
111
 
        self._check(None, 'foo', 'ab+', ['bar'], ['bar', '>>', 'foo'])
 
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'])
112
152
 
113
153
    def test_redirection_syntax_errors(self):
114
154
        self._check('', None, None, [], ['<'])
115
 
        self._check(None, '', 'wb+', [], ['>'])
116
 
        self._check(None, '', 'ab+', [], ['>>'])
117
 
        self._check('>', '', 'ab+', [], ['<', '>', '>>'])
118
 
 
 
155
        self._check(None, '', 'w+', [], ['>'])
 
156
        self._check(None, '', 'a+', [], ['>>'])
 
157
        self._check('>', '', 'a+', [], ['<', '>', '>>'])
119
158
 
120
159
 
121
160
class TestExecution(script.TestCaseWithTransportAndScript):
122
161
 
123
162
    def test_unknown_command(self):
124
 
        self.assertRaises(SyntaxError, self.run_script, 'foo')
 
163
        """A clear error is reported for commands that aren't recognised
 
164
 
 
165
        Testing the attributes of the SyntaxError instance is equivalent to
 
166
        using traceback.format_exception_only and comparing with:
 
167
          File "<string>", line 1
 
168
            foo --frob
 
169
            ^
 
170
        SyntaxError: Command not found "foo"
 
171
        """
 
172
        e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
 
173
        self.assertContainsRe(e.msg, "not found.*foo")
 
174
        self.assertEqual(e.text, "foo --frob")
 
175
 
 
176
    def test_blank_output_mismatches_output(self):
 
177
        """If you give output, the output must actually be blank.
 
178
 
 
179
        See <https://bugs.launchpad.net/bzr/+bug/637830>: previously blank
 
180
        output was a wildcard.  Now you must say ... if you want that.
 
181
        """
 
182
        self.assertRaises(AssertionError,
 
183
                          self.run_script,
 
184
                          """
 
185
            $ echo foo
 
186
            """)
 
187
 
 
188
    def test_null_output_matches_option(self):
 
189
        """If you want null output to be a wild card, you can pass
 
190
        null_output_matches_anything to run_script"""
 
191
        self.run_script(
 
192
            """
 
193
            $ echo foo
 
194
            """, null_output_matches_anything=True)
 
195
 
 
196
    def test_ellipsis_everything(self):
 
197
        """A simple ellipsis matches everything."""
 
198
        self.run_script("""
 
199
        $ echo foo
 
200
        ...
 
201
        """)
 
202
 
 
203
    def test_ellipsis_matches_empty(self):
 
204
        self.run_script("""
 
205
        $ cd .
 
206
        ...
 
207
        """)
125
208
 
126
209
    def test_stops_on_unexpected_output(self):
127
210
        story = """
131
214
"""
132
215
        self.assertRaises(AssertionError, self.run_script, story)
133
216
 
134
 
 
135
217
    def test_stops_on_unexpected_error(self):
136
218
        story = """
137
219
$ cat
138
220
<Hello
139
 
$ bzr not-a-command
 
221
$ brz not-a-command
140
222
"""
141
223
        self.assertRaises(AssertionError, self.run_script, story)
142
224
 
143
225
    def test_continue_on_expected_error(self):
144
226
        story = """
145
 
$ bzr not-a-command
 
227
$ brz not-a-command
146
228
2>..."not-a-command"
147
229
"""
148
230
        self.run_script(story)
150
232
    def test_continue_on_error_output(self):
151
233
        # The status matters, not the output
152
234
        story = """
153
 
$ bzr init
 
235
$ brz init
 
236
...
154
237
$ cat >file
155
238
<Hello
156
 
$ bzr add file
157
 
$ bzr commit -m 'adding file'
 
239
$ brz add file
 
240
...
 
241
$ brz commit -m 'adding file'
 
242
2>...
158
243
"""
159
244
        self.run_script(story)
160
245
 
170
255
"""
171
256
        self.run_script(story)
172
257
        story = """
173
 
$ bzr not-a-command
 
258
$ brz not-a-command
174
259
2>..."not-a-command"
175
260
"""
176
261
        self.run_script(story)
177
262
 
178
263
        story = """
179
 
$ bzr branch not-a-branch
180
 
2>bzr: ERROR: Not a branch...not-a-branch/".
 
264
$ brz branch not-a-branch
 
265
2>brz: ERROR: Not a branch...not-a-branch/".
181
266
"""
182
267
        self.run_script(story)
183
268
 
206
291
cat dog "chicken" 'dragon'
207
292
""")
208
293
 
 
294
    def test_verbosity_isolated(self):
 
295
        """Global verbosity is isolated from commands run in scripts.
 
296
        """
 
297
        # see also 656694; we should get rid of global verbosity
 
298
        self.run_script("""
 
299
        $ brz init --quiet a
 
300
        """)
 
301
        self.assertEqual(trace.is_quiet(), False)
 
302
 
209
303
 
210
304
class TestCat(script.TestCaseWithTransportAndScript):
211
305
 
215
309
    def test_cat_input_to_output(self):
216
310
        retcode, out, err = self.run_command(['cat'],
217
311
                                             'content\n', 'content\n', None)
218
 
        self.assertEquals('content\n', out)
219
 
        self.assertEquals(None, err)
 
312
        self.assertEqual('content\n', out)
 
313
        self.assertEqual(None, err)
220
314
 
221
315
    def test_cat_file_to_output(self):
222
 
        self.build_tree_contents([('file', 'content\n')])
 
316
        self.build_tree_contents([('file', b'content\n')])
223
317
        retcode, out, err = self.run_command(['cat', 'file'],
224
318
                                             None, 'content\n', None)
225
 
        self.assertEquals('content\n', out)
226
 
        self.assertEquals(None, err)
 
319
        self.assertEqual('content\n', out)
 
320
        self.assertEqual(None, err)
227
321
 
228
322
    def test_cat_input_to_file(self):
229
323
        retcode, out, err = self.run_command(['cat', '>file'],
230
324
                                             'content\n', None, None)
231
325
        self.assertFileEqual('content\n', 'file')
232
 
        self.assertEquals(None, out)
233
 
        self.assertEquals(None, err)
 
326
        self.assertEqual(None, out)
 
327
        self.assertEqual(None, err)
234
328
        retcode, out, err = self.run_command(['cat', '>>file'],
235
329
                                             'more\n', None, None)
236
330
        self.assertFileEqual('content\nmore\n', 'file')
237
 
        self.assertEquals(None, out)
238
 
        self.assertEquals(None, err)
 
331
        self.assertEqual(None, out)
 
332
        self.assertEqual(None, err)
239
333
 
240
334
    def test_cat_file_to_file(self):
241
 
        self.build_tree_contents([('file', 'content\n')])
 
335
        self.build_tree_contents([('file', b'content\n')])
242
336
        retcode, out, err = self.run_command(['cat', 'file', '>file2'],
243
337
                                             None, None, None)
244
 
        self.assertFileEqual('content\n', 'file2')
 
338
        self.assertFileEqual(b'content\n', 'file2')
245
339
 
246
340
    def test_cat_files_to_file(self):
247
 
        self.build_tree_contents([('cat', 'cat\n')])
248
 
        self.build_tree_contents([('dog', 'dog\n')])
 
341
        self.build_tree_contents([('cat', b'cat\n')])
 
342
        self.build_tree_contents([('dog', b'dog\n')])
249
343
        retcode, out, err = self.run_command(['cat', 'cat', 'dog', '>file'],
250
344
                                             None, None, None)
251
 
        self.assertFileEqual('cat\ndog\n', 'file')
 
345
        self.assertFileEqual(b'cat\ndog\n', 'file')
252
346
 
253
347
    def test_cat_bogus_input_file(self):
254
348
        self.run_script("""
279
373
 
280
374
    def test_mkdir_jailed(self):
281
375
        self.assertRaises(ValueError, self.run_script, '$ mkdir /out-of-jail')
282
 
        self.assertRaises(ValueError, self.run_script, '$ mkdir ../out-of-jail')
 
376
        self.assertRaises(ValueError, self.run_script,
 
377
                          '$ mkdir ../out-of-jail')
283
378
 
284
379
    def test_mkdir_in_jail(self):
285
380
        self.run_script("""
288
383
$ mkdir ../dir2
289
384
$ cd ..
290
385
""")
291
 
        self.failUnlessExists('dir')
292
 
        self.failUnlessExists('dir2')
 
386
        self.assertPathExists('dir')
 
387
        self.assertPathExists('dir2')
293
388
 
294
389
 
295
390
class TestCd(script.TestCaseWithTransportAndScript):
302
397
        self.assertRaises(ValueError, self.run_script, '$ cd ..')
303
398
 
304
399
    def test_cd_dir_and_back_home(self):
305
 
        self.assertEquals(self.test_dir, osutils.getcwd())
 
400
        self.assertEqual(self.test_dir, osutils.getcwd())
306
401
        self.run_script("""
307
402
$ mkdir dir
308
403
$ cd dir
309
404
""")
310
 
        self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),
311
 
                          osutils.getcwd())
 
405
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
 
406
                         osutils.getcwd())
312
407
 
313
408
        self.run_script('$ cd')
314
 
        self.assertEquals(self.test_dir, osutils.getcwd())
315
 
 
316
 
 
317
 
class TestBzr(script.TestCaseWithTransportAndScript):
318
 
 
319
 
    def test_bzr_smoke(self):
320
 
        self.run_script('$ bzr init branch')
321
 
        self.failUnlessExists('branch')
 
409
        self.assertEqual(self.test_dir, osutils.getcwd())
 
410
 
 
411
 
 
412
class TestBrz(script.TestCaseWithTransportAndScript):
 
413
 
 
414
    def test_brz_smoke(self):
 
415
        self.run_script("""
 
416
            $ brz init branch
 
417
            Created a standalone tree (format: ...)
 
418
            """)
 
419
        self.assertPathExists('branch')
322
420
 
323
421
 
324
422
class TestEcho(script.TestCaseWithMemoryTransportAndScript):
337
435
 
338
436
    def test_echo_to_output(self):
339
437
        retcode, out, err = self.run_command(['echo'], None, '\n', None)
340
 
        self.assertEquals('\n', out)
341
 
        self.assertEquals(None, err)
 
438
        self.assertEqual('\n', out)
 
439
        self.assertEqual(None, err)
342
440
 
343
441
    def test_echo_some_to_output(self):
344
442
        retcode, out, err = self.run_command(['echo', 'hello'],
345
443
                                             None, 'hello\n', None)
346
 
        self.assertEquals('hello\n', out)
347
 
        self.assertEquals(None, err)
 
444
        self.assertEqual('hello\n', out)
 
445
        self.assertEqual(None, err)
348
446
 
349
447
    def test_echo_more_output(self):
350
448
        retcode, out, err = self.run_command(
351
449
            ['echo', 'hello', 'happy', 'world'],
352
450
            None, 'hello happy world\n', None)
353
 
        self.assertEquals('hello happy world\n', out)
354
 
        self.assertEquals(None, err)
 
451
        self.assertEqual('hello happy world\n', out)
 
452
        self.assertEqual(None, err)
355
453
 
356
454
    def test_echo_appended(self):
357
455
        retcode, out, err = self.run_command(['echo', 'hello', '>file'],
358
456
                                             None, None, None)
359
 
        self.assertEquals(None, out)
360
 
        self.assertEquals(None, err)
361
 
        self.assertFileEqual('hello\n', 'file')
 
457
        self.assertEqual(None, out)
 
458
        self.assertEqual(None, err)
 
459
        self.assertFileEqual(b'hello\n', 'file')
362
460
        retcode, out, err = self.run_command(['echo', 'happy', '>>file'],
363
461
                                             None, None, None)
364
 
        self.assertEquals(None, out)
365
 
        self.assertEquals(None, err)
366
 
        self.assertFileEqual('hello\nhappy\n', 'file')
 
462
        self.assertEqual(None, out)
 
463
        self.assertEqual(None, err)
 
464
        self.assertFileEqual(b'hello\nhappy\n', 'file')
 
465
 
 
466
    def test_empty_line_in_output_is_respected(self):
 
467
        self.run_script("""
 
468
            $ echo
 
469
 
 
470
            $ echo bar
 
471
            bar
 
472
            """)
367
473
 
368
474
 
369
475
class TestRm(script.TestCaseWithTransportAndScript):
374
480
 
375
481
    def test_rm_file(self):
376
482
        self.run_script('$ echo content >file')
377
 
        self.failUnlessExists('file')
 
483
        self.assertPathExists('file')
378
484
        self.run_script('$ rm file')
379
 
        self.failIfExists('file')
 
485
        self.assertPathDoesNotExist('file')
380
486
 
381
487
    def test_rm_file_force(self):
382
 
        self.failIfExists('file')
 
488
        self.assertPathDoesNotExist('file')
383
489
        self.run_script('$ rm -f file')
384
 
        self.failIfExists('file')
 
490
        self.assertPathDoesNotExist('file')
385
491
 
386
492
    def test_rm_files(self):
387
493
        self.run_script("""
388
494
$ echo content >file
389
495
$ echo content >file2
390
496
""")
391
 
        self.failUnlessExists('file2')
 
497
        self.assertPathExists('file2')
392
498
        self.run_script('$ rm file file2')
393
 
        self.failIfExists('file2')
 
499
        self.assertPathDoesNotExist('file2')
394
500
 
395
501
    def test_rm_dir(self):
396
502
        self.run_script('$ mkdir dir')
397
 
        self.failUnlessExists('dir')
 
503
        self.assertPathExists('dir')
398
504
        self.run_script("""
399
505
$ rm dir
400
506
2>rm: cannot remove 'dir': Is a directory
401
507
""")
402
 
        self.failUnlessExists('dir')
 
508
        self.assertPathExists('dir')
403
509
 
404
510
    def test_rm_dir_recursive(self):
405
511
        self.run_script("""
406
512
$ mkdir dir
407
513
$ rm -r dir
408
514
""")
409
 
        self.failIfExists('dir')
 
515
        self.assertPathDoesNotExist('dir')
410
516
 
411
517
 
412
518
class TestMv(script.TestCaseWithTransportAndScript):
418
524
 
419
525
    def test_move_file(self):
420
526
        self.run_script('$ echo content >file')
421
 
        self.failUnlessExists('file')
 
527
        self.assertPathExists('file')
422
528
        self.run_script('$ mv file new_name')
423
 
        self.failIfExists('file')
424
 
        self.failUnlessExists('new_name')
 
529
        self.assertPathDoesNotExist('file')
 
530
        self.assertPathExists('new_name')
425
531
 
426
532
    def test_move_unknown_file(self):
427
533
        self.assertRaises(AssertionError,
433
539
$ echo content >dir/file
434
540
""")
435
541
        self.run_script('$ mv dir new_name')
436
 
        self.failIfExists('dir')
437
 
        self.failUnlessExists('new_name')
438
 
        self.failUnlessExists('new_name/file')
 
542
        self.assertPathDoesNotExist('dir')
 
543
        self.assertPathExists('new_name')
 
544
        self.assertPathExists('new_name/file')
439
545
 
440
546
    def test_move_file_into_dir(self):
441
547
        self.run_script("""
443
549
$ echo content > file
444
550
""")
445
551
        self.run_script('$ mv file dir')
446
 
        self.failUnlessExists('dir')
447
 
        self.failIfExists('file')
448
 
        self.failUnlessExists('dir/file')
449
 
 
 
552
        self.assertPathExists('dir')
 
553
        self.assertPathDoesNotExist('file')
 
554
        self.assertPathExists('dir/file')
 
555
 
 
556
 
 
557
class cmd_test_confirm(commands.Command):
 
558
 
 
559
    def run(self):
 
560
        if ui.ui_factory.get_boolean(
 
561
                u'Really do it',
 
562
                # 'breezy.tests.test_script.confirm',
 
563
                # {}
 
564
                ):
 
565
            self.outf.write('Do it!\n')
 
566
        else:
 
567
            print('ok, no')
 
568
 
 
569
 
 
570
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
571
 
 
572
    def test_confirm_action(self):
 
573
        """You can write tests that demonstrate user confirmation.
 
574
 
 
575
        Specifically, ScriptRunner does't care if the output line for the
 
576
        prompt isn't terminated by a newline from the program; it's implicitly
 
577
        terminated by the input.
 
578
        """
 
579
        commands.builtin_command_registry.register(cmd_test_confirm)
 
580
        self.addCleanup(
 
581
            commands.builtin_command_registry.remove, 'test-confirm')
 
582
        self.run_script("""
 
583
            $ brz test-confirm
 
584
            2>Really do it? ([y]es, [n]o): yes
 
585
            <y
 
586
            Do it!
 
587
            $ brz test-confirm
 
588
            2>Really do it? ([y]es, [n]o): no
 
589
            <n
 
590
            ok, no
 
591
            """)
 
592
 
 
593
 
 
594
class TestShelve(script.TestCaseWithTransportAndScript):
 
595
 
 
596
    def setUp(self):
 
597
        super(TestShelve, self).setUp()
 
598
        self.run_script("""
 
599
            $ brz init test
 
600
            Created a standalone tree (format: 2a)
 
601
            $ cd test
 
602
            $ echo foo > file
 
603
            $ brz add
 
604
            adding file
 
605
            $ brz commit -m 'file added'
 
606
            2>Committing to:...test/
 
607
            2>added file
 
608
            2>Committed revision 1.
 
609
            $ echo bar > file
 
610
            """)
 
611
 
 
612
    def test_shelve(self):
 
613
        self.run_script("""
 
614
            $ brz shelve -m 'shelve bar'
 
615
            2>Shelve? ([y]es, [N]o, [f]inish, [q]uit): yes
 
616
            <y
 
617
            2>Selected changes:
 
618
            2> M  file
 
619
            2>Shelve 1 change(s)? ([y]es, [N]o, [f]inish, [q]uit): yes
 
620
            <y
 
621
            2>Changes shelved with id "1".
 
622
            """,
 
623
                        null_output_matches_anything=True)
 
624
        self.run_script("""
 
625
            $ brz shelve --list
 
626
              1: shelve bar
 
627
            """)
 
628
 
 
629
    def test_dont_shelve(self):
 
630
        # 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
 
638
            modified:
 
639
              file
 
640
            """)