26
26
it's normally invoked.
31
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
32
from bzrlib.branch import Branch
33
from bzrlib.commands import run_bzr
36
class ExternalBase(TestCaseInTempDir):
37
def runbzr(self, args, retcode=0,backtick=False):
38
if isinstance(args, basestring):
42
return self.backtick(['python', self.BZRPATH,] + args,
45
return self.runcmd(['python', self.BZRPATH,] + args,
49
class TestCommands(ExternalBase):
51
def test_help_commands(self):
54
self.runbzr('help commands')
55
self.runbzr('help help')
56
self.runbzr('commit -h')
58
def test_init_branch(self):
61
def test_whoami(self):
62
# this should always identify something, if only "john@localhost"
64
self.runbzr("whoami --email")
66
self.assertEquals(self.runbzr("whoami --email",
67
backtick=True).count('@'), 1)
69
def test_whoami_branch(self):
70
"""branch specific user identity works."""
72
f = file('.bzr/email', 'wt')
73
f.write('Branch Identity <branch@identi.ty>')
75
whoami = self.runbzr("whoami",backtick=True)
76
whoami_email = self.runbzr("whoami --email",backtick=True)
77
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
78
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
80
def test_invalid_commands(self):
81
self.runbzr("pants", retcode=1)
82
self.runbzr("--pants off", retcode=1)
83
self.runbzr("diff --message foo", retcode=1)
85
def test_empty_commit(self):
87
self.build_tree(['hello.txt'])
88
self.runbzr("commit -m empty", retcode=1)
89
self.runbzr("add hello.txt")
90
self.runbzr("commit -m added")
92
def test_ignore_patterns(self):
93
from bzrlib.branch import Branch
95
b = Branch('.', init=True)
96
self.assertEquals(list(b.unknowns()), [])
98
file('foo.tmp', 'wt').write('tmp files are ignored')
99
self.assertEquals(list(b.unknowns()), [])
100
assert self.backtick('bzr unknowns') == ''
102
file('foo.c', 'wt').write('int main() {}')
103
self.assertEquals(list(b.unknowns()), ['foo.c'])
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
106
self.runbzr(['add', 'foo.c'])
107
assert self.backtick('bzr unknowns') == ''
109
# 'ignore' works when creating the .bzignore file
110
file('foo.blah', 'wt').write('blah')
111
self.assertEquals(list(b.unknowns()), ['foo.blah'])
112
self.runbzr('ignore *.blah')
113
self.assertEquals(list(b.unknowns()), [])
114
assert file('.bzrignore', 'rb').read() == '*.blah\n'
116
# 'ignore' works when then .bzrignore file already exists
117
file('garh', 'wt').write('garh')
118
self.assertEquals(list(b.unknowns()), ['garh'])
119
assert self.backtick('bzr unknowns') == 'garh\n'
120
self.runbzr('ignore garh')
121
self.assertEquals(list(b.unknowns()), [])
122
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
124
def test_revert(self):
128
file('hello', 'wt').write('foo')
129
self.runbzr('add hello')
130
self.runbzr('commit -m setup hello')
132
file('goodbye', 'wt').write('baz')
133
self.runbzr('add goodbye')
134
self.runbzr('commit -m setup goodbye')
136
file('hello', 'wt').write('bar')
137
file('goodbye', 'wt').write('qux')
138
self.runbzr('revert hello')
139
self.check_file_contents('hello', 'foo')
140
self.check_file_contents('goodbye', 'qux')
141
self.runbzr('revert')
142
self.check_file_contents('goodbye', 'baz')
144
os.mkdir('revertdir')
145
self.runbzr('add revertdir')
146
self.runbzr('commit -m f')
147
os.rmdir('revertdir')
148
self.runbzr('revert')
150
def skipped_test_mv_modes(self):
151
"""Test two modes of operation for mv"""
152
from bzrlib.branch import Branch
153
b = Branch('.', init=True)
154
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')
161
def test_main_version(self):
162
"""Check output from version command and master option is reasonable"""
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
34
class TestVersion(TestBase):
163
36
# output is intentionally passed through to stdout so that we
164
37
# can see the version being tested
165
output = self.runbzr('version', backtick=1)
166
self.log('bzr version output:')
168
self.assert_(output.startswith('bzr (bazaar-ng) '))
169
self.assertNotEqual(output.index('Canonical'), -1)
170
# make sure --version is consistent
171
tmp_output = self.runbzr('--version', backtick=1)
172
self.log('bzr --version output:')
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
38
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
44
self.runcmd('bzr --help')
45
self.runcmd('bzr help')
46
self.runcmd('bzr help commands')
47
self.runcmd('bzr help help')
48
self.runcmd('bzr commit -h')
51
class InitBranch(InTempDir):
202
self.example_branch()
204
self.runbzr('branch a b')
206
file('goodbye', 'wt').write('quux')
207
self.runbzr(['commit', '-m', "more u's are always good"])
210
file('hello', 'wt').write('quuux')
211
# We can't merge when there are in-tree changes
212
self.runbzr('merge ../b', retcode=1)
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
214
self.runbzr('merge ../b')
215
self.check_file_contents('goodbye', 'quux')
216
# Merging a branch pulls its revision into the tree
219
a.get_revision_xml(b.last_patch())
221
self.log('pending merges: %s', a.pending_merges())
222
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
# % (a.pending_merges(), b.last_patch())
226
def test_add_reports(self):
227
"""add command prints the names of added files."""
228
b = Branch('.', init=True)
229
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)
239
# the ordering is not defined at the moment
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
self.assertEquals(['added dir',
247
class OldTests(ExternalBase):
248
"""old tests moved from ./testbzr."""
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
60
# this should always identify something, if only "john@localhost"
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
63
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
67
class InvalidCommands(InTempDir):
69
self.runcmd("bzr pants", retcode=1)
70
self.runcmd("bzr --pants off", retcode=1)
71
self.runcmd("bzr diff --message foo", retcode=1)
75
class OldTests(InTempDir):
76
# old tests moved from ./testbzr
251
78
from os import chdir, mkdir
252
79
from os.path import exists
256
83
backtick = self.backtick
257
84
progress = self.log
259
86
progress("basic branch creation")
87
runcmd(['mkdir', 'branch1'])
264
91
self.assertEquals(backtick('bzr root').rstrip(),
265
92
os.path.join(self.test_dir, 'branch1'))
308
135
progress("command help")
311
runbzr("help commands")
312
runbzr("help slartibartfast", 1)
136
runcmd("bzr help st")
138
runcmd("bzr help commands")
139
runcmd("bzr help slartibartfast", 1)
314
141
out = backtick("bzr help ci")
315
142
out.index('aliases: ')
317
144
progress("can't rename unversioned file")
318
runbzr("rename test.txt new-test.txt", 1)
145
runcmd("bzr rename test.txt new-test.txt", 1)
320
147
progress("adding a file")
322
runbzr("add test.txt")
149
runcmd("bzr add test.txt")
323
150
assert backtick("bzr unknowns") == ''
324
151
assert backtick("bzr status --all") == ("added:\n"
327
154
progress("rename newly-added file")
328
runbzr("rename test.txt hello.txt")
155
runcmd("bzr rename test.txt hello.txt")
329
156
assert os.path.exists("hello.txt")
330
157
assert not os.path.exists("test.txt")
332
159
assert backtick("bzr revno") == '0\n'
334
161
progress("add first revision")
335
runbzr(['commit', '-m', 'add first revision'])
162
runcmd(["bzr", "commit", "-m", 'add first revision'])
337
164
progress("more complex renames")
339
runbzr("rename hello.txt sub1", 1)
340
runbzr("rename hello.txt sub1/hello.txt", 1)
341
runbzr("move hello.txt sub1", 1)
166
runcmd("bzr rename hello.txt sub1", 1)
167
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
168
runcmd("bzr move hello.txt sub1", 1)
344
runbzr("rename sub1 sub2")
345
runbzr("move hello.txt sub2")
170
runcmd("bzr add sub1")
171
runcmd("bzr rename sub1 sub2")
172
runcmd("bzr move hello.txt sub2")
346
173
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
348
175
assert exists("sub2")
350
177
assert not exists("sub1")
351
178
assert not exists("hello.txt")
353
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
180
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
357
runbzr('move sub2/hello.txt sub1')
183
runcmd('bzr add sub1')
184
runcmd('bzr move sub2/hello.txt sub1')
358
185
assert not exists('sub2/hello.txt')
359
186
assert exists('sub1/hello.txt')
360
runbzr('move sub2 sub1')
187
runcmd('bzr move sub2 sub1')
361
188
assert not exists('sub2')
362
189
assert exists('sub1/sub2')
364
runbzr(['commit', '-m', 'rename nested subdirectories'])
191
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
366
193
chdir('sub1/sub2')
367
194
self.assertEquals(backtick('bzr root')[:-1],
368
195
os.path.join(self.test_dir, 'branch1'))
369
runbzr('move ../hello.txt .')
196
runcmd('bzr move ../hello.txt .')
370
197
assert exists('./hello.txt')
371
198
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
372
199
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
373
runbzr(['commit', '-m', 'move to parent directory'])
200
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
375
202
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
377
runbzr('move sub2/hello.txt .')
204
runcmd('bzr move sub2/hello.txt .')
378
205
assert exists('hello.txt')
380
207
f = file('hello.txt', 'wt')
385
212
f.write('this is my new commit\n')
388
runbzr('commit -F msg.tmp')
215
runcmd('bzr commit -F msg.tmp')
390
217
assert backtick('bzr revno') == '5\n'
391
runbzr('export -r 5 export-5.tmp')
392
runbzr('export export.tmp')
396
runbzr('log -v --forward')
397
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
399
assert "this is my new commit" in log_out
400
assert "rename nested" not in log_out
401
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
218
runcmd('bzr export -r 5 export-5.tmp')
219
runcmd('bzr export export.tmp')
405
226
progress("file with spaces in name")
406
227
mkdir('sub directory')
407
228
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
410
runbzr('commit -m add-spaces')
414
runbzr('log --forward')
231
runcmd('bzr commit -m add-spaces')
235
runcmd('bzr log --forward')
247
# Can't create a branch if it already exists
248
runcmd('bzr branch branch1', retcode=1)
249
# Can't create a branch if its parent doesn't exist
250
runcmd('bzr branch /unlikely/to/exist', retcode=1)
251
runcmd('bzr branch branch1 branch2')
255
runcmd('bzr pull', retcode=1)
256
runcmd('bzr pull ../branch2')
259
runcmd('bzr commit -m empty')
261
chdir('../../branch2')
263
runcmd('bzr commit -m empty')
265
runcmd('bzr commit -m empty')
266
runcmd('bzr pull', retcode=1)
269
progress('status after remove')
270
mkdir('status-after-remove')
271
# see mail from William Dodé, 2005-05-25
272
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
273
# * looking for changes...
278
# bzr: local variable 'kind' referenced before assignment
279
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
280
# see ~/.bzr.log for debug information
281
chdir('status-after-remove')
283
file('a', 'w').write('foo')
285
runcmd(['bzr', 'commit', '-m', 'add a'])
286
runcmd('bzr remove a')
291
progress('ignore patterns')
292
mkdir('ignorebranch')
293
chdir('ignorebranch')
295
assert backtick('bzr unknowns') == ''
297
file('foo.tmp', 'wt').write('tmp files are ignored')
298
assert backtick('bzr unknowns') == ''
300
file('foo.c', 'wt').write('int main() {}')
301
assert backtick('bzr unknowns') == 'foo.c\n'
302
runcmd('bzr add foo.c')
303
assert backtick('bzr unknowns') == ''
305
# 'ignore' works when creating the .bzignore file
306
file('foo.blah', 'wt').write('blah')
307
assert backtick('bzr unknowns') == 'foo.blah\n'
308
runcmd('bzr ignore *.blah')
309
assert backtick('bzr unknowns') == ''
310
assert file('.bzrignore', 'rb').read() == '*.blah\n'
312
# 'ignore' works when then .bzrignore file already exists
313
file('garh', 'wt').write('garh')
314
assert backtick('bzr unknowns') == 'garh\n'
315
runcmd('bzr ignore garh')
316
assert backtick('bzr unknowns') == ''
317
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
324
progress("recursive and non-recursive add")
329
fp = os.path.join('foo', 'test.txt')
333
runcmd('bzr add --no-recurse foo')
334
runcmd('bzr file-id foo')
335
runcmd('bzr file-id ' + fp, 1) # not versioned yet
336
runcmd('bzr commit -m add-dir-only')
338
runcmd('bzr file-id ' + fp, 1) # still not versioned
340
runcmd('bzr add foo')
341
runcmd('bzr file-id ' + fp)
342
runcmd('bzr commit -m add-sub-file')
348
class RevertCommand(InTempDir):
350
self.runcmd('bzr init')
352
file('hello', 'wt').write('foo')
353
self.runcmd('bzr add hello')
354
self.runcmd('bzr commit -m setup hello')
356
file('hello', 'wt').write('bar')
357
self.runcmd('bzr revert hello')
358
self.check_file_contents('hello', 'foo')
364
# lists all tests from this module in the best order to run them. we
365
# do it this way rather than just discovering them all because it
366
# allows us to test more basic functions first where failures will be
367
# easiest to understand.
370
from unittest import TestSuite
372
s.addTests([TestVersion(),