~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2007-07-12 20:55:33 UTC
  • mfrom: (553.1.1 bzrtools)
  • Revision ID: abentley@panoramicfeedback.com-20070712205533-ael98t8ly97zuba3
Merge option help fixes from vila

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os.path
1
2
from bzrlib.diff import _patch_header_date
2
3
import bzrlib.tests
3
 
import os.path
4
4
 
5
 
try:
6
 
    from bzrlib.plugins.bzrtools.hunk_selector import (
7
 
        ShelveHunkSelector,
8
 
        UnshelveHunkSelector,
9
 
        )
10
 
    from bzrlib.plugins.bzrtools.errors import NoColor
11
 
except ImportError:
12
 
    from bzrtools.hunk_selector import (
13
 
        ShelveHunkSelector,
14
 
        UnshelveHunkSelector,
15
 
        )
16
 
    from bzrtools.errors import NoColor
 
5
from bzrlib.plugins.bzrtools.hunk_selector import (
 
6
    ShelveHunkSelector,
 
7
    UnshelveHunkSelector,
 
8
    )
 
9
from bzrlib.plugins.bzrtools.errors import NoColor
 
10
from bzrlib.plugins.bzrtools import cmd_shelf
17
11
 
18
12
 
19
13
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
40
34
"""
41
35
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
42
36
        old_tree = self.tree.basis_tree()
43
 
        old_date = _patch_header_date(old_tree, 
44
 
                                      old_tree.inventory.path2id(filename),
45
 
                                      filename)
46
 
        new_date = _patch_header_date(self.tree, 
47
 
                                      self.tree.inventory.path2id(filename),
48
 
                                      filename)
49
 
        keys = { 'filename' : filename , 'old_date': old_date, 
 
37
        old_tree.lock_read()
 
38
        self.tree.lock_read()
 
39
        try:
 
40
            old_date = _patch_header_date(old_tree,
 
41
                                          old_tree.inventory.path2id(filename),
 
42
                                          filename)
 
43
            new_date = _patch_header_date(self.tree,
 
44
                self.tree.inventory.path2id(filename), filename)
 
45
        finally:
 
46
            self.tree.unlock()
 
47
            old_tree.unlock()
 
48
        keys = { 'filename' : filename , 'old_date': old_date,
50
49
                 'new_date': new_date}
51
50
        hdr  = self.DIFF_HEADER % keys
52
51
        diff = diff % keys
53
 
        self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
 
52
        self.assertEqual(self.run_bzr('diff', retcode=1)[0], hdr + diff + '\n')
54
53
 
55
54
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
56
55
                     new_date=None):
57
56
        old_tree = self.tree.basis_tree()
58
 
        old_date = _patch_header_date(old_tree, 
59
 
                                      old_tree.inventory.path2id(filename),
60
 
                                      filename)
 
57
        old_tree.lock_read()
 
58
        try:
 
59
            old_date = _patch_header_date(old_tree,
 
60
                                          old_tree.inventory.path2id(filename),
 
61
                                          filename)
 
62
        finally:
 
63
            old_tree.unlock()
61
64
        diff = diff % { 'filename' : filename, 'old_date': old_date,
62
65
                        'new_date': new_date}
63
66
        shelf = open(os.path.join(self.tree.basedir,
74
77
    def __test_loop(self, count):
75
78
        self.tree = self.make_branch_and_tree('.')
76
79
        self.__create_and_add_test_file()
77
 
 
78
 
        while count > 0:
79
 
            count -= 1
80
 
 
 
80
        for counter in range(count):
81
81
            # Modify the test file
82
 
            # write in binary mode because on win32 line-endings should be LF
 
82
            # write in binary mode because on win32 line-endings should be
 
83
            # LF
83
84
            f = file('test_file', 'wb')
84
85
            f.write(self.MODIFIED)
85
86
            f.close()
86
87
 
87
88
            self._check_diff()
88
 
            
89
 
            new_date = _patch_header_date(self.tree, 
90
 
                self.tree.inventory.path2id('test_file'), 'test_file')
 
89
 
 
90
            self.tree.lock_write()
 
91
            try:
 
92
                new_date = _patch_header_date(self.tree,
 
93
                    self.tree.inventory.path2id('test_file'), 'test_file')
 
94
            finally:
 
95
                self.tree.unlock()
91
96
 
92
97
            # Shelve the changes
93
 
            self.run_bzr('shelve', '--all', retcode=0)
 
98
            self.run_bzr('shelve --all', retcode=0)
94
99
 
95
100
            # Make sure there is no diff anymore
96
 
            self.assertEqual(self.capture('diff', retcode=0), '')
 
101
            self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
97
102
 
98
103
            # Make sure the file is actually back the way it was
99
104
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
101
106
            self._check_shelf('00', new_date=new_date)
102
107
 
103
108
            # Unshelve
104
 
            self.run_bzr('unshelve', '--all', retcode=0)
 
109
            self.run_bzr('unshelve --all', retcode=0)
105
110
 
106
111
            self._check_diff()
107
112
 
117
122
        self.__create_and_add_test_file()
118
123
 
119
124
        # Shelve the changes
120
 
        self.run_bzr('shelve', '--all', retcode=3)
 
125
        self.run_bzr('shelve --all', retcode=3)
121
126
 
122
127
        if os.path.exists(os.path.join(self.tree.branch.base,
123
128
                '.shelf/shelves/default/00')):
141
146
        self.tree.commit(message='update test_file')
142
147
 
143
148
        # Shelve the changes
144
 
        self.run_bzr('shelve', '--all', '-r', '1', retcode=0)
 
149
        self.run_bzr('shelve --all -r 1', retcode=0)
145
150
 
146
151
        self._check_diff(self.DIFF_2)
147
152
 
149
154
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
150
155
 
151
156
        # Unshelve
152
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
157
        self.run_bzr('unshelve --all', retcode=0)
153
158
 
154
159
        # Make sure the file is back the way it should be
155
160
        self.assertEqual(file('test_file').read(), self.MODIFIED)
157
162
    def test_shelf_with_two_revisions(self):
158
163
        self.tree = self.make_branch_and_tree('.')
159
164
 
160
 
        cmd = 'shelve --all -r 1..2'
161
 
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
 
165
        stdout, stderr = self.run_bzr('shelve --all -r 1..2', retcode=None)
162
166
 
163
167
        self.assertEqual(stderr.split('\n')[0],
164
168
            'bzr: ERROR: shelve only accepts a single revision parameter.')
173
177
        self.build_tree_contents([('test_file', 'patch %s\n' % patch)])
174
178
 
175
179
        # Shelve the changes
176
 
        self.run_bzr('shelve', '--all', retcode=0)
 
180
        self.run_bzr('shelve --all', retcode=0)
177
181
 
178
182
        # Make sure there is no diff anymore
179
 
        self.assertEqual(self.capture('diff', retcode=0), '')
 
183
        self.assertEqual(self.run_bzr('diff', retcode=0)[0], '')
180
184
 
181
185
        # Check the shelf is right
182
186
        shelf = open(os.path.join(self.tree.basedir,
184
188
        self.assertTrue('patch %s' % patch in shelf)
185
189
 
186
190
        # Check the shown output is right
187
 
        shown = self.capture('shelf show %s' % patch, retcode=0)
 
191
        shown = self.run_bzr('shelf show %s' % patch, retcode=0)[0]
188
192
        self.assertEqual(shown, shelf)
189
193
 
190
194
    def test_shelf_show_multi(self):
200
204
        self.assertTrue('patch 00' in shelf)
201
205
 
202
206
        # Check the shown output is right
203
 
        shown = self.capture('shelf show 00', retcode=0)
 
207
        shown = self.run_bzr('shelf show 00', retcode=0)[0]
204
208
        self.assertEqual(shown, shelf)
205
209
 
206
210
    def test_shelf_show_unspecified(self):
216
220
        self.assertTrue('patch 02' in shelf)
217
221
 
218
222
        # Check the shown output is right
219
 
        shown = self.capture('shelf show', retcode=0)
 
223
        shown = self.run_bzr('shelf show', retcode=0)[0]
220
224
        self.assertEqual(shown, shelf)
221
225
 
222
226
    def test_shelf_show_with_no_patch(self):
223
227
        self.tree = self.make_branch_and_tree('.')
224
 
        stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
 
228
        stderr = self.run_bzr('shelf show 00', retcode=None)[1]
225
229
        self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
226
230
 
227
231
    def test_shelf_unshelve_failure(self):
233
237
        file('test_file', 'w').write(self.MODIFIED)
234
238
 
235
239
        # Shelve the changes
236
 
        self.run_bzr('shelve', '--all', retcode=0)
 
240
        self.run_bzr('shelve --all', retcode=0)
237
241
 
238
242
        # Write an unapplyable patch into the shelf
239
243
        shelf = open(os.path.join(self.tree.basedir,
242
246
        shelf.close()
243
247
 
244
248
        # Unshelve, should fail
245
 
        self.run_bzr('unshelve', '--all', retcode=3)
 
249
        self.run_bzr('unshelve --all', retcode=3)
246
250
 
247
251
        # Make sure the patch is still there, eventhough it's broken
248
252
        shelf = open(os.path.join(self.tree.basedir,
250
254
        self.assertEqual(shelf, self.DIFF_2)
251
255
 
252
256
        # Working tree should be unchanged
253
 
        diff = self.capture('diff', retcode=0)
 
257
        diff = self.run_bzr('diff', retcode=0)[0]
254
258
        self.assertEqual(diff, '')
255
259
 
256
260
    def test_shelf_unshelve_failure_two_hunks(self):
264
268
        file('test_file2', 'w').write(self.MODIFIED)
265
269
 
266
270
        # Shelve the changes
267
 
        self.run_bzr('shelve', '--all', retcode=0)
 
271
        self.run_bzr('shelve --all', retcode=0)
268
272
 
269
273
        # Put the changes to test_file back, the shelved patch won't apply now
270
274
        file('test_file', 'w').write(self.MODIFIED)
271
275
        self.tree.commit(message='screw up test_file')
272
276
 
273
277
        # Unshelve, should fail
274
 
        self.run_bzr('unshelve', '--all', retcode=3)
 
278
        self.run_bzr('unshelve --all', retcode=3)
275
279
 
276
280
        # Working tree should be unchanged
277
 
        diff = self.capture('diff', retcode=0)
 
281
        diff = self.run_bzr('diff', retcode=0)[0]
278
282
        self.assertEqual(diff, '')
279
283
 
280
284
        # Force should succeed and modify test_file2, but leave shelf
281
 
        self.run_bzr('unshelve', '--force', '--all', retcode=0)
 
285
        self.run_bzr('unshelve --force --all', retcode=0)
282
286
        self.assertEqual(open('test_file2').read(), self.MODIFIED)
283
287
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
284
288
 
293
297
        file('test_file2', 'w').write(self.MODIFIED)
294
298
 
295
299
        # Shelve the changes
296
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
297
 
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
 
300
        self.run_bzr('shelve --all test_file', retcode=0)
 
301
        self.run_bzr('shelve --all test_file2', retcode=0)
298
302
 
299
303
        # Unshelve
300
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
304
        self.run_bzr('unshelve --all', retcode=0)
301
305
 
302
306
        # We should now have 00 and 01~
303
307
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
304
308
        self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
305
309
 
306
310
        # Check ls works
307
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
 
311
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
308
312
        for line in lines:
309
313
            self.assertFalse(line.startswith(' 01'))
310
314
 
311
315
        # Unshelve, if unshelve is confused by the backup it will fail
312
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
316
        self.run_bzr('unshelve --all', retcode=0)
313
317
 
314
318
    def test_shelf_delete(self):
315
319
        self.tree = self.make_branch_and_tree('.')
316
 
 
317
 
        self.__create_and_add_test_file()
318
 
        self.__create_and_add_test_file(filename='test_file2')
319
 
 
320
 
        # Modify the test files
321
 
        # write in binary mode because on win32 line-endings should be LF
322
 
        f = file('test_file', 'wb')
323
 
        f.write(self.MODIFIED)
324
 
        f.close()
325
 
        f = file('test_file2', 'wb')
326
 
        f.write(self.MODIFIED)
327
 
        f.close()
328
 
        new_date = _patch_header_date(self.tree, 
329
 
            self.tree.inventory.path2id('test_file'), 'test_file')
 
320
        self.tree.lock_write()
 
321
        try:
 
322
            self.__create_and_add_test_file()
 
323
            self.__create_and_add_test_file(filename='test_file2')
 
324
 
 
325
            # Modify the test files
 
326
            # write in binary mode because on win32 line-endings should be LF
 
327
            f = file('test_file', 'wb')
 
328
            f.write(self.MODIFIED)
 
329
            f.close()
 
330
            f = file('test_file2', 'wb')
 
331
            f.write(self.MODIFIED)
 
332
            f.close()
 
333
            new_date = _patch_header_date(self.tree,
 
334
                self.tree.inventory.path2id('test_file'), 'test_file')
 
335
        finally:
 
336
            self.tree.unlock()
330
337
 
331
338
        # Shelve the changes
332
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
333
 
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
 
339
        self.run_bzr('shelve --all test_file', retcode=0)
 
340
        self.run_bzr('shelve --all test_file2', retcode=0)
334
341
 
335
342
        self._check_shelf('00', new_date=new_date)
336
343
 
337
344
        # Delete 00
338
 
        self.run_bzr('shelf', 'delete', '00', retcode=0)
 
345
        self.run_bzr('shelf delete 00', retcode=0)
339
346
 
340
347
        # We should now have 01 but not 00, but we should have 00~
341
348
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
346
353
        self._check_shelf('00~', new_date=new_date)
347
354
 
348
355
        # Check ls works
349
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
 
356
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
350
357
        for line in lines:
351
358
            self.assertFalse(line.startswith(' 00'))
352
359
 
353
360
        # Unshelve should unshelve 01
354
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
361
        self.run_bzr('unshelve --all', retcode=0)
355
362
        self.assertEqual(file('test_file2').read(), self.MODIFIED)
356
363
 
357
364
    def test_shelf_gaps(self):
358
365
        self.tree = self.make_branch_and_tree('.')
359
366
        self.__create_and_add_test_file()
360
367
        file('test_file', 'w').write(self.MODIFIED)
361
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
368
        self.run_bzr('shelve --all test_file', retcode=0)
362
369
        file('test_file', 'w').write(self.MODIFIED)
363
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
370
        self.run_bzr('shelve --all test_file', retcode=0)
364
371
 
365
372
        # Now delete 00, leaving 01, next shelve should go into 02
366
 
        self.run_bzr('shelf', 'delete', '0', retcode=0)
 
373
        self.run_bzr('shelf delete 0', retcode=0)
367
374
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
368
375
        self.assertFalse(os.path.exists('.shelf/shelves/default/02'))
369
376
        file('test_file', 'w').write(self.MODIFIED)
370
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
377
        self.run_bzr('shelve --all test_file', retcode=0)
371
378
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
372
379
        self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
373
380
 
378
385
 
379
386
        # Modify then shelve, so we're not upgrading to 00, just for kicks
380
387
        file('test_file', 'w').write(self.MODIFIED)
381
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
388
        self.run_bzr('shelve --all test_file', retcode=0)
382
389
 
383
390
        open('.bzr-shelf', 'w').write('First old shelf')
384
391
        open('.bzr-shelf-1', 'w').write('Second old shelf')
386
393
 
387
394
        # shelve and unshelve should bitch and do nothing
388
395
        file('test_file', 'w').write('blah blah blah')
389
 
        self.run_bzr('shelve', '--all', retcode=3)
 
396
        self.run_bzr('shelve --all', retcode=3)
390
397
        self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
391
398
        self.assertEqual(file('test_file').read(), 'blah blah blah')
392
 
        self.run_bzr('unshelve', '--all', retcode=3)
 
399
        self.run_bzr('unshelve --all', retcode=3)
393
400
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
394
401
 
395
402
        # Upgrade, make sure it worked
396
 
        self.run_bzr('shelf', 'upgrade', retcode=0)
 
403
        self.run_bzr('shelf upgrade', retcode=0)
397
404
        self.assertEqual(open('.shelf/shelves/default/01').read(),
398
405
                'First old shelf')
399
406
        self.assertEqual(open('.shelf/shelves/default/02').read(),
410
417
        self.assertFalse(os.path.exists('.bzr-shelf-3'))
411
418
 
412
419
        # Shelve should work now
413
 
        self.run_bzr('shelve', '--all', retcode=0)
 
420
        self.run_bzr('shelve --all', retcode=0)
414
421
 
415
422
    def test_shelf_p1_patch(self):
416
423
        self.tree = self.make_branch_and_tree('.')
418
425
        self.__create_and_add_test_file()
419
426
 
420
427
        # Run a benign shelf command to setup .shelf for us
421
 
        self.run_bzr('shelf', 'ls', retcode=0)
 
428
        self.run_bzr('shelf ls', retcode=0)
422
429
 
423
430
        old_tree = self.tree.basis_tree()
424
 
        old_date = _patch_header_date(old_tree, 
425
 
                                      old_tree.inventory.path2id('test_file'),
426
 
                                      'test_file')
427
 
        new_date = _patch_header_date(self.tree, 
428
 
                                      self.tree.inventory.path2id('test_file'),
429
 
                                      'test_file')
 
431
        old_tree.lock_read()
 
432
        self.tree.lock_read()
 
433
        try:
 
434
            old_date = _patch_header_date(old_tree,
 
435
                old_tree.inventory.path2id('test_file'),
 
436
                                          'test_file')
 
437
            new_date = _patch_header_date(self.tree,
 
438
                self.tree.inventory.path2id('test_file'), 'test_file')
 
439
        finally:
 
440
            old_tree.unlock()
 
441
            self.tree.unlock()
430
442
        # Fake a -p0 shelved patch
431
443
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
432
444
                               'new_date' : new_date}
435
447
        open('.shelf/shelves/default/00', 'w').write(diff)
436
448
 
437
449
        # This should work
438
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
450
        self.run_bzr('unshelve --all', retcode=0)
439
451
 
440
452
        self._check_diff()
441
453
 
456
468
        f.close()
457
469
 
458
470
        # Shelve the changes
459
 
        self.run_bzr('shelve', '--all', retcode=0)
 
471
        self.run_bzr('shelve --all', retcode=0)
460
472
 
461
473
        # Working tree should be unchanged
462
 
        diff = self.capture('diff', retcode=0)
 
474
        diff = self.run_bzr('diff', retcode=0)[0]
463
475
        self.assertEqual(diff, '')
464
476
 
465
477
        # Unshelve, should succeed
466
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
478
        self.run_bzr('unshelve --all', retcode=0)
467
479
 
468
480
        self._check_diff(filename='subdir/test_file')
469
481
 
470
482
        # Make sure relative filenames work ok
471
 
        self.run_bzr('shelve', 'test_file', '--all', retcode=0)
 
483
        self.run_bzr('shelve test_file --all', retcode=0)
472
484
 
473
485
    def test_shelf_shelf_bogus_subcommand(self):
474
486
        self.tree = self.make_branch_and_tree('.')
475
 
        self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
 
487
        self.run_bzr('shelf foo', retcode=3) # <- retcode == 3
476
488
 
477
489
    def test_shelf_OOO_unshelve(self):
478
490
        self.tree = self.make_branch_and_tree('.')
486
498
 
487
499
        # Shelve the changes
488
500
        for i in range(1, 5):
489
 
            self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
 
501
            self.run_bzr(['shelve', '--all', 'test_file%d' % i], retcode=0)
490
502
 
491
503
        # Check shelving worked
492
504
        for i in range(1, 5):
497
509
            self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
498
510
 
499
511
        # Unshelve 00
500
 
        self.run_bzr('unshelve', '--all', '00', retcode=0)
 
512
        self.run_bzr('unshelve --all 00', retcode=0)
501
513
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
502
514
 
503
515
        # Check ls works
504
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
 
516
        lines = self.run_bzr('shelf ls', retcode=0)[0].split('\n')
505
517
        for line in lines:
506
518
            self.assertFalse(line.startswith(' 00'))
507
519
 
508
520
        # Check we can reshelve once we've unshelved out of order, should be 04
509
521
        self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
510
 
        self.run_bzr('shelve', '--all')
 
522
        self.run_bzr('shelve --all')
511
523
        self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
512
524
 
513
525
        # Check ls works
514
 
        text = self.capture('shelf ls', retcode=0)
 
526
        text = self.run_bzr('shelf ls', retcode=0)[0]
515
527
        for line in text.split('\n'):
516
528
            self.assertFalse(line.startswith(' 00'))
517
529
 
518
530
        # We now have 01,02,03,04
519
531
        # Unshelve 02
520
 
        self.run_bzr('unshelve', '--all', '02', retcode=0)
 
532
        self.run_bzr('unshelve --all 02', retcode=0)
521
533
        self.assertEqual(file('test_file3').read(), self.MODIFIED)
522
534
 
523
535
        # Unshelve the default, this is the reshelved 00, hence modifies file 1
524
 
        self.run_bzr('unshelve', '--all', retcode=0)
 
536
        self.run_bzr('unshelve --all', retcode=0)
525
537
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
526
538
 
527
539
    def test_shelf_switch_basic(self):
530
542
 
531
543
        # This should go to "default"
532
544
        file('test_file', 'w').write(self.MODIFIED)
533
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
545
        self.run_bzr('shelve --all test_file', retcode=0)
534
546
 
535
547
        # Switch to "other"
536
 
        self.run_bzr('shelf', 'switch', 'other', retcode=0)
 
548
        self.run_bzr('shelf switch other', retcode=0)
537
549
        file('test_file', 'w').write(self.MODIFIED)
538
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
550
        self.run_bzr('shelve --all test_file', retcode=0)
539
551
 
540
552
        # Check it worked
541
553
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
543
555
        self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
544
556
 
545
557
        # Switch back
546
 
        self.run_bzr('shelf', 'switch', 'default', retcode=0)
 
558
        self.run_bzr('shelf switch default', retcode=0)
547
559
        file('test_file', 'w').write(self.MODIFIED)
548
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
 
560
        self.run_bzr('shelve --all test_file', retcode=0)
549
561
 
550
562
        # Check that worked
551
563
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
555
567
        self.tree = self.make_branch_and_tree('.')
556
568
 
557
569
        # Check the bad arg handling
558
 
        stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
 
570
        stdout, error = self.run_bzr('unshelve 01', retcode=3)
559
571
        self.assertTrue("Patch '01' doesn't exist on shelf" in error)
560
572
 
561
 
        stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
 
573
        stdout, error = self.run_bzr('unshelve foo', retcode=3)
562
574
        self.assertTrue("Invalid patch name 'foo'" in error)
563
575
 
564
576
        # Hex and is cracky, so it shouldn't work
565
 
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
 
577
        stdout, error = self.run_bzr(['unshelve', '0x00'], retcode=3)
566
578
        self.assertTrue("Invalid patch name '0x00'" in error)
567
579
 
568
580
    def test_color_hunk_selector(self):
600
612
        f = file('test_file', 'wb')
601
613
        f.write(self.MODIFIED)
602
614
        f.close()
603
 
        stdout, error = self.run_bzr_captured(['shelve', '--all', 
604
 
                                               '--no-color'])
605
 
        stdout, error = self.run_bzr_captured(['unshelve', '--all', 
606
 
                                               '--no-color'])
 
615
        stdout, error = self.run_bzr('shelve --all --no-color')
 
616
        stdout, error = self.run_bzr('unshelve --all --no-color')
 
617
 
 
618
    def test_shelf_help(self):
 
619
        self.assertContainsRe(cmd_shelf().help(),
 
620
                              'list\n.*List the patches on the current shelf')