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:
30
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
32
class ExternalBase(TestCaseInTempDir):
33
def runbzr(self, args, retcode=0,backtick=False):
44
34
if isinstance(args, basestring):
45
35
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):
38
return self.backtick(['python', self.BZRPATH,] + args,
41
return self.runcmd(['python', self.BZRPATH,] + args,
45
class TestCommands(ExternalBase):
47
def test_help_commands(self):
105
48
self.runbzr('--help')
106
49
self.runbzr('help')
107
50
self.runbzr('help commands')
108
51
self.runbzr('help help')
109
52
self.runbzr('commit -h')
112
class InitBranch(ExternalBase):
54
def test_init_branch(self):
115
55
self.runbzr(['init'])
119
class UserIdentity(ExternalBase):
57
def test_whoami(self):
121
58
# this should always identify something, if only "john@localhost"
122
59
self.runbzr("whoami")
123
60
self.runbzr("whoami --email")
124
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
128
class InvalidCommands(ExternalBase):
62
self.assertEquals(self.runbzr("whoami --email",
63
backtick=True).count('@'), 1)
65
def test_whoami_branch(self):
66
"""branch specific user identity works."""
68
f = file('.bzr/email', 'wt')
69
f.write('Branch Identity <branch@identi.ty>')
71
whoami = self.runbzr("whoami",backtick=True)
72
whoami_email = self.runbzr("whoami --email",backtick=True)
73
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
74
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
76
def test_invalid_commands(self):
130
77
self.runbzr("pants", retcode=1)
131
78
self.runbzr("--pants off", retcode=1)
132
79
self.runbzr("diff --message foo", retcode=1)
136
class EmptyCommit(ExternalBase):
81
def test_empty_commit(self):
138
82
self.runbzr("init")
139
83
self.build_tree(['hello.txt'])
140
84
self.runbzr("commit -m empty", retcode=1)
141
85
self.runbzr("add hello.txt")
142
86
self.runbzr("commit -m added")
146
class IgnorePatterns(ExternalBase):
88
def test_ignore_patterns(self):
148
89
from bzrlib.branch import Branch
150
91
b = Branch('.', init=True)
175
116
self.runbzr('ignore garh')
176
117
self.assertEquals(list(b.unknowns()), [])
177
118
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
120
def test_revert(self):
124
file('hello', 'wt').write('foo')
125
self.runbzr('add hello')
126
self.runbzr('commit -m setup hello')
128
file('goodbye', 'wt').write('baz')
129
self.runbzr('add goodbye')
130
self.runbzr('commit -m setup goodbye')
132
file('hello', 'wt').write('bar')
133
file('goodbye', 'wt').write('qux')
134
self.runbzr('revert hello')
135
self.check_file_contents('hello', 'foo')
136
self.check_file_contents('goodbye', 'qux')
137
self.runbzr('revert')
138
self.check_file_contents('goodbye', 'baz')
140
os.mkdir('revertdir')
141
self.runbzr('add revertdir')
142
self.runbzr('commit -m f')
143
os.rmdir('revertdir')
144
self.runbzr('revert')
146
def skipped_test_mv_modes(self):
147
"""Test two modes of operation for mv"""
148
from bzrlib.branch import Branch
149
b = Branch('.', init=True)
150
self.build_tree(['a', 'c', 'subdir/'])
151
self.run_bzr('mv', 'a', 'b')
152
self.run_bzr('mv', 'b', 'subdir')
153
self.run_bzr('mv', 'subdir/b', 'a')
154
self.run_bzr('mv', 'a', 'b', 'subdir')
155
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
157
def test_main_version(self):
158
"""Check output from version command and master option is reasonable"""
159
# output is intentionally passed through to stdout so that we
160
# can see the version being tested
161
output = self.runbzr('version', backtick=1)
162
self.log('bzr version output:')
164
self.assert_(output.startswith('bzr (bazaar-ng) '))
165
self.assertNotEqual(output.index('Canonical'), -1)
166
# make sure --version is consistent
167
tmp_output = self.runbzr('--version', backtick=1)
168
self.log('bzr --version output:')
170
self.assertEquals(output, tmp_output)
172
def example_branch(test):
174
file('hello', 'wt').write('foo')
175
test.runbzr('add hello')
176
test.runbzr('commit -m setup hello')
177
file('goodbye', 'wt').write('baz')
178
test.runbzr('add goodbye')
179
test.runbzr('commit -m setup goodbye')
181
def test_revert(self):
182
self.example_branch()
183
file('hello', 'wt').write('bar')
184
file('goodbye', 'wt').write('qux')
185
self.runbzr('revert hello')
186
self.check_file_contents('hello', 'foo')
187
self.check_file_contents('goodbye', 'qux')
188
self.runbzr('revert')
189
self.check_file_contents('goodbye', 'baz')
191
def test_merge(self):
192
from bzrlib.branch import Branch
198
self.example_branch()
200
self.runbzr('branch a b')
202
file('goodbye', 'wt').write('quux')
203
self.runbzr(['commit', '-m', "more u's are always good"])
206
file('hello', 'wt').write('quuux')
207
# We can't merge when there are in-tree changes
208
self.runbzr('merge ../b', retcode=1)
209
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
210
self.runbzr('merge ../b')
211
self.check_file_contents('goodbye', 'quux')
212
# Merging a branch pulls its revision into the tree
215
a.get_revision_xml(b.last_patch())
217
self.log('pending merges: %s', a.pending_merges())
218
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
219
# % (a.pending_merges(), b.last_patch())
182
221
class OldTests(ExternalBase):
183
# old tests moved from ./testbzr
222
"""old tests moved from ./testbzr."""
185
225
from os import chdir, mkdir
186
226
from os.path import exists