45
43
if isinstance(args, basestring):
46
44
args = args.split()
48
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestVersion(ExternalBase):
55
# output is intentionally passed through to stdout so that we
56
# can see the version being tested
57
self.runbzr(['version'])
61
class HelpCommands(ExternalBase):
47
return self.backtick(['python', self.BZRPATH,] + args,
50
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestCommands(ExternalBase):
55
def test_help_commands(self):
63
56
self.runbzr('--help')
64
57
self.runbzr('help')
65
58
self.runbzr('help commands')
66
59
self.runbzr('help help')
67
60
self.runbzr('commit -h')
70
class InitBranch(ExternalBase):
62
def test_init_branch(self):
73
64
self.runbzr(['init'])
77
class UserIdentity(ExternalBase):
66
def test_whoami(self):
79
67
# this should always identify something, if only "john@localhost"
80
68
self.runbzr("whoami")
81
69
self.runbzr("whoami --email")
82
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
86
class InvalidCommands(ExternalBase):
71
self.assertEquals(self.runbzr("whoami --email",
72
backtick=True).count('@'), 1)
74
def test_whoami_branch(self):
75
"""branch specific user identity works."""
77
f = file('.bzr/email', 'wt')
78
f.write('Branch Identity <branch@identi.ty>')
80
whoami = self.runbzr("whoami",backtick=True)
81
whoami_email = self.runbzr("whoami --email",backtick=True)
82
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
83
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
85
def test_invalid_commands(self):
88
86
self.runbzr("pants", retcode=1)
89
87
self.runbzr("--pants off", retcode=1)
90
88
self.runbzr("diff --message foo", retcode=1)
94
class EmptyCommit(ExternalBase):
90
def test_empty_commit(self):
96
91
self.runbzr("init")
97
92
self.build_tree(['hello.txt'])
98
93
self.runbzr("commit -m empty", retcode=1)
99
94
self.runbzr("add hello.txt")
100
95
self.runbzr("commit -m added")
104
class IgnorePatterns(ExternalBase):
97
def test_ignore_patterns(self):
106
98
from bzrlib.branch import Branch
108
100
b = Branch('.', init=True)
133
125
self.runbzr('ignore garh')
134
126
self.assertEquals(list(b.unknowns()), [])
135
127
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
129
def test_revert(self):
133
file('hello', 'wt').write('foo')
134
self.runbzr('add hello')
135
self.runbzr('commit -m setup hello')
137
file('goodbye', 'wt').write('baz')
138
self.runbzr('add goodbye')
139
self.runbzr('commit -m setup goodbye')
141
file('hello', 'wt').write('bar')
142
file('goodbye', 'wt').write('qux')
143
self.runbzr('revert hello')
144
self.check_file_contents('hello', 'foo')
145
self.check_file_contents('goodbye', 'qux')
146
self.runbzr('revert')
147
self.check_file_contents('goodbye', 'baz')
149
os.mkdir('revertdir')
150
self.runbzr('add revertdir')
151
self.runbzr('commit -m f')
152
os.rmdir('revertdir')
153
self.runbzr('revert')
155
def skipped_test_mv_modes(self):
156
"""Test two modes of operation for mv"""
157
from bzrlib.branch import Branch
158
b = Branch('.', init=True)
159
self.build_tree(['a', 'c', 'subdir/'])
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')
166
def test_main_version(self):
167
"""Check output from version command and master option is reasonable"""
168
# output is intentionally passed through to stdout so that we
169
# can see the version being tested
170
output = self.runbzr('version', backtick=1)
171
self.log('bzr version output:')
173
self.assert_(output.startswith('bzr (bazaar-ng) '))
174
self.assertNotEqual(output.index('Canonical'), -1)
175
# make sure --version is consistent
176
tmp_output = self.runbzr('--version', backtick=1)
177
self.log('bzr --version output:')
179
self.assertEquals(output, tmp_output)
181
def example_branch(test):
183
file('hello', 'wt').write('foo')
184
test.runbzr('add hello')
185
test.runbzr('commit -m setup hello')
186
file('goodbye', 'wt').write('baz')
187
test.runbzr('add goodbye')
188
test.runbzr('commit -m setup goodbye')
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')
200
def test_merge(self):
201
from bzrlib.branch import Branch
205
self.example_branch()
207
self.runbzr('branch a b')
209
file('goodbye', 'wt').write('quux')
210
self.runbzr(['commit', '-m', "more u's are always good"])
213
file('hello', 'wt').write('quuux')
214
# We can't merge when there are in-tree changes
215
self.runbzr('merge ../b', retcode=1)
216
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
217
self.runbzr('merge ../b')
218
self.check_file_contents('goodbye', 'quux')
219
# Merging a branch pulls its revision into the tree
222
a.get_revision_xml(b.last_patch())
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())
140
227
class OldTests(ExternalBase):
141
# old tests moved from ./testbzr
228
"""old tests moved from ./testbzr."""
143
231
from os import chdir, mkdir
144
232
from os.path import exists
318
assert os.path.exists('branch1')
319
assert not os.path.exists('branch2')
320
# Can't create a branch if it already exists
321
runbzr('branch branch1', retcode=1)
322
# Can't create a branch if its parent doesn't exist
323
runbzr('branch /unlikely/to/exist', retcode=1)
324
runbzr('branch branch1 branch2')
325
assert exists('branch2')
326
assert exists('branch2/sub1')
327
assert exists('branch2/sub1/hello.txt')
329
runbzr('branch --revision 0 branch1 branch3')
330
assert not exists('branch3/sub1/hello.txt')
331
runbzr('branch --revision 0..3 branch1 branch4', retcode=1)
335
runbzr('pull', retcode=1)
336
runbzr('pull ../branch2')
339
runbzr('commit --unchanged -m empty')
341
chdir('../../branch2')
343
runbzr('commit --unchanged -m empty')
345
runbzr('commit --unchanged -m empty')
346
runbzr('pull', retcode=1)
349
progress('status after remove')
350
mkdir('status-after-remove')
351
# see mail from William Dodé, 2005-05-25
352
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
353
# * looking for changes...
358
# bzr: local variable 'kind' referenced before assignment
359
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
360
# see ~/.bzr.log for debug information
361
chdir('status-after-remove')
363
file('a', 'w').write('foo')
365
runbzr(['commit', '-m', 'add a'])
373
progress("recursive and non-recursive add")
378
fp = os.path.join('foo', 'test.txt')
382
runbzr('add --no-recurse foo')
383
runbzr('file-id foo')
384
runbzr('file-id ' + fp, 1) # not versioned yet
385
runbzr('commit -m add-dir-only')
387
self.runbzr('file-id ' + fp, 1) # still not versioned
389
self.runbzr('add foo')
390
self.runbzr('file-id ' + fp)
391
self.runbzr('commit -m add-sub-file')
397
class RevertCommand(ExternalBase):
401
file('hello', 'wt').write('foo')
402
self.runbzr('add hello')
403
self.runbzr('commit -m setup hello')
405
file('hello', 'wt').write('bar')
406
self.runbzr('revert hello')
407
self.check_file_contents('hello', 'foo')