32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
33
from bzrlib.branch import Branch
34
from bzrlib.commands import run_bzr
37
class ExternalBase(TestCaseInTempDir):
38
def runbzr(self, args, retcode=0,backtick=False):
31
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
35
class ExternalBase(InTempDir):
36
def runbzr(self, args, retcode=0):
39
from subprocess import call
40
except ImportError, e:
39
44
if isinstance(args, basestring):
40
45
args = args.split()
43
return self.backtick(['python', self.BZRPATH,] + args,
46
return self.runcmd(['python', self.BZRPATH,] + args,
50
class TestCommands(ExternalBase):
52
def test_help_commands(self):
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):
53
105
self.runbzr('--help')
54
106
self.runbzr('help')
55
107
self.runbzr('help commands')
56
108
self.runbzr('help help')
57
109
self.runbzr('commit -h')
59
def test_init_branch(self):
112
class InitBranch(ExternalBase):
60
115
self.runbzr(['init'])
62
def test_whoami(self):
119
class UserIdentity(ExternalBase):
63
121
# this should always identify something, if only "john@localhost"
64
122
self.runbzr("whoami")
65
123
self.runbzr("whoami --email")
67
self.assertEquals(self.runbzr("whoami --email",
68
backtick=True).count('@'), 1)
70
def test_whoami_branch(self):
71
"""branch specific user identity works."""
73
f = file('.bzr/email', 'wt')
74
f.write('Branch Identity <branch@identi.ty>')
76
whoami = self.runbzr("whoami",backtick=True)
77
whoami_email = self.runbzr("whoami --email",backtick=True)
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
79
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
81
def test_invalid_commands(self):
124
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
128
class InvalidCommands(ExternalBase):
82
130
self.runbzr("pants", retcode=1)
83
131
self.runbzr("--pants off", retcode=1)
84
132
self.runbzr("diff --message foo", retcode=1)
86
def test_empty_commit(self):
136
class EmptyCommit(ExternalBase):
87
138
self.runbzr("init")
88
139
self.build_tree(['hello.txt'])
89
140
self.runbzr("commit -m empty", retcode=1)
90
141
self.runbzr("add hello.txt")
91
142
self.runbzr("commit -m added")
93
def test_ignore_patterns(self):
146
class IgnorePatterns(ExternalBase):
94
148
from bzrlib.branch import Branch
96
150
b = Branch('.', init=True)
121
175
self.runbzr('ignore garh')
122
176
self.assertEquals(list(b.unknowns()), [])
123
177
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
125
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"""
163
# output is intentionally passed through to stdout so that we
164
# 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
201
self.example_branch()
203
self.runbzr('branch a b')
205
file('goodbye', 'wt').write('quux')
206
self.runbzr(['commit', '-m', "more u's are always good"])
209
file('hello', 'wt').write('quuux')
210
# We can't merge when there are in-tree changes
211
self.runbzr('merge ../b', retcode=1)
212
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
213
self.runbzr('merge ../b')
214
self.check_file_contents('goodbye', 'quux')
215
# Merging a branch pulls its revision into the tree
218
a.get_revision_xml(b.last_patch())
220
self.log('pending merges: %s', a.pending_merges())
221
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
# % (a.pending_merges(), b.last_patch())
225
"""Pull changes from one branch to another."""
229
self.example_branch()
230
self.runbzr('pull', retcode=1)
231
self.runbzr('missing', retcode=1)
232
self.runbzr('missing .')
233
self.runbzr('missing')
235
self.runbzr('pull /', retcode=1)
239
self.runbzr('branch a b')
242
self.runbzr('commit -m blah --unchanged')
246
assert a.revision_history() == b.revision_history()[:-1]
247
self.runbzr('pull ../b')
248
assert a.revision_history() == b.revision_history()
249
self.runbzr('commit -m blah2 --unchanged')
251
self.runbzr('commit -m blah3 --unchanged')
252
self.runbzr('pull ../a', retcode=1)
254
self.runbzr('merge ../b')
255
self.runbzr('commit -m blah4 --unchanged')
257
self.runbzr('pull ../a')
258
assert a.revision_history()[-1] == b.revision_history()[-1]
261
def test_add_reports(self):
262
"""add command prints the names of added files."""
263
b = Branch('.', init=True)
264
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
266
from cStringIO import StringIO
269
ret = self.apply_redirected(None, out, None,
272
self.assertEquals(ret, 0)
274
# the ordering is not defined at the moment
275
results = sorted(out.getvalue().rstrip('\n').split('\n'))
276
self.assertEquals(['added dir',
282
182
class OldTests(ExternalBase):
283
"""old tests moved from ./testbzr."""
183
# old tests moved from ./testbzr
286
185
from os import chdir, mkdir
287
186
from os.path import exists
289
189
runbzr = self.runbzr
290
190
backtick = self.backtick