36
38
class ExternalBase(TestCaseInTempDir):
37
def runbzr(self, args, retcode=0,backtick=False):
39
def runbzr(self, args, retcode=0, backtick=False):
38
40
if isinstance(args, basestring):
39
41
args = args.split()
42
return self.backtick(['python', self.BZRPATH,] + args,
44
return self.run_bzr_captured(args, retcode=retcode)[0]
45
return self.runcmd(['python', self.BZRPATH,] + args,
46
return self.run_bzr_captured(args, retcode=retcode)
49
49
class TestCommands(ExternalBase):
72
72
f = file('.bzr/email', 'wt')
73
73
f.write('Branch Identity <branch@identi.ty>')
75
bzr_email = os.environ.get('BZREMAIL')
76
if bzr_email is not None:
77
del os.environ['BZREMAIL']
75
78
whoami = self.runbzr("whoami",backtick=True)
76
79
whoami_email = self.runbzr("whoami --email",backtick=True)
77
80
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
78
81
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
82
# Verify that the environment variable overrides the value
84
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
85
whoami = self.runbzr("whoami",backtick=True)
86
whoami_email = self.runbzr("whoami --email",backtick=True)
87
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
88
self.assertTrue(whoami_email.startswith('other@environ.ment'))
89
if bzr_email is not None:
90
os.environ['BZREMAIL'] = bzr_email
80
92
def test_invalid_commands(self):
81
93
self.runbzr("pants", retcode=1)
92
104
def test_ignore_patterns(self):
93
105
from bzrlib.branch import Branch
95
b = Branch('.', init=True)
107
b = Branch.initialize('.')
96
108
self.assertEquals(list(b.unknowns()), [])
98
110
file('foo.tmp', 'wt').write('tmp files are ignored')
99
111
self.assertEquals(list(b.unknowns()), [])
100
assert self.backtick('bzr unknowns') == ''
112
assert self.capture('unknowns') == ''
102
114
file('foo.c', 'wt').write('int main() {}')
103
115
self.assertEquals(list(b.unknowns()), ['foo.c'])
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
116
assert self.capture('unknowns') == 'foo.c\n'
106
118
self.runbzr(['add', 'foo.c'])
107
assert self.backtick('bzr unknowns') == ''
119
assert self.capture('unknowns') == ''
109
121
# 'ignore' works when creating the .bzignore file
110
122
file('foo.blah', 'wt').write('blah')
116
128
# 'ignore' works when then .bzrignore file already exists
117
129
file('garh', 'wt').write('garh')
118
130
self.assertEquals(list(b.unknowns()), ['garh'])
119
assert self.backtick('bzr unknowns') == 'garh\n'
131
assert self.capture('unknowns') == 'garh\n'
120
132
self.runbzr('ignore garh')
121
133
self.assertEquals(list(b.unknowns()), [])
122
134
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
124
136
def test_revert(self):
126
137
self.runbzr('init')
128
139
file('hello', 'wt').write('foo')
147
158
os.rmdir('revertdir')
148
159
self.runbzr('revert')
150
def skipped_test_mv_modes(self):
161
file('hello', 'wt').write('xyz')
162
self.runbzr('commit -m xyz hello')
163
self.runbzr('revert -r 1 hello')
164
self.check_file_contents('hello', 'foo')
165
self.runbzr('revert hello')
166
self.check_file_contents('hello', 'xyz')
168
def test_mv_modes(self):
151
169
"""Test two modes of operation for mv"""
152
170
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
171
b = Branch.initialize('.')
154
172
self.build_tree(['a', 'c', 'subdir/'])
173
self.run_bzr('add', self.test_dir)
155
174
self.run_bzr('mv', 'a', 'b')
156
175
self.run_bzr('mv', 'b', 'subdir')
157
176
self.run_bzr('mv', 'subdir/b', 'a')
158
self.run_bzr('mv', 'a', 'b', 'subdir')
177
self.run_bzr('mv', 'a', 'c', 'subdir')
159
178
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
161
181
def test_main_version(self):
162
182
"""Check output from version command and master option is reasonable"""
163
183
# output is intentionally passed through to stdout so that we
182
202
test.runbzr('add goodbye')
183
203
test.runbzr('commit -m setup goodbye')
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')
206
self.example_branch()
207
file('hello', 'wt').write('hello world!')
208
self.runbzr('commit -m fixing hello')
209
output = self.runbzr('diff -r 2..3', backtick=1)
210
self.assert_('\n+hello world!' in output)
211
output = self.runbzr('diff -r last:3..last:1', backtick=1)
212
self.assert_('\n+baz' in output)
215
self.example_branch()
216
file('hello', 'wt').write('hello world!')
217
self.runbzr('commit -m fixing hello')
218
output = self.runbzr('diff -r 2..3', backtick=1)
219
self.assert_('\n+hello world!' in output)
220
output = self.runbzr('diff -r last:3..last:1', backtick=1)
221
self.assert_('\n+baz' in output)
195
223
def test_merge(self):
196
224
from bzrlib.branch import Branch
202
228
self.example_branch()
204
230
self.runbzr('branch a b')
214
240
self.runbzr('merge ../b')
215
241
self.check_file_contents('goodbye', 'quux')
216
242
# Merging a branch pulls its revision into the tree
244
b = Branch.open('../b')
219
245
a.get_revision_xml(b.last_patch())
221
246
self.log('pending merges: %s', a.pending_merges())
222
247
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
248
# % (a.pending_merges(), b.last_patch())
251
"""Pull changes from one branch to another."""
255
self.example_branch()
256
self.runbzr('pull', retcode=1)
257
self.runbzr('missing', retcode=1)
258
self.runbzr('missing .')
259
self.runbzr('missing')
261
self.runbzr('pull /', retcode=1)
265
self.runbzr('branch a b')
268
self.runbzr('commit -m blah --unchanged')
271
b = Branch.open('../b')
272
assert a.revision_history() == b.revision_history()[:-1]
273
self.runbzr('pull ../b')
274
assert a.revision_history() == b.revision_history()
275
self.runbzr('commit -m blah2 --unchanged')
277
self.runbzr('commit -m blah3 --unchanged')
278
self.runbzr('pull ../a', retcode=1)
280
self.runbzr('merge ../b')
281
self.runbzr('commit -m blah4 --unchanged')
283
self.runbzr('pull ../a')
284
assert a.revision_history()[-1] == b.revision_history()[-1]
226
286
def test_add_reports(self):
227
287
"""add command prints the names of added files."""
228
b = Branch('.', init=True)
288
b = Branch.initialize('.')
229
289
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
from cStringIO import StringIO
234
291
ret = self.apply_redirected(None, out, None,
237
294
self.assertEquals(ret, 0)
239
295
# the ordering is not defined at the moment
240
296
results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
297
self.assertEquals(['added dir',
243
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')
247
311
class OldTests(ExternalBase):
248
312
"""old tests moved from ./testbzr."""
264
self.assertEquals(backtick('bzr root').rstrip(),
327
self.assertEquals(capture('root').rstrip(),
265
328
os.path.join(self.test_dir, 'branch1'))
267
330
progress("status of new file")
270
333
f.write('hello world!\n')
273
out = backtick("bzr unknowns")
274
self.assertEquals(out, 'test.txt\n')
336
self.assertEquals(capture('unknowns'), 'test.txt\n')
276
out = backtick("bzr status")
338
out = capture("status")
277
339
assert out == 'unknown:\n test.txt\n'
279
out = backtick("bzr status --all")
341
out = capture("status --all")
280
342
assert out == "unknown:\n test.txt\n"
282
out = backtick("bzr status test.txt --all")
344
out = capture("status test.txt --all")
283
345
assert out == "unknown:\n test.txt\n"
285
347
f = file('test2.txt', 'wt')
286
348
f.write('goodbye cruel world...\n')
289
out = backtick("bzr status test.txt")
351
out = capture("status test.txt")
290
352
assert out == "unknown:\n test.txt\n"
292
out = backtick("bzr status")
354
out = capture("status")
293
355
assert out == ("unknown:\n"
297
359
os.unlink('test2.txt')
299
361
progress("command aliases")
300
out = backtick("bzr st --all")
362
out = capture("st --all")
301
363
assert out == ("unknown:\n"
304
out = backtick("bzr stat")
366
out = capture("stat")
305
367
assert out == ("unknown:\n"
320
382
progress("adding a file")
322
384
runbzr("add test.txt")
323
assert backtick("bzr unknowns") == ''
324
assert backtick("bzr status --all") == ("added:\n"
385
assert capture("unknowns") == ''
386
assert capture("status --all") == ("added:\n"
327
389
progress("rename newly-added file")
329
391
assert os.path.exists("hello.txt")
330
392
assert not os.path.exists("test.txt")
332
assert backtick("bzr revno") == '0\n'
394
assert capture("revno") == '0\n'
334
396
progress("add first revision")
335
397
runbzr(['commit', '-m', 'add first revision'])
343
405
runbzr("add sub1")
344
406
runbzr("rename sub1 sub2")
345
407
runbzr("move hello.txt sub2")
346
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")
348
410
assert exists("sub2")
349
411
assert exists("sub2/hello.txt")
364
426
runbzr(['commit', '-m', 'rename nested subdirectories'])
366
428
chdir('sub1/sub2')
367
self.assertEquals(backtick('bzr root')[:-1],
429
self.assertEquals(capture('root')[:-1],
368
430
os.path.join(self.test_dir, 'branch1'))
369
431
runbzr('move ../hello.txt .')
370
432
assert exists('./hello.txt')
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')
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')
373
436
runbzr(['commit', '-m', 'move to parent directory'])
375
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')
377
440
runbzr('move sub2/hello.txt .')
378
441
assert exists('hello.txt')
388
451
runbzr('commit -F msg.tmp')
390
assert backtick('bzr revno') == '5\n'
453
assert capture('revno') == '5\n'
391
454
runbzr('export -r 5 export-5.tmp')
392
455
runbzr('export export.tmp')
396
459
runbzr('log -v --forward')
397
460
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
461
log_out = capture('log -m commit')
399
462
assert "this is my new commit" in log_out
400
463
assert "rename nested" not in log_out
401
464
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
465
assert 'revision-id' in capture('log --show-ids -m commit')
405
468
progress("file with spaces in name")