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()
44
return self.backtick(['python', self.BZRPATH,] + args,
44
return self.run_bzr_captured(args, retcode=retcode)[0]
47
return self.runcmd(['python', self.BZRPATH,] + args,
46
return self.run_bzr_captured(args, retcode=retcode)
51
49
class TestCommands(ExternalBase):
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') == ''
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'
120
118
self.runbzr(['add', 'foo.c'])
121
assert self.backtick('bzr unknowns') == ''
119
assert self.capture('unknowns') == ''
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')
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',],
302
def test_unknown_command(self):
303
"""Handling of unknown command."""
304
out, err = self.run_bzr_captured(['fluffy-badger'],
306
self.assertEquals(out, '')
307
err.index('unknown command')
304
311
class OldTests(ExternalBase):
305
312
"""old tests moved from ./testbzr."""
320
self.assertEquals(backtick('bzr root').rstrip(),
327
self.assertEquals(capture('root').rstrip(),
321
328
os.path.join(self.test_dir, 'branch1'))
323
330
progress("status of new file")
326
333
f.write('hello world!\n')
329
out = backtick("bzr unknowns")
330
self.assertEquals(out, 'test.txt\n')
336
self.assertEquals(capture('unknowns'), 'test.txt\n')
332
out = backtick("bzr status")
338
out = capture("status")
333
339
assert out == 'unknown:\n test.txt\n'
335
out = backtick("bzr status --all")
341
out = capture("status --all")
336
342
assert out == "unknown:\n test.txt\n"
338
out = backtick("bzr status test.txt --all")
344
out = capture("status test.txt --all")
339
345
assert out == "unknown:\n test.txt\n"
341
347
f = file('test2.txt', 'wt')
342
348
f.write('goodbye cruel world...\n')
345
out = backtick("bzr status test.txt")
351
out = capture("status test.txt")
346
352
assert out == "unknown:\n test.txt\n"
348
out = backtick("bzr status")
354
out = capture("status")
349
355
assert out == ("unknown:\n"
353
359
os.unlink('test2.txt')
355
361
progress("command aliases")
356
out = backtick("bzr st --all")
362
out = capture("st --all")
357
363
assert out == ("unknown:\n"
360
out = backtick("bzr stat")
366
out = capture("stat")
361
367
assert out == ("unknown:\n"
376
382
progress("adding a file")
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"
383
389
progress("rename newly-added file")
385
391
assert os.path.exists("hello.txt")
386
392
assert not os.path.exists("test.txt")
388
assert backtick("bzr revno") == '0\n'
394
assert capture("revno") == '0\n'
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")
404
410
assert exists("sub2")
405
411
assert exists("sub2/hello.txt")
420
426
runbzr(['commit', '-m', 'rename nested subdirectories'])
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'])
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')
433
440
runbzr('move sub2/hello.txt .')
434
441
assert exists('hello.txt')
444
451
runbzr('commit -F msg.tmp')
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')
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')
461
468
progress("file with spaces in name")