44
43
if isinstance(args, basestring):
45
44
args = args.split()
47
return self.runcmd(['python', self.BZRPATH,] + args,
52
class MvCommand(BzrTestBase):
54
"""Test two modes of operation for mv"""
55
b = Branch('.', init=True)
56
self.build_tree(['a', 'c', 'subdir/'])
57
self.run_bzr('mv', 'a', 'b')
58
self.run_bzr('mv', 'b', 'subdir')
59
self.run_bzr('mv', 'subdir/b', 'a')
60
self.run_bzr('mv', 'a', 'b', 'subdir')
61
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
65
class TestVersion(BzrTestBase):
66
"""Check output from version command and master option is reasonable"""
68
# output is intentionally passed through to stdout so that we
69
# can see the version being tested
70
from cStringIO import StringIO
73
sys.stdout = tmp_out = StringIO()
75
self.run_bzr('version')
79
output = tmp_out.getvalue()
80
self.log('bzr version output:')
83
self.assert_(output.startswith('bzr (bazaar-ng) '))
84
self.assertNotEqual(output.index('Canonical'), -1)
86
# make sure --version is consistent
88
sys.stdout = tmp_out = StringIO()
90
self.run_bzr('--version')
94
self.log('bzr --version output:')
95
self.log(tmp_out.getvalue())
97
self.assertEquals(output, tmp_out.getvalue())
103
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):
105
56
self.runbzr('--help')
106
57
self.runbzr('help')
107
58
self.runbzr('help commands')
108
59
self.runbzr('help help')
109
60
self.runbzr('commit -h')
112
class InitBranch(ExternalBase):
62
def test_init_branch(self):
115
64
self.runbzr(['init'])
119
class UserIdentity(ExternalBase):
66
def test_whoami(self):
121
67
# this should always identify something, if only "john@localhost"
122
68
self.runbzr("whoami")
123
69
self.runbzr("whoami --email")
124
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
128
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):
130
86
self.runbzr("pants", retcode=1)
131
87
self.runbzr("--pants off", retcode=1)
132
88
self.runbzr("diff --message foo", retcode=1)
136
class EmptyCommit(ExternalBase):
90
def test_empty_commit(self):
138
91
self.runbzr("init")
139
92
self.build_tree(['hello.txt'])
140
93
self.runbzr("commit -m empty", retcode=1)
141
94
self.runbzr("add hello.txt")
142
95
self.runbzr("commit -m added")
146
class IgnorePatterns(ExternalBase):
97
def test_ignore_patterns(self):
148
98
from bzrlib.branch import Branch
150
100
b = Branch('.', init=True)
175
125
self.runbzr('ignore garh')
176
126
self.assertEquals(list(b.unknowns()), [])
177
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())
182
227
class OldTests(ExternalBase):
183
# old tests moved from ./testbzr
228
"""old tests moved from ./testbzr."""
185
231
from os import chdir, mkdir
186
232
from os.path import exists
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
assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
404
% (a.pending_merges(), b.last_patch())
405
self.runbzr('revert hello')
406
assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
407
% (a.pending_merges(), b.last_patch())
408
self.runbzr('revert')
409
assert a.pending_merges() == [], "Assertion %s %s" \
410
% (a.pending_merges(), b.last_patch())
411
self.runbzr('merge ../b -r2..3')
412
assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
413
% (a.pending_merges(), b.last_patch())
414
self.runbzr('revert')
415
self.runbzr('merge ../b -r3..3')
416
assert a.pending_merges() == [], "Assertion %s %s" \
417
% (a.pending_merges(), b.last_patch())
418
os.mkdir('revertdir')
419
self.runbzr('add revertdir')
420
self.runbzr('commit -m f')
421
os.rmdir('revertdir')
422
self.runbzr('revert')