~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-09-12 09:50:44 UTC
  • Revision ID: mbp@sourcefrog.net-20050912095044-6acfdb5611729987
- no tests in bzrlib.fetch anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Black-box tests for bzr.
20
20
 
21
21
These check that it behaves properly when it's invoked through the regular
22
 
command-line interface.  This doesn't actually run a new interpreter but 
23
 
rather starts again from the run_bzr function.
 
22
command-line interface.
 
23
 
 
24
This always reinvokes bzr through a new Python interpreter, which is a
 
25
bit inefficient but arguably tests in a way more representative of how
 
26
it's normally invoked.
24
27
"""
25
28
 
26
 
 
27
 
from cStringIO import StringIO
28
 
import os
29
 
import shutil
30
29
import sys
31
 
import os
32
30
 
33
31
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
34
32
from bzrlib.branch import Branch
35
 
from bzrlib.osutils import has_symlinks
 
33
from bzrlib.commands import run_bzr
36
34
 
37
35
 
38
36
class ExternalBase(TestCaseInTempDir):
39
 
 
40
 
    def runbzr(self, args, retcode=0, backtick=False):
 
37
    def runbzr(self, args, retcode=0,backtick=False):
41
38
        if isinstance(args, basestring):
42
39
            args = args.split()
43
40
 
44
41
        if backtick:
45
 
            return self.run_bzr_captured(args, retcode=retcode)[0]
 
42
            return self.backtick(['python', self.BZRPATH,] + args,
 
43
                           retcode=retcode)
46
44
        else:
47
 
            return self.run_bzr_captured(args, retcode=retcode)
 
45
            return self.runcmd(['python', self.BZRPATH,] + args,
 
46
                           retcode=retcode)
48
47
 
49
48
 
50
49
class TestCommands(ExternalBase):
73
72
        f = file('.bzr/email', 'wt')
74
73
        f.write('Branch Identity <branch@identi.ty>')
75
74
        f.close()
76
 
        bzr_email = os.environ.get('BZREMAIL')
77
 
        if bzr_email is not None:
78
 
            del os.environ['BZREMAIL']
79
75
        whoami = self.runbzr("whoami",backtick=True)
80
76
        whoami_email = self.runbzr("whoami --email",backtick=True)
81
77
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
82
78
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
83
 
        # Verify that the environment variable overrides the value 
84
 
        # in the file
85
 
        os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
86
 
        whoami = self.runbzr("whoami",backtick=True)
87
 
        whoami_email = self.runbzr("whoami --email",backtick=True)
88
 
        self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
89
 
        self.assertTrue(whoami_email.startswith('other@environ.ment'))
90
 
        if bzr_email is not None:
91
 
            os.environ['BZREMAIL'] = bzr_email
92
79
 
93
80
    def test_invalid_commands(self):
94
81
        self.runbzr("pants", retcode=1)
105
92
    def test_ignore_patterns(self):
106
93
        from bzrlib.branch import Branch
107
94
        
108
 
        b = Branch.initialize('.')
 
95
        b = Branch('.', init=True)
109
96
        self.assertEquals(list(b.unknowns()), [])
110
97
 
111
98
        file('foo.tmp', 'wt').write('tmp files are ignored')
112
99
        self.assertEquals(list(b.unknowns()), [])
113
 
        assert self.capture('unknowns') == ''
 
100
        assert self.backtick('bzr unknowns') == ''
114
101
 
115
102
        file('foo.c', 'wt').write('int main() {}')
116
103
        self.assertEquals(list(b.unknowns()), ['foo.c'])
117
 
        assert self.capture('unknowns') == 'foo.c\n'
 
104
        assert self.backtick('bzr unknowns') == 'foo.c\n'
118
105
 
119
106
        self.runbzr(['add', 'foo.c'])
120
 
        assert self.capture('unknowns') == ''
 
107
        assert self.backtick('bzr unknowns') == ''
121
108
 
122
109
        # 'ignore' works when creating the .bzignore file
123
110
        file('foo.blah', 'wt').write('blah')
124
111
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
125
112
        self.runbzr('ignore *.blah')
126
113
        self.assertEquals(list(b.unknowns()), [])
127
 
        assert file('.bzrignore', 'rU').read() == '*.blah\n'
 
114
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
128
115
 
129
116
        # 'ignore' works when then .bzrignore file already exists
130
117
        file('garh', 'wt').write('garh')
131
118
        self.assertEquals(list(b.unknowns()), ['garh'])
132
 
        assert self.capture('unknowns') == 'garh\n'
 
119
        assert self.backtick('bzr unknowns') == 'garh\n'
133
120
        self.runbzr('ignore garh')
134
121
        self.assertEquals(list(b.unknowns()), [])
135
 
        assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
 
122
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
136
123
 
137
124
    def test_revert(self):
 
125
        import os
138
126
        self.runbzr('init')
139
127
 
140
128
        file('hello', 'wt').write('foo')
144
132
        file('goodbye', 'wt').write('baz')
145
133
        self.runbzr('add goodbye')
146
134
        self.runbzr('commit -m setup goodbye')
147
 
 
 
135
        
148
136
        file('hello', 'wt').write('bar')
149
137
        file('goodbye', 'wt').write('qux')
150
138
        self.runbzr('revert hello')
159
147
        os.rmdir('revertdir')
160
148
        self.runbzr('revert')
161
149
 
162
 
        os.symlink('/unlikely/to/exist', 'symlink')
163
 
        self.runbzr('add symlink')
164
 
        self.runbzr('commit -m f')
165
 
        os.unlink('symlink')
166
 
        self.runbzr('revert')
167
 
        
168
 
        file('hello', 'wt').write('xyz')
169
 
        self.runbzr('commit -m xyz hello')
170
 
        self.runbzr('revert -r 1 hello')
171
 
        self.check_file_contents('hello', 'foo')
172
 
        self.runbzr('revert hello')
173
 
        self.check_file_contents('hello', 'xyz')
174
 
        os.chdir('revertdir')
175
 
        self.runbzr('revert')
176
 
        os.chdir('..')
177
 
 
178
 
 
179
 
    def test_mv_modes(self):
 
150
    def skipped_test_mv_modes(self):
180
151
        """Test two modes of operation for mv"""
181
152
        from bzrlib.branch import Branch
182
 
        b = Branch.initialize('.')
 
153
        b = Branch('.', init=True)
183
154
        self.build_tree(['a', 'c', 'subdir/'])
184
 
        self.run_bzr_captured(['add', self.test_dir])
185
 
        self.run_bzr_captured(['mv', 'a', 'b'])
186
 
        self.run_bzr_captured(['mv', 'b', 'subdir'])
187
 
        self.run_bzr_captured(['mv', 'subdir/b', 'a'])
188
 
        self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
189
 
        self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
 
155
        self.run_bzr('mv', 'a', 'b')
 
156
        self.run_bzr('mv', 'b', 'subdir')
 
157
        self.run_bzr('mv', 'subdir/b', 'a')
 
158
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
159
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
190
160
 
191
161
    def test_main_version(self):
192
162
        """Check output from version command and master option is reasonable"""
212
182
        test.runbzr('add goodbye')
213
183
        test.runbzr('commit -m setup goodbye')
214
184
 
215
 
    def test_export(self):
216
 
        os.mkdir('branch')
217
 
        os.chdir('branch')
218
 
        self.example_branch()
219
 
        self.runbzr('export ../latest')
220
 
        self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
221
 
        self.runbzr('export ../first -r 1')
222
 
        assert not os.path.exists('../first/goodbye')
223
 
        self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
224
 
        self.runbzr('export ../first.gz -r 1')
225
 
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
226
 
        self.runbzr('export ../first.bz2 -r 1')
227
 
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
228
 
        self.runbzr('export ../first.tar -r 1')
229
 
        assert os.path.isfile('../first.tar')
230
 
        from tarfile import TarFile
231
 
        tf = TarFile('../first.tar')
232
 
        assert 'first/hello' in tf.getnames(), tf.getnames()
233
 
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
234
 
        self.runbzr('export ../first.tar.gz -r 1')
235
 
        assert os.path.isfile('../first.tar.gz')
236
 
        self.runbzr('export ../first.tbz2 -r 1')
237
 
        assert os.path.isfile('../first.tbz2')
238
 
        self.runbzr('export ../first.tar.bz2 -r 1')
239
 
        assert os.path.isfile('../first.tar.bz2')
240
 
        self.runbzr('export ../first.tar.tbz2 -r 1')
241
 
        assert os.path.isfile('../first.tar.tbz2')
242
 
        from bz2 import BZ2File
243
 
        tf = TarFile('../first.tar.tbz2', 
244
 
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
245
 
        assert 'first.tar/hello' in tf.getnames(), tf.getnames()
246
 
        self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
247
 
        self.runbzr('export ../first2.tar -r 1 --root pizza')
248
 
        tf = TarFile('../first2.tar')
249
 
        assert 'pizza/hello' in tf.getnames(), tf.getnames()
250
 
 
251
 
    def test_diff(self):
252
 
        self.example_branch()
253
 
        file('hello', 'wt').write('hello world!')
254
 
        self.runbzr('commit -m fixing hello')
255
 
        output = self.runbzr('diff -r 2..3', backtick=1)
256
 
        self.assert_('\n+hello world!' in output)
257
 
        output = self.runbzr('diff -r last:3..last:1', backtick=1)
258
 
        self.assert_('\n+baz' in output)
259
 
 
260
 
    def test_branch(self):
261
 
        """Branch from one branch to another."""
262
 
        os.mkdir('a')
263
 
        os.chdir('a')
264
 
        self.example_branch()
265
 
        os.chdir('..')
266
 
        self.runbzr('branch a b')
267
 
        self.runbzr('branch a c -r 1')
268
 
        os.chdir('b')
269
 
        self.runbzr('commit -m foo --unchanged')
270
 
        os.chdir('..')
271
 
        # naughty - abstraction violations RBC 20050928  
272
 
        print "test_branch used to delete the stores, how is this meant to work ?"
273
 
        #shutil.rmtree('a/.bzr/revision-store')
274
 
        #shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
275
 
        #shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
276
 
        self.runbzr('branch a d --basis b')
 
185
    def test_revert(self):
 
186
        self.example_branch()
 
187
        file('hello', 'wt').write('bar')
 
188
        file('goodbye', 'wt').write('qux')
 
189
        self.runbzr('revert hello')
 
190
        self.check_file_contents('hello', 'foo')
 
191
        self.check_file_contents('goodbye', 'qux')
 
192
        self.runbzr('revert')
 
193
        self.check_file_contents('goodbye', 'baz')
277
194
 
278
195
    def test_merge(self):
279
196
        from bzrlib.branch import Branch
 
197
        import os
280
198
        
281
199
        os.mkdir('a')
282
200
        os.chdir('a')
 
201
 
283
202
        self.example_branch()
284
203
        os.chdir('..')
285
204
        self.runbzr('branch a b')
295
214
        self.runbzr('merge ../b')
296
215
        self.check_file_contents('goodbye', 'quux')
297
216
        # Merging a branch pulls its revision into the tree
298
 
        a = Branch.open('.')
299
 
        b = Branch.open('../b')
300
 
        a.get_revision_xml(b.last_revision())
 
217
        a = Branch('.')
 
218
        b = Branch('../b')
 
219
        a.get_revision_xml(b.last_patch())
 
220
 
301
221
        self.log('pending merges: %s', a.pending_merges())
302
 
        #        assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
 
222
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
303
223
        #        % (a.pending_merges(), b.last_patch())
304
224
 
305
 
    def test_merge_with_missing_file(self):
306
 
        """Merge handles missing file conflicts"""
307
 
        os.mkdir('a')
308
 
        os.chdir('a')
309
 
        os.mkdir('sub')
310
 
        print >> file('sub/a.txt', 'wb'), "hello"
311
 
        print >> file('b.txt', 'wb'), "hello"
312
 
        print >> file('sub/c.txt', 'wb'), "hello"
313
 
        self.runbzr('init')
314
 
        self.runbzr('add')
315
 
        self.runbzr(('commit', '-m', 'added a'))
316
 
        self.runbzr('branch . ../b')
317
 
        print >> file('sub/a.txt', 'ab'), "there"
318
 
        print >> file('b.txt', 'ab'), "there"
319
 
        print >> file('sub/c.txt', 'ab'), "there"
320
 
        self.runbzr(('commit', '-m', 'Added there'))
321
 
        os.unlink('sub/a.txt')
322
 
        os.unlink('sub/c.txt')
323
 
        os.rmdir('sub')
324
 
        os.unlink('b.txt')
325
 
        self.runbzr(('commit', '-m', 'Removed a.txt'))
326
 
        os.chdir('../b')
327
 
        print >> file('sub/a.txt', 'ab'), "something"
328
 
        print >> file('b.txt', 'ab'), "something"
329
 
        print >> file('sub/c.txt', 'ab'), "something"
330
 
        self.runbzr(('commit', '-m', 'Modified a.txt'))
331
 
        self.runbzr('merge ../a/')
332
 
        assert os.path.exists('sub/a.txt.THIS')
333
 
        assert os.path.exists('sub/a.txt.BASE')
334
 
        os.chdir('../a')
335
 
        self.runbzr('merge ../b/')
336
 
        assert os.path.exists('sub/a.txt.OTHER')
337
 
        assert os.path.exists('sub/a.txt.BASE')
338
 
 
339
 
    def test_merge_with_missing_file(self):
340
 
        """Merge handles missing file conflicts"""
341
 
        os.mkdir('a')
342
 
        os.chdir('a')
343
 
        os.mkdir('sub')
344
 
        print >> file('sub/a.txt', 'wb'), "hello"
345
 
        print >> file('b.txt', 'wb'), "hello"
346
 
        print >> file('sub/c.txt', 'wb'), "hello"
347
 
        self.runbzr('init')
348
 
        self.runbzr('add')
349
 
        self.runbzr(('commit', '-m', 'added a'))
350
 
        self.runbzr('branch . ../b')
351
 
        print >> file('sub/a.txt', 'ab'), "there"
352
 
        print >> file('b.txt', 'ab'), "there"
353
 
        print >> file('sub/c.txt', 'ab'), "there"
354
 
        self.runbzr(('commit', '-m', 'Added there'))
355
 
        os.unlink('sub/a.txt')
356
 
        os.unlink('sub/c.txt')
357
 
        os.rmdir('sub')
358
 
        os.unlink('b.txt')
359
 
        self.runbzr(('commit', '-m', 'Removed a.txt'))
360
 
        os.chdir('../b')
361
 
        print >> file('sub/a.txt', 'ab'), "something"
362
 
        print >> file('b.txt', 'ab'), "something"
363
 
        print >> file('sub/c.txt', 'ab'), "something"
364
 
        self.runbzr(('commit', '-m', 'Modified a.txt'))
365
 
        self.runbzr('merge ../a/')
366
 
        assert os.path.exists('sub/a.txt.THIS')
367
 
        assert os.path.exists('sub/a.txt.BASE')
368
 
        os.chdir('../a')
369
 
        self.runbzr('merge ../b/')
370
 
        assert os.path.exists('sub/a.txt.OTHER')
371
 
        assert os.path.exists('sub/a.txt.BASE')
372
 
 
373
 
    def test_pull(self):
374
 
        """Pull changes from one branch to another."""
375
 
        os.mkdir('a')
376
 
        os.chdir('a')
377
 
 
378
 
        self.example_branch()
379
 
        self.runbzr('pull', retcode=1)
380
 
        self.runbzr('missing', retcode=1)
381
 
        self.runbzr('missing .')
382
 
        self.runbzr('missing')
383
 
        self.runbzr('pull')
384
 
        self.runbzr('pull /', retcode=1)
385
 
        self.runbzr('pull')
386
 
 
387
 
        os.chdir('..')
388
 
        self.runbzr('branch a b')
389
 
        os.chdir('b')
390
 
        self.runbzr('pull')
391
 
        os.mkdir('subdir')
392
 
        self.runbzr('add subdir')
393
 
        self.runbzr('commit -m blah --unchanged')
394
 
        os.chdir('../a')
395
 
        a = Branch.open('.')
396
 
        b = Branch.open('../b')
397
 
        assert a.revision_history() == b.revision_history()[:-1]
398
 
        self.runbzr('pull ../b')
399
 
        assert a.revision_history() == b.revision_history()
400
 
        self.runbzr('commit -m blah2 --unchanged')
401
 
        os.chdir('../b')
402
 
        self.runbzr('commit -m blah3 --unchanged')
403
 
        self.runbzr('pull ../a', retcode=1)
404
 
        print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
405
 
        return
406
 
        os.chdir('../a')
407
 
        self.runbzr('merge ../b')
408
 
        self.runbzr('commit -m blah4 --unchanged')
409
 
        os.chdir('../b/subdir')
410
 
        self.runbzr('pull ../../a')
411
 
        assert a.revision_history()[-1] == b.revision_history()[-1]
412
 
        self.runbzr('commit -m blah5 --unchanged')
413
 
        self.runbzr('commit -m blah6 --unchanged')
414
 
        os.chdir('..')
415
 
        self.runbzr('pull ../a')
416
 
        os.chdir('../a')
417
 
        self.runbzr('commit -m blah7 --unchanged')
418
 
        self.runbzr('merge ../b')
419
 
        self.runbzr('commit -m blah8 --unchanged')
420
 
        self.runbzr('pull ../b')
421
 
        self.runbzr('pull ../b')
422
 
 
423
 
    def test_locations(self):
424
 
        """Using and remembering different locations"""
425
 
        os.mkdir('a')
426
 
        os.chdir('a')
427
 
        self.runbzr('init')
428
 
        self.runbzr('commit -m unchanged --unchanged')
429
 
        self.runbzr('pull', retcode=1)
430
 
        self.runbzr('merge', retcode=1)
431
 
        self.runbzr('branch . ../b')
432
 
        os.chdir('../b')
433
 
        self.runbzr('pull')
434
 
        self.runbzr('branch . ../c')
435
 
        self.runbzr('pull ../c')
436
 
        self.runbzr('merge')
437
 
        os.chdir('../a')
438
 
        self.runbzr('pull ../b')
439
 
        self.runbzr('pull')
440
 
        self.runbzr('pull ../c')
441
 
        self.runbzr('branch ../c ../d')
442
 
        shutil.rmtree('../c')
443
 
        self.runbzr('pull')
444
 
        os.chdir('../b')
445
 
        self.runbzr('pull')
446
 
        os.chdir('../d')
447
 
        self.runbzr('pull', retcode=1)
448
 
        self.runbzr('pull ../a --remember')
449
 
        self.runbzr('pull')
450
 
        
 
225
 
451
226
    def test_add_reports(self):
452
227
        """add command prints the names of added files."""
453
 
        b = Branch.initialize('.')
 
228
        b = Branch('.', init=True)
454
229
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
455
 
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
 
230
 
 
231
        from cStringIO import StringIO
 
232
        out = StringIO()
 
233
 
 
234
        ret = self.apply_redirected(None, out, None,
 
235
                                    run_bzr,
 
236
                                    ['add'])
 
237
        self.assertEquals(ret, 0)
 
238
 
456
239
        # the ordering is not defined at the moment
457
 
        results = sorted(out.rstrip('\n').split('\n'))
 
240
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
458
241
        self.assertEquals(['added dir',
459
 
                           'added dir'+os.sep+'sub.txt',
 
242
                           'added dir/sub.txt',
460
243
                           'added top.txt',],
461
244
                          results)
462
245
 
463
 
    def test_unknown_command(self):
464
 
        """Handling of unknown command."""
465
 
        out, err = self.run_bzr_captured(['fluffy-badger'],
466
 
                                         retcode=1)
467
 
        self.assertEquals(out, '')
468
 
        err.index('unknown command')
469
 
 
470
 
    def test_conflicts(self):
471
 
        """Handling of merge conflicts"""
472
 
        os.mkdir('base')
473
 
        os.chdir('base')
474
 
        file('hello', 'wb').write("hi world")
475
 
        file('answer', 'wb').write("42")
476
 
        self.runbzr('init')
477
 
        self.runbzr('add')
478
 
        self.runbzr('commit -m base')
479
 
        self.runbzr('branch . ../other')
480
 
        self.runbzr('branch . ../this')
481
 
        os.chdir('../other')
482
 
        file('hello', 'wb').write("Hello.")
483
 
        file('answer', 'wb').write("Is anyone there?")
484
 
        self.runbzr('commit -m other')
485
 
        os.chdir('../this')
486
 
        file('hello', 'wb').write("Hello, world")
487
 
        self.runbzr('mv answer question')
488
 
        file('question', 'wb').write("What do you get when you multiply six"
489
 
                                   "times nine?")
490
 
        self.runbzr('commit -m this')
491
 
        self.runbzr('merge ../other')
492
 
        result = self.runbzr('conflicts', backtick=1)
493
 
        self.assertEquals(result, "hello\nquestion\n")
494
 
        result = self.runbzr('status', backtick=1)
495
 
        assert "conflicts:\n  hello\n  question\n" in result, result
496
 
        self.runbzr('resolve hello')
497
 
        result = self.runbzr('conflicts', backtick=1)
498
 
        self.assertEquals(result, "question\n")
499
 
        self.runbzr('commit -m conflicts', retcode=1)
500
 
        self.runbzr('resolve --all')
501
 
        result = self.runbzr('conflicts', backtick=1)
502
 
        self.runbzr('commit -m conflicts')
503
 
        self.assertEquals(result, "")
504
 
 
505
 
def listdir_sorted(dir):
506
 
    L = os.listdir(dir)
507
 
    L.sort()
508
 
    return L
509
 
 
510
246
 
511
247
class OldTests(ExternalBase):
512
248
    """old tests moved from ./testbzr."""
514
250
    def test_bzr(self):
515
251
        from os import chdir, mkdir
516
252
        from os.path import exists
 
253
        import os
517
254
 
518
255
        runbzr = self.runbzr
519
 
        capture = self.capture
 
256
        backtick = self.backtick
520
257
        progress = self.log
521
258
 
522
259
        progress("basic branch creation")
524
261
        chdir('branch1')
525
262
        runbzr('init')
526
263
 
527
 
        self.assertEquals(capture('root').rstrip(),
 
264
        self.assertEquals(backtick('bzr root').rstrip(),
528
265
                          os.path.join(self.test_dir, 'branch1'))
529
266
 
530
267
        progress("status of new file")
533
270
        f.write('hello world!\n')
534
271
        f.close()
535
272
 
536
 
        self.assertEquals(capture('unknowns'), 'test.txt\n')
 
273
        out = backtick("bzr unknowns")
 
274
        self.assertEquals(out, 'test.txt\n')
537
275
 
538
 
        out = capture("status")
 
276
        out = backtick("bzr status")
539
277
        assert out == 'unknown:\n  test.txt\n'
540
278
 
541
 
        out = capture("status --all")
 
279
        out = backtick("bzr status --all")
542
280
        assert out == "unknown:\n  test.txt\n"
543
281
 
544
 
        out = capture("status test.txt --all")
 
282
        out = backtick("bzr status test.txt --all")
545
283
        assert out == "unknown:\n  test.txt\n"
546
284
 
547
285
        f = file('test2.txt', 'wt')
548
286
        f.write('goodbye cruel world...\n')
549
287
        f.close()
550
288
 
551
 
        out = capture("status test.txt")
 
289
        out = backtick("bzr status test.txt")
552
290
        assert out == "unknown:\n  test.txt\n"
553
291
 
554
 
        out = capture("status")
 
292
        out = backtick("bzr status")
555
293
        assert out == ("unknown:\n"
556
294
                       "  test.txt\n"
557
295
                       "  test2.txt\n")
559
297
        os.unlink('test2.txt')
560
298
 
561
299
        progress("command aliases")
562
 
        out = capture("st --all")
 
300
        out = backtick("bzr st --all")
563
301
        assert out == ("unknown:\n"
564
302
                       "  test.txt\n")
565
303
 
566
 
        out = capture("stat")
 
304
        out = backtick("bzr stat")
567
305
        assert out == ("unknown:\n"
568
306
                       "  test.txt\n")
569
307
 
573
311
        runbzr("help commands")
574
312
        runbzr("help slartibartfast", 1)
575
313
 
576
 
        out = capture("help ci")
 
314
        out = backtick("bzr help ci")
577
315
        out.index('aliases: ')
578
316
 
579
317
        progress("can't rename unversioned file")
582
320
        progress("adding a file")
583
321
 
584
322
        runbzr("add test.txt")
585
 
        assert capture("unknowns") == ''
586
 
        assert capture("status --all") == ("added:\n"
 
323
        assert backtick("bzr unknowns") == ''
 
324
        assert backtick("bzr status --all") == ("added:\n"
587
325
                                                "  test.txt\n")
588
326
 
589
327
        progress("rename newly-added file")
591
329
        assert os.path.exists("hello.txt")
592
330
        assert not os.path.exists("test.txt")
593
331
 
594
 
        assert capture("revno") == '0\n'
 
332
        assert backtick("bzr revno") == '0\n'
595
333
 
596
334
        progress("add first revision")
597
335
        runbzr(['commit', '-m', 'add first revision'])
605
343
        runbzr("add sub1")
606
344
        runbzr("rename sub1 sub2")
607
345
        runbzr("move hello.txt sub2")
608
 
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
346
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
609
347
 
610
348
        assert exists("sub2")
611
349
        assert exists("sub2/hello.txt")
626
364
        runbzr(['commit', '-m', 'rename nested subdirectories'])
627
365
 
628
366
        chdir('sub1/sub2')
629
 
        self.assertEquals(capture('root')[:-1],
 
367
        self.assertEquals(backtick('bzr root')[:-1],
630
368
                          os.path.join(self.test_dir, 'branch1'))
631
369
        runbzr('move ../hello.txt .')
632
370
        assert exists('./hello.txt')
633
 
        self.assertEquals(capture('relpath hello.txt'),
634
 
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
635
 
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
371
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
372
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
636
373
        runbzr(['commit', '-m', 'move to parent directory'])
637
374
        chdir('..')
638
 
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
375
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
639
376
 
640
377
        runbzr('move sub2/hello.txt .')
641
378
        assert exists('hello.txt')
650
387
 
651
388
        runbzr('commit -F msg.tmp')
652
389
 
653
 
        assert capture('revno') == '5\n'
 
390
        assert backtick('bzr revno') == '5\n'
654
391
        runbzr('export -r 5 export-5.tmp')
655
392
        runbzr('export export.tmp')
656
393
 
658
395
        runbzr('log -v')
659
396
        runbzr('log -v --forward')
660
397
        runbzr('log -m', retcode=1)
661
 
        log_out = capture('log -m commit')
 
398
        log_out = backtick('bzr log -m commit')
662
399
        assert "this is my new commit" in log_out
663
400
        assert "rename nested" not in log_out
664
401
        assert 'revision-id' not in log_out
665
 
        assert 'revision-id' in capture('log --show-ids -m commit')
 
402
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
666
403
 
667
404
 
668
405
        progress("file with spaces in name")
678
415
 
679
416
        runbzr('info')
680
417
 
681
 
        if has_symlinks():
682
 
            progress("symlinks")
683
 
            mkdir('symlinks')
684
 
            chdir('symlinks')
685
 
            runbzr('init')
686
 
            os.symlink("NOWHERE1", "link1")
687
 
            runbzr('add link1')
688
 
            assert self.capture('unknowns') == ''
689
 
            runbzr(['commit', '-m', '1: added symlink link1'])
690
 
    
691
 
            mkdir('d1')
692
 
            runbzr('add d1')
693
 
            assert self.capture('unknowns') == ''
694
 
            os.symlink("NOWHERE2", "d1/link2")
695
 
            assert self.capture('unknowns') == 'd1/link2\n'
696
 
            # is d1/link2 found when adding d1
697
 
            runbzr('add d1')
698
 
            assert self.capture('unknowns') == ''
699
 
            os.symlink("NOWHERE3", "d1/link3")
700
 
            assert self.capture('unknowns') == 'd1/link3\n'
701
 
            runbzr(['commit', '-m', '2: added dir, symlink'])
702
 
    
703
 
            runbzr('rename d1 d2')
704
 
            runbzr('move d2/link2 .')
705
 
            runbzr('move link1 d2')
706
 
            assert os.readlink("./link2") == "NOWHERE2"
707
 
            assert os.readlink("d2/link1") == "NOWHERE1"
708
 
            runbzr('add d2/link3')
709
 
            runbzr('diff')
710
 
            runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
711
 
    
712
 
            os.unlink("link2")
713
 
            os.symlink("TARGET 2", "link2")
714
 
            os.unlink("d2/link1")
715
 
            os.symlink("TARGET 1", "d2/link1")
716
 
            runbzr('diff')
717
 
            assert self.capture("relpath d2/link1") == "d2/link1\n"
718
 
            runbzr(['commit', '-m', '4: retarget of two links'])
719
 
    
720
 
            runbzr('remove d2/link1')
721
 
            assert self.capture('unknowns') == 'd2/link1\n'
722
 
            runbzr(['commit', '-m', '5: remove d2/link1'])
723
 
    
724
 
            os.mkdir("d1")
725
 
            runbzr('add d1')
726
 
            runbzr('rename d2/link3 d1/link3new')
727
 
            assert self.capture('unknowns') == 'd2/link1\n'
728
 
            runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
729
 
            
730
 
            runbzr(['check'])
731
 
            
732
 
            runbzr(['export', '-r', '1', 'exp1.tmp'])
733
 
            chdir("exp1.tmp")
734
 
            assert listdir_sorted(".") == [ "link1" ]
735
 
            assert os.readlink("link1") == "NOWHERE1"
736
 
            chdir("..")
737
 
            
738
 
            runbzr(['export', '-r', '2', 'exp2.tmp'])
739
 
            chdir("exp2.tmp")
740
 
            assert listdir_sorted(".") == [ "d1", "link1" ]
741
 
            chdir("..")
742
 
            
743
 
            runbzr(['export', '-r', '3', 'exp3.tmp'])
744
 
            chdir("exp3.tmp")
745
 
            assert listdir_sorted(".") == [ "d2", "link2" ]
746
 
            assert listdir_sorted("d2") == [ "link1", "link3" ]
747
 
            assert os.readlink("d2/link1") == "NOWHERE1"
748
 
            assert os.readlink("link2")    == "NOWHERE2"
749
 
            chdir("..")
750
 
            
751
 
            runbzr(['export', '-r', '4', 'exp4.tmp'])
752
 
            chdir("exp4.tmp")
753
 
            assert listdir_sorted(".") == [ "d2", "link2" ]
754
 
            assert os.readlink("d2/link1") == "TARGET 1"
755
 
            assert os.readlink("link2")    == "TARGET 2"
756
 
            assert listdir_sorted("d2") == [ "link1", "link3" ]
757
 
            chdir("..")
758
 
            
759
 
            runbzr(['export', '-r', '5', 'exp5.tmp'])
760
 
            chdir("exp5.tmp")
761
 
            assert listdir_sorted(".") == [ "d2", "link2" ]
762
 
            assert os.path.islink("link2")
763
 
            assert listdir_sorted("d2")== [ "link3" ]
764
 
            chdir("..")
765
 
            
766
 
            runbzr(['export', '-r', '6', 'exp6.tmp'])
767
 
            chdir("exp6.tmp")
768
 
            assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
769
 
            assert listdir_sorted("d1") == [ "link3new" ]
770
 
            assert listdir_sorted("d2") == []
771
 
            assert os.readlink("d1/link3new") == "NOWHERE3"
772
 
            chdir("..")
773
 
        else:
774
 
            progress("skipping symlink tests")
775