30
from bzrlib.selftest import InTempDir, BzrTestBase
33
class ExternalBase(InTempDir):
35
def runbzr(self, args, retcode=0,backtick=False):
38
from subprocess import call
39
except ImportError, e:
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
37
class ExternalBase(TestCaseInTempDir):
38
def runbzr(self, args, retcode=0, backtick=False):
43
39
if isinstance(args, basestring):
44
40
args = args.split()
47
return self.backtick(['python', self.BZRPATH,] + args,
43
return self.run_bzr_captured(args, retcode=retcode)[0]
50
return self.runcmd(['python', self.BZRPATH,] + args,
45
return self.run_bzr_captured(args, retcode=retcode)
53
48
class TestCommands(ExternalBase):
97
91
def test_ignore_patterns(self):
98
92
from bzrlib.branch import Branch
100
b = Branch('.', init=True)
94
b = Branch.initialize('.')
101
95
self.assertEquals(list(b.unknowns()), [])
103
97
file('foo.tmp', 'wt').write('tmp files are ignored')
104
98
self.assertEquals(list(b.unknowns()), [])
105
assert self.backtick('bzr unknowns') == ''
99
assert self.capture('unknowns') == ''
107
101
file('foo.c', 'wt').write('int main() {}')
108
102
self.assertEquals(list(b.unknowns()), ['foo.c'])
109
assert self.backtick('bzr unknowns') == 'foo.c\n'
103
assert self.capture('unknowns') == 'foo.c\n'
111
105
self.runbzr(['add', 'foo.c'])
112
assert self.backtick('bzr unknowns') == ''
106
assert self.capture('unknowns') == ''
114
108
# 'ignore' works when creating the .bzignore file
115
109
file('foo.blah', 'wt').write('blah')
153
145
os.rmdir('revertdir')
154
146
self.runbzr('revert')
157
def skipped_test_mv_modes(self):
148
def test_mv_modes(self):
158
149
"""Test two modes of operation for mv"""
159
150
from bzrlib.branch import Branch
160
b = Branch('.', init=True)
151
b = Branch.initialize('.')
161
152
self.build_tree(['a', 'c', 'subdir/'])
153
self.run_bzr('add', self.test_dir)
162
154
self.run_bzr('mv', 'a', 'b')
163
155
self.run_bzr('mv', 'b', 'subdir')
164
156
self.run_bzr('mv', 'subdir/b', 'a')
165
self.run_bzr('mv', 'a', 'b', 'subdir')
157
self.run_bzr('mv', 'a', 'c', 'subdir')
166
158
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
168
161
def test_main_version(self):
169
162
"""Check output from version command and master option is reasonable"""
170
163
# output is intentionally passed through to stdout so that we
180
173
self.log(tmp_output)
181
174
self.assertEquals(output, tmp_output)
176
def example_branch(test):
178
file('hello', 'wt').write('foo')
179
test.runbzr('add hello')
180
test.runbzr('commit -m setup hello')
181
file('goodbye', 'wt').write('baz')
182
test.runbzr('add goodbye')
183
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')
195
def test_merge(self):
196
from bzrlib.branch import Branch
200
self.example_branch()
202
self.runbzr('branch a b')
204
file('goodbye', 'wt').write('quux')
205
self.runbzr(['commit', '-m', "more u's are always good"])
208
file('hello', 'wt').write('quuux')
209
# We can't merge when there are in-tree changes
210
self.runbzr('merge ../b', retcode=1)
211
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
212
self.runbzr('merge ../b')
213
self.check_file_contents('goodbye', 'quux')
214
# Merging a branch pulls its revision into the tree
216
b = Branch.open('../b')
217
a.get_revision_xml(b.last_patch())
218
self.log('pending merges: %s', a.pending_merges())
219
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
220
# % (a.pending_merges(), b.last_patch())
223
"""Pull changes from one branch to another."""
227
self.example_branch()
228
self.runbzr('pull', retcode=1)
229
self.runbzr('missing', retcode=1)
230
self.runbzr('missing .')
231
self.runbzr('missing')
233
self.runbzr('pull /', retcode=1)
237
self.runbzr('branch a b')
240
self.runbzr('commit -m blah --unchanged')
243
b = Branch.open('../b')
244
assert a.revision_history() == b.revision_history()[:-1]
245
self.runbzr('pull ../b')
246
assert a.revision_history() == b.revision_history()
247
self.runbzr('commit -m blah2 --unchanged')
249
self.runbzr('commit -m blah3 --unchanged')
250
self.runbzr('pull ../a', retcode=1)
252
self.runbzr('merge ../b')
253
self.runbzr('commit -m blah4 --unchanged')
255
self.runbzr('pull ../a')
256
assert a.revision_history()[-1] == b.revision_history()[-1]
259
def test_add_reports(self):
260
"""add command prints the names of added files."""
261
b = Branch.initialize('.')
262
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
264
from cStringIO import StringIO
267
ret = self.apply_redirected(None, out, None,
270
self.assertEquals(ret, 0)
272
# the ordering is not defined at the moment
273
results = sorted(out.getvalue().rstrip('\n').split('\n'))
274
self.assertEquals(['added dir',
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')
183
288
class OldTests(ExternalBase):
184
# old tests moved from ./testbzr
289
"""old tests moved from ./testbzr."""
185
291
def test_bzr(self):
186
292
from os import chdir, mkdir
187
293
from os.path import exists
190
295
runbzr = self.runbzr
191
backtick = self.backtick
296
capture = self.capture
192
297
progress = self.log
194
299
progress("basic branch creation")
205
310
f.write('hello world!\n')
208
out = backtick("bzr unknowns")
209
self.assertEquals(out, 'test.txt\n')
313
self.assertEquals(capture('unknowns'), 'test.txt\n')
211
out = backtick("bzr status")
315
out = capture("status")
212
316
assert out == 'unknown:\n test.txt\n'
214
out = backtick("bzr status --all")
318
out = capture("status --all")
215
319
assert out == "unknown:\n test.txt\n"
217
out = backtick("bzr status test.txt --all")
321
out = capture("status test.txt --all")
218
322
assert out == "unknown:\n test.txt\n"
220
324
f = file('test2.txt', 'wt')
221
325
f.write('goodbye cruel world...\n')
224
out = backtick("bzr status test.txt")
328
out = capture("status test.txt")
225
329
assert out == "unknown:\n test.txt\n"
227
out = backtick("bzr status")
331
out = capture("status")
228
332
assert out == ("unknown:\n"
299
403
runbzr(['commit', '-m', 'rename nested subdirectories'])
301
405
chdir('sub1/sub2')
302
self.assertEquals(backtick('bzr root')[:-1],
406
self.assertEquals(capture('root')[:-1],
303
407
os.path.join(self.test_dir, 'branch1'))
304
408
runbzr('move ../hello.txt .')
305
409
assert exists('./hello.txt')
306
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
307
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')
308
413
runbzr(['commit', '-m', 'move to parent directory'])
310
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')
312
417
runbzr('move sub2/hello.txt .')
313
418
assert exists('hello.txt')
355
def example_branch(test):
358
file('hello', 'wt').write('foo')
359
test.runbzr('add hello')
360
test.runbzr('commit -m setup hello')
362
file('goodbye', 'wt').write('baz')
363
test.runbzr('add goodbye')
364
test.runbzr('commit -m setup goodbye')
367
class RevertCommand(ExternalBase):
370
file('hello', 'wt').write('bar')
371
file('goodbye', 'wt').write('qux')
372
self.runbzr('revert hello')
373
self.check_file_contents('hello', 'foo')
374
self.check_file_contents('goodbye', 'qux')
375
self.runbzr('revert')
376
self.check_file_contents('goodbye', 'baz')
379
class MergeCommand(ExternalBase):
381
from bzrlib.branch import Branch
387
self.runbzr('branch a b')
389
file('goodbye', 'wt').write('quux')
390
self.runbzr(['commit', '-m', "more u's are always good"])
393
file('hello', 'wt').write('quuux')
394
# We can't merge when there are in-tree changes
395
self.runbzr('merge ../b', retcode=1)
396
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
397
self.runbzr('merge ../b')
398
self.check_file_contents('goodbye', 'quux')
399
# Merging a branch pulls its revision into the tree
402
a.get_revision_xml(b.last_patch())
403
print "Pending: %s" % a.pending_merges()
404
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
405
# % (a.pending_merges(), b.last_patch())