~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

merge merge tweaks from aaron, which includes latest .dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
class ExternalBase(TestCaseInTempDir):
39
 
    def runbzr(self, args, retcode=0,backtick=False):
 
39
    def runbzr(self, args, retcode=0, backtick=False):
40
40
        if isinstance(args, basestring):
41
41
            args = args.split()
42
42
 
43
43
        if backtick:
44
 
            return self.backtick(['python', self.BZRPATH,] + args,
45
 
                           retcode=retcode)
 
44
            return self.run_bzr_captured(args, retcode=retcode)[0]
46
45
        else:
47
 
            return self.runcmd(['python', self.BZRPATH,] + args,
48
 
                           retcode=retcode)
 
46
            return self.run_bzr_captured(args, retcode=retcode)
49
47
 
50
48
 
51
49
class TestCommands(ExternalBase):
111
109
 
112
110
        file('foo.tmp', 'wt').write('tmp files are ignored')
113
111
        self.assertEquals(list(b.unknowns()), [])
114
 
        assert self.backtick('bzr unknowns') == ''
 
112
        assert self.capture('unknowns') == ''
115
113
 
116
114
        file('foo.c', 'wt').write('int main() {}')
117
115
        self.assertEquals(list(b.unknowns()), ['foo.c'])
118
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
 
116
        assert self.capture('unknowns') == 'foo.c\n'
119
117
 
120
118
        self.runbzr(['add', 'foo.c'])
121
 
        assert self.backtick('bzr unknowns') == ''
 
119
        assert self.capture('unknowns') == ''
122
120
 
123
121
        # 'ignore' works when creating the .bzignore file
124
122
        file('foo.blah', 'wt').write('blah')
130
128
        # 'ignore' works when then .bzrignore file already exists
131
129
        file('garh', 'wt').write('garh')
132
130
        self.assertEquals(list(b.unknowns()), ['garh'])
133
 
        assert self.backtick('bzr unknowns') == 'garh\n'
 
131
        assert self.capture('unknowns') == 'garh\n'
134
132
        self.runbzr('ignore garh')
135
133
        self.assertEquals(list(b.unknowns()), [])
136
134
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
179
177
        self.run_bzr('mv', 'a', 'c', 'subdir')
180
178
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
181
179
 
 
180
 
182
181
    def test_main_version(self):
183
182
        """Check output from version command and master option is reasonable"""
184
183
        # output is intentionally passed through to stdout so that we
300
299
                           'added top.txt',],
301
300
                          results)
302
301
 
 
302
    def test_unknown_command(self):
 
303
        """Handling of unknown command."""
 
304
        out, err = self.run_bzr_captured(['fluffy-badger'],
 
305
                                         retcode=1)
 
306
        self.assertEquals(out, '')
 
307
        err.index('unknown command')
 
308
        
 
309
 
303
310
 
304
311
class OldTests(ExternalBase):
305
312
    """old tests moved from ./testbzr."""
309
316
        from os.path import exists
310
317
 
311
318
        runbzr = self.runbzr
312
 
        backtick = self.backtick
 
319
        capture = self.capture
313
320
        progress = self.log
314
321
 
315
322
        progress("basic branch creation")
317
324
        chdir('branch1')
318
325
        runbzr('init')
319
326
 
320
 
        self.assertEquals(backtick('bzr root').rstrip(),
 
327
        self.assertEquals(capture('root').rstrip(),
321
328
                          os.path.join(self.test_dir, 'branch1'))
322
329
 
323
330
        progress("status of new file")
326
333
        f.write('hello world!\n')
327
334
        f.close()
328
335
 
329
 
        out = backtick("bzr unknowns")
330
 
        self.assertEquals(out, 'test.txt\n')
 
336
        self.assertEquals(capture('unknowns'), 'test.txt\n')
331
337
 
332
 
        out = backtick("bzr status")
 
338
        out = capture("status")
333
339
        assert out == 'unknown:\n  test.txt\n'
334
340
 
335
 
        out = backtick("bzr status --all")
 
341
        out = capture("status --all")
336
342
        assert out == "unknown:\n  test.txt\n"
337
343
 
338
 
        out = backtick("bzr status test.txt --all")
 
344
        out = capture("status test.txt --all")
339
345
        assert out == "unknown:\n  test.txt\n"
340
346
 
341
347
        f = file('test2.txt', 'wt')
342
348
        f.write('goodbye cruel world...\n')
343
349
        f.close()
344
350
 
345
 
        out = backtick("bzr status test.txt")
 
351
        out = capture("status test.txt")
346
352
        assert out == "unknown:\n  test.txt\n"
347
353
 
348
 
        out = backtick("bzr status")
 
354
        out = capture("status")
349
355
        assert out == ("unknown:\n"
350
356
                       "  test.txt\n"
351
357
                       "  test2.txt\n")
353
359
        os.unlink('test2.txt')
354
360
 
355
361
        progress("command aliases")
356
 
        out = backtick("bzr st --all")
 
362
        out = capture("st --all")
357
363
        assert out == ("unknown:\n"
358
364
                       "  test.txt\n")
359
365
 
360
 
        out = backtick("bzr stat")
 
366
        out = capture("stat")
361
367
        assert out == ("unknown:\n"
362
368
                       "  test.txt\n")
363
369
 
367
373
        runbzr("help commands")
368
374
        runbzr("help slartibartfast", 1)
369
375
 
370
 
        out = backtick("bzr help ci")
 
376
        out = capture("help ci")
371
377
        out.index('aliases: ')
372
378
 
373
379
        progress("can't rename unversioned file")
376
382
        progress("adding a file")
377
383
 
378
384
        runbzr("add test.txt")
379
 
        assert backtick("bzr unknowns") == ''
380
 
        assert backtick("bzr status --all") == ("added:\n"
 
385
        assert capture("unknowns") == ''
 
386
        assert capture("status --all") == ("added:\n"
381
387
                                                "  test.txt\n")
382
388
 
383
389
        progress("rename newly-added file")
385
391
        assert os.path.exists("hello.txt")
386
392
        assert not os.path.exists("test.txt")
387
393
 
388
 
        assert backtick("bzr revno") == '0\n'
 
394
        assert capture("revno") == '0\n'
389
395
 
390
396
        progress("add first revision")
391
397
        runbzr(['commit', '-m', 'add first revision'])
399
405
        runbzr("add sub1")
400
406
        runbzr("rename sub1 sub2")
401
407
        runbzr("move hello.txt sub2")
402
 
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
408
        assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
403
409
 
404
410
        assert exists("sub2")
405
411
        assert exists("sub2/hello.txt")
420
426
        runbzr(['commit', '-m', 'rename nested subdirectories'])
421
427
 
422
428
        chdir('sub1/sub2')
423
 
        self.assertEquals(backtick('bzr root')[:-1],
 
429
        self.assertEquals(capture('root')[:-1],
424
430
                          os.path.join(self.test_dir, 'branch1'))
425
431
        runbzr('move ../hello.txt .')
426
432
        assert exists('./hello.txt')
427
 
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
428
 
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
433
        self.assertEquals(capture('relpath hello.txt'),
 
434
                          os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
 
435
        assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
429
436
        runbzr(['commit', '-m', 'move to parent directory'])
430
437
        chdir('..')
431
 
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
438
        assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
432
439
 
433
440
        runbzr('move sub2/hello.txt .')
434
441
        assert exists('hello.txt')
443
450
 
444
451
        runbzr('commit -F msg.tmp')
445
452
 
446
 
        assert backtick('bzr revno') == '5\n'
 
453
        assert capture('revno') == '5\n'
447
454
        runbzr('export -r 5 export-5.tmp')
448
455
        runbzr('export export.tmp')
449
456
 
451
458
        runbzr('log -v')
452
459
        runbzr('log -v --forward')
453
460
        runbzr('log -m', retcode=1)
454
 
        log_out = backtick('bzr log -m commit')
 
461
        log_out = capture('log -m commit')
455
462
        assert "this is my new commit" in log_out
456
463
        assert "rename nested" not in log_out
457
464
        assert 'revision-id' not in log_out
458
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
465
        assert 'revision-id' in capture('log --show-ids -m commit')
459
466
 
460
467
 
461
468
        progress("file with spaces in name")