37
37
class ExternalBase(TestCaseInTempDir):
38
def runbzr(self, args, retcode=0,backtick=False):
38
def runbzr(self, args, retcode=0, backtick=False):
39
39
if isinstance(args, basestring):
40
40
args = args.split()
43
return self.backtick(['python', self.BZRPATH,] + args,
43
return self.run_bzr_captured(args, retcode=retcode)[0]
46
return self.runcmd(['python', self.BZRPATH,] + args,
45
return self.run_bzr_captured(args, retcode=retcode)
50
48
class TestCommands(ExternalBase):
93
91
def test_ignore_patterns(self):
94
92
from bzrlib.branch import Branch
96
b = Branch('.', init=True)
94
b = Branch.initialize('.')
97
95
self.assertEquals(list(b.unknowns()), [])
99
97
file('foo.tmp', 'wt').write('tmp files are ignored')
100
98
self.assertEquals(list(b.unknowns()), [])
101
assert self.backtick('bzr unknowns') == ''
99
assert self.capture('unknowns') == ''
103
101
file('foo.c', 'wt').write('int main() {}')
104
102
self.assertEquals(list(b.unknowns()), ['foo.c'])
105
assert self.backtick('bzr unknowns') == 'foo.c\n'
103
assert self.capture('unknowns') == 'foo.c\n'
107
105
self.runbzr(['add', 'foo.c'])
108
assert self.backtick('bzr unknowns') == ''
106
assert self.capture('unknowns') == ''
110
108
# 'ignore' works when creating the .bzignore file
111
109
file('foo.blah', 'wt').write('blah')
117
115
# 'ignore' works when then .bzrignore file already exists
118
116
file('garh', 'wt').write('garh')
119
117
self.assertEquals(list(b.unknowns()), ['garh'])
120
assert self.backtick('bzr unknowns') == 'garh\n'
118
assert self.capture('unknowns') == 'garh\n'
121
119
self.runbzr('ignore garh')
122
120
self.assertEquals(list(b.unknowns()), [])
123
121
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
150
148
def test_mv_modes(self):
151
149
"""Test two modes of operation for mv"""
152
150
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
151
b = Branch.initialize('.')
154
152
self.build_tree(['a', 'c', 'subdir/'])
155
153
self.run_bzr('add', self.test_dir)
156
154
self.run_bzr('mv', 'a', 'b')
214
212
self.runbzr('merge ../b')
215
213
self.check_file_contents('goodbye', 'quux')
216
214
# Merging a branch pulls its revision into the tree
216
b = Branch.open('../b')
219
217
a.get_revision_xml(b.last_patch())
220
218
self.log('pending merges: %s', a.pending_merges())
221
219
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
261
259
def test_add_reports(self):
262
260
"""add command prints the names of added files."""
263
b = Branch('.', init=True)
261
b = Branch.initialize('.')
264
262
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
266
264
from cStringIO import StringIO
278
276
'added top.txt',],
279
def test_unknown_command(self):
280
"""Handling of unknown command."""
281
out, err = self.run_bzr_captured(['fluffy-badger'],
283
self.assertEquals(out, '')
284
err.index('unknown command')
282
288
class OldTests(ExternalBase):
283
289
"""old tests moved from ./testbzr."""
298
self.assertEquals(backtick('bzr root').rstrip(),
304
self.assertEquals(capture('root').rstrip(),
299
305
os.path.join(self.test_dir, 'branch1'))
301
307
progress("status of new file")
304
310
f.write('hello world!\n')
307
out = backtick("bzr unknowns")
308
self.assertEquals(out, 'test.txt\n')
313
self.assertEquals(capture('unknowns'), 'test.txt\n')
310
out = backtick("bzr status")
315
out = capture("status")
311
316
assert out == 'unknown:\n test.txt\n'
313
out = backtick("bzr status --all")
318
out = capture("status --all")
314
319
assert out == "unknown:\n test.txt\n"
316
out = backtick("bzr status test.txt --all")
321
out = capture("status test.txt --all")
317
322
assert out == "unknown:\n test.txt\n"
319
324
f = file('test2.txt', 'wt')
320
325
f.write('goodbye cruel world...\n')
323
out = backtick("bzr status test.txt")
328
out = capture("status test.txt")
324
329
assert out == "unknown:\n test.txt\n"
326
out = backtick("bzr status")
331
out = capture("status")
327
332
assert out == ("unknown:\n"
331
336
os.unlink('test2.txt')
333
338
progress("command aliases")
334
out = backtick("bzr st --all")
339
out = capture("st --all")
335
340
assert out == ("unknown:\n"
338
out = backtick("bzr stat")
343
out = capture("stat")
339
344
assert out == ("unknown:\n"
354
359
progress("adding a file")
356
361
runbzr("add test.txt")
357
assert backtick("bzr unknowns") == ''
358
assert backtick("bzr status --all") == ("added:\n"
362
assert capture("unknowns") == ''
363
assert capture("status --all") == ("added:\n"
361
366
progress("rename newly-added file")
363
368
assert os.path.exists("hello.txt")
364
369
assert not os.path.exists("test.txt")
366
assert backtick("bzr revno") == '0\n'
371
assert capture("revno") == '0\n'
368
373
progress("add first revision")
369
374
runbzr(['commit', '-m', 'add first revision'])
377
382
runbzr("add sub1")
378
383
runbzr("rename sub1 sub2")
379
384
runbzr("move hello.txt sub2")
380
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
385
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
382
387
assert exists("sub2")
383
388
assert exists("sub2/hello.txt")
398
403
runbzr(['commit', '-m', 'rename nested subdirectories'])
400
405
chdir('sub1/sub2')
401
self.assertEquals(backtick('bzr root')[:-1],
406
self.assertEquals(capture('root')[:-1],
402
407
os.path.join(self.test_dir, 'branch1'))
403
408
runbzr('move ../hello.txt .')
404
409
assert exists('./hello.txt')
405
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
406
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
410
self.assertEquals(capture('relpath hello.txt'),
411
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
412
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
407
413
runbzr(['commit', '-m', 'move to parent directory'])
409
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
415
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
411
417
runbzr('move sub2/hello.txt .')
412
418
assert exists('hello.txt')
422
428
runbzr('commit -F msg.tmp')
424
assert backtick('bzr revno') == '5\n'
430
assert capture('revno') == '5\n'
425
431
runbzr('export -r 5 export-5.tmp')
426
432
runbzr('export export.tmp')
430
436
runbzr('log -v --forward')
431
437
runbzr('log -m', retcode=1)
432
log_out = backtick('bzr log -m commit')
438
log_out = capture('log -m commit')
433
439
assert "this is my new commit" in log_out
434
440
assert "rename nested" not in log_out
435
441
assert 'revision-id' not in log_out
436
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
442
assert 'revision-id' in capture('log --show-ids -m commit')
439
445
progress("file with spaces in name")