26
26
it's normally invoked.
29
from cStringIO import StringIO
31
33
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
32
34
from bzrlib.branch import Branch
33
from bzrlib.commands import run_bzr
36
37
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')
111
123
self.assertEquals(list(b.unknowns()), ['foo.blah'])
112
124
self.runbzr('ignore *.blah')
113
125
self.assertEquals(list(b.unknowns()), [])
114
assert file('.bzrignore', 'rb').read() == '*.blah\n'
126
assert file('.bzrignore', 'rU').read() == '*.blah\n'
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
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
134
assert file('.bzrignore', 'rU').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')
167
os.chdir('revertdir')
168
self.runbzr('revert')
172
def test_mv_modes(self):
151
173
"""Test two modes of operation for mv"""
152
174
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
175
b = Branch.initialize('.')
154
176
self.build_tree(['a', 'c', 'subdir/'])
155
self.run_bzr('mv', 'a', 'b')
156
self.run_bzr('mv', 'b', 'subdir')
157
self.run_bzr('mv', 'subdir/b', 'a')
158
self.run_bzr('mv', 'a', 'b', 'subdir')
159
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
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'])
161
185
def test_main_version(self):
162
186
"""Check output from version command and master option is reasonable"""
182
206
test.runbzr('add goodbye')
183
207
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')
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')
195
227
def test_merge(self):
196
228
from bzrlib.branch import Branch
202
232
self.example_branch()
204
234
self.runbzr('branch a b')
214
244
self.runbzr('merge ../b')
215
245
self.check_file_contents('goodbye', 'quux')
216
246
# Merging a branch pulls its revision into the tree
248
b = Branch.open('../b')
219
249
a.get_revision_xml(b.last_revision())
221
250
self.log('pending merges: %s', a.pending_merges())
222
251
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
223
252
# % (a.pending_merges(), b.last_revision())
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)
285
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
287
## self.runbzr('merge ../b')
288
## self.runbzr('commit -m blah4 --unchanged')
289
## os.chdir('../b/subdir')
290
## self.runbzr('pull ../../a')
291
## assert a.revision_history()[-1] == b.revision_history()[-1]
226
293
def test_add_reports(self):
227
294
"""add command prints the names of added files."""
228
b = Branch('.', init=True)
295
b = Branch.initialize('.')
229
296
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
from cStringIO import StringIO
234
ret = self.apply_redirected(None, out, None,
237
self.assertEquals(ret, 0)
297
out = self.run_bzr_captured(['add'], retcode = 0)[0]
239
298
# the ordering is not defined at the moment
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
299
results = sorted(out.rstrip('\n').split('\n'))
241
300
self.assertEquals(['added dir',
301
'added dir'+os.sep+'sub.txt',
243
302
'added top.txt',],
305
def test_unknown_command(self):
306
"""Handling of unknown command."""
307
out, err = self.run_bzr_captured(['fluffy-badger'],
309
self.assertEquals(out, '')
310
err.index('unknown command')
247
314
class OldTests(ExternalBase):
248
315
"""old tests moved from ./testbzr."""
270
336
f.write('hello world!\n')
273
out = backtick("bzr unknowns")
274
self.assertEquals(out, 'test.txt\n')
339
self.assertEquals(capture('unknowns'), 'test.txt\n')
276
out = backtick("bzr status")
341
out = capture("status")
277
342
assert out == 'unknown:\n test.txt\n'
279
out = backtick("bzr status --all")
344
out = capture("status --all")
280
345
assert out == "unknown:\n test.txt\n"
282
out = backtick("bzr status test.txt --all")
347
out = capture("status test.txt --all")
283
348
assert out == "unknown:\n test.txt\n"
285
350
f = file('test2.txt', 'wt')
286
351
f.write('goodbye cruel world...\n')
289
out = backtick("bzr status test.txt")
354
out = capture("status test.txt")
290
355
assert out == "unknown:\n test.txt\n"
292
out = backtick("bzr status")
357
out = capture("status")
293
358
assert out == ("unknown:\n"
364
429
runbzr(['commit', '-m', 'rename nested subdirectories'])
366
431
chdir('sub1/sub2')
367
self.assertEquals(backtick('bzr root')[:-1],
432
self.assertEquals(capture('root')[:-1],
368
433
os.path.join(self.test_dir, 'branch1'))
369
434
runbzr('move ../hello.txt .')
370
435
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')
436
self.assertEquals(capture('relpath hello.txt'),
437
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
438
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
373
439
runbzr(['commit', '-m', 'move to parent directory'])
375
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
441
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
377
443
runbzr('move sub2/hello.txt .')
378
444
assert exists('hello.txt')
396
462
runbzr('log -v --forward')
397
463
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
464
log_out = capture('log -m commit')
399
465
assert "this is my new commit" in log_out
400
466
assert "rename nested" not in log_out
401
467
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
468
assert 'revision-id' in capture('log --show-ids -m commit')
405
471
progress("file with spaces in name")