26
26
it's normally invoked.
29
from cStringIO import StringIO
33
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
34
from bzrlib.branch import Branch
37
class ExternalBase(TestCaseInTempDir):
39
def runbzr(self, args, retcode=0, backtick=False):
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:
40
43
if isinstance(args, basestring):
41
44
args = args.split()
44
return self.run_bzr_captured(args, retcode=retcode)[0]
47
return self.backtick(['python', self.BZRPATH,] + args,
46
return self.run_bzr_captured(args, retcode=retcode)
50
return self.runcmd(['python', self.BZRPATH,] + args,
49
53
class TestCommands(ExternalBase):
72
77
f = file('.bzr/email', 'wt')
73
78
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']
78
80
whoami = self.runbzr("whoami",backtick=True)
79
81
whoami_email = self.runbzr("whoami --email",backtick=True)
80
82
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
81
83
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
92
85
def test_invalid_commands(self):
93
86
self.runbzr("pants", retcode=1)
104
97
def test_ignore_patterns(self):
105
98
from bzrlib.branch import Branch
107
b = Branch.initialize('.')
100
b = Branch('.', init=True)
108
101
self.assertEquals(list(b.unknowns()), [])
110
103
file('foo.tmp', 'wt').write('tmp files are ignored')
111
104
self.assertEquals(list(b.unknowns()), [])
112
assert self.capture('unknowns') == ''
105
assert self.backtick('bzr unknowns') == ''
114
107
file('foo.c', 'wt').write('int main() {}')
115
108
self.assertEquals(list(b.unknowns()), ['foo.c'])
116
assert self.capture('unknowns') == 'foo.c\n'
109
assert self.backtick('bzr unknowns') == 'foo.c\n'
118
111
self.runbzr(['add', 'foo.c'])
119
assert self.capture('unknowns') == ''
112
assert self.backtick('bzr unknowns') == ''
121
114
# 'ignore' works when creating the .bzignore file
122
115
file('foo.blah', 'wt').write('blah')
128
121
# 'ignore' works when then .bzrignore file already exists
129
122
file('garh', 'wt').write('garh')
130
123
self.assertEquals(list(b.unknowns()), ['garh'])
131
assert self.capture('unknowns') == 'garh\n'
124
assert self.backtick('bzr unknowns') == 'garh\n'
132
125
self.runbzr('ignore garh')
133
126
self.assertEquals(list(b.unknowns()), [])
134
127
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
136
129
def test_revert(self):
137
131
self.runbzr('init')
139
133
file('hello', 'wt').write('foo')
158
152
os.rmdir('revertdir')
159
153
self.runbzr('revert')
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')
167
os.chdir('revertdir')
168
self.runbzr('revert')
172
def test_mv_modes(self):
155
def skipped_test_mv_modes(self):
173
156
"""Test two modes of operation for mv"""
174
157
from bzrlib.branch import Branch
175
b = Branch.initialize('.')
158
b = Branch('.', init=True)
176
159
self.build_tree(['a', 'c', 'subdir/'])
177
self.run_bzr_captured(['add', self.test_dir])
178
self.run_bzr_captured(['mv', 'a', 'b'])
179
self.run_bzr_captured(['mv', 'b', 'subdir'])
180
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
181
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
182
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
160
self.run_bzr('mv', 'a', 'b')
161
self.run_bzr('mv', 'b', 'subdir')
162
self.run_bzr('mv', 'subdir/b', 'a')
163
self.run_bzr('mv', 'a', 'b', 'subdir')
164
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
185
166
def test_main_version(self):
186
167
"""Check output from version command and master option is reasonable"""
206
187
test.runbzr('add goodbye')
207
188
test.runbzr('commit -m setup goodbye')
210
self.example_branch()
211
file('hello', 'wt').write('hello world!')
212
self.runbzr('commit -m fixing hello')
213
output = self.runbzr('diff -r 2..3', backtick=1)
214
self.assert_('\n+hello world!' in output)
215
output = self.runbzr('diff -r last:3..last:1', backtick=1)
216
self.assert_('\n+baz' in output)
218
def test_branch(self):
219
"""Branch from one branch to another."""
222
self.example_branch()
224
self.runbzr('branch a b')
225
self.runbzr('branch a c -r 1')
190
def test_revert(self):
191
self.example_branch()
192
file('hello', 'wt').write('bar')
193
file('goodbye', 'wt').write('qux')
194
self.runbzr('revert hello')
195
self.check_file_contents('hello', 'foo')
196
self.check_file_contents('goodbye', 'qux')
197
self.runbzr('revert')
198
self.check_file_contents('goodbye', 'baz')
227
200
def test_merge(self):
228
201
from bzrlib.branch import Branch
232
205
self.example_branch()
244
217
self.runbzr('merge ../b')
245
218
self.check_file_contents('goodbye', 'quux')
246
219
# Merging a branch pulls its revision into the tree
248
b = Branch.open('../b')
249
222
a.get_revision_xml(b.last_patch())
250
self.log('pending merges: %s', a.pending_merges())
251
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
252
# % (a.pending_merges(), b.last_patch())
255
"""Pull changes from one branch to another."""
259
self.example_branch()
260
self.runbzr('pull', retcode=1)
261
self.runbzr('missing', retcode=1)
262
self.runbzr('missing .')
263
self.runbzr('missing')
265
self.runbzr('pull /', retcode=1)
269
self.runbzr('branch a b')
273
self.runbzr('add subdir')
274
self.runbzr('commit -m blah --unchanged')
277
b = Branch.open('../b')
278
assert a.revision_history() == b.revision_history()[:-1]
279
self.runbzr('pull ../b')
280
assert a.revision_history() == b.revision_history()
281
self.runbzr('commit -m blah2 --unchanged')
283
self.runbzr('commit -m blah3 --unchanged')
284
self.runbzr('pull ../a', retcode=1)
286
self.runbzr('merge ../b')
287
self.runbzr('commit -m blah4 --unchanged')
288
os.chdir('../b/subdir')
289
self.runbzr('pull ../../a')
290
assert a.revision_history()[-1] == b.revision_history()[-1]
292
def test_add_reports(self):
293
"""add command prints the names of added files."""
294
b = Branch.initialize('.')
295
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
296
out = self.run_bzr_captured(['add'], retcode = 0)[0]
297
# the ordering is not defined at the moment
298
results = sorted(out.rstrip('\n').split('\n'))
299
self.assertEquals(['added dir',
304
def test_unknown_command(self):
305
"""Handling of unknown command."""
306
out, err = self.run_bzr_captured(['fluffy-badger'],
308
self.assertEquals(out, '')
309
err.index('unknown command')
223
print "Pending: %s" % a.pending_merges()
224
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
225
# % (a.pending_merges(), b.last_patch())
313
227
class OldTests(ExternalBase):
314
228
"""old tests moved from ./testbzr."""
335
250
f.write('hello world!\n')
338
self.assertEquals(capture('unknowns'), 'test.txt\n')
253
out = backtick("bzr unknowns")
254
self.assertEquals(out, 'test.txt\n')
340
out = capture("status")
256
out = backtick("bzr status")
341
257
assert out == 'unknown:\n test.txt\n'
343
out = capture("status --all")
259
out = backtick("bzr status --all")
344
260
assert out == "unknown:\n test.txt\n"
346
out = capture("status test.txt --all")
262
out = backtick("bzr status test.txt --all")
347
263
assert out == "unknown:\n test.txt\n"
349
265
f = file('test2.txt', 'wt')
350
266
f.write('goodbye cruel world...\n')
353
out = capture("status test.txt")
269
out = backtick("bzr status test.txt")
354
270
assert out == "unknown:\n test.txt\n"
356
out = capture("status")
272
out = backtick("bzr status")
357
273
assert out == ("unknown:\n"
393
309
assert os.path.exists("hello.txt")
394
310
assert not os.path.exists("test.txt")
396
assert capture("revno") == '0\n'
312
assert backtick("bzr revno") == '0\n'
398
314
progress("add first revision")
399
315
runbzr(['commit', '-m', 'add first revision'])
428
344
runbzr(['commit', '-m', 'rename nested subdirectories'])
430
346
chdir('sub1/sub2')
431
self.assertEquals(capture('root')[:-1],
347
self.assertEquals(backtick('bzr root')[:-1],
432
348
os.path.join(self.test_dir, 'branch1'))
433
349
runbzr('move ../hello.txt .')
434
350
assert exists('./hello.txt')
435
self.assertEquals(capture('relpath hello.txt'),
436
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
437
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
351
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
352
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
438
353
runbzr(['commit', '-m', 'move to parent directory'])
440
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
355
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
442
357
runbzr('move sub2/hello.txt .')
443
358
assert exists('hello.txt')
461
376
runbzr('log -v --forward')
462
377
runbzr('log -m', retcode=1)
463
log_out = capture('log -m commit')
378
log_out = backtick('bzr log -m commit')
464
379
assert "this is my new commit" in log_out
465
380
assert "rename nested" not in log_out
466
381
assert 'revision-id' not in log_out
467
assert 'revision-id' in capture('log --show-ids -m commit')
382
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
470
385
progress("file with spaces in name")