26
26
it's normally invoked.
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:
44
if isinstance(args, basestring):
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"""
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
34
class TestVersion(TestBase):
68
36
# output is intentionally passed through to stdout so that we
69
37
# 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
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
104
43
def runTest(self):
105
self.runbzr('--help')
107
self.runbzr('help commands')
108
self.runbzr('help help')
109
self.runbzr('commit -h')
112
class InitBranch(ExternalBase):
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):
113
52
def runTest(self):
115
self.runbzr(['init'])
119
class UserIdentity(ExternalBase):
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
120
59
def runTest(self):
121
60
# this should always identify something, if only "john@localhost"
122
self.runbzr("whoami")
123
self.runbzr("whoami --email")
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
124
63
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
128
class InvalidCommands(ExternalBase):
130
self.runbzr("pants", retcode=1)
131
self.runbzr("--pants off", retcode=1)
132
self.runbzr("diff --message foo", retcode=1)
136
class EmptyCommit(ExternalBase):
139
self.build_tree(['hello.txt'])
140
self.runbzr("commit -m empty", retcode=1)
141
self.runbzr("add hello.txt")
142
self.runbzr("commit -m added")
146
class IgnorePatterns(ExternalBase):
148
from bzrlib.branch import Branch
150
b = Branch('.', init=True)
151
self.assertEquals(list(b.unknowns()), [])
153
file('foo.tmp', 'wt').write('tmp files are ignored')
154
self.assertEquals(list(b.unknowns()), [])
155
assert self.backtick('bzr unknowns') == ''
157
file('foo.c', 'wt').write('int main() {}')
158
self.assertEquals(list(b.unknowns()), ['foo.c'])
159
assert self.backtick('bzr unknowns') == 'foo.c\n'
161
self.runbzr(['add', 'foo.c'])
162
assert self.backtick('bzr unknowns') == ''
164
# 'ignore' works when creating the .bzignore file
165
file('foo.blah', 'wt').write('blah')
166
self.assertEquals(list(b.unknowns()), ['foo.blah'])
167
self.runbzr('ignore *.blah')
168
self.assertEquals(list(b.unknowns()), [])
169
assert file('.bzrignore', 'rb').read() == '*.blah\n'
171
# 'ignore' works when then .bzrignore file already exists
172
file('garh', 'wt').write('garh')
173
self.assertEquals(list(b.unknowns()), ['garh'])
174
assert self.backtick('bzr unknowns') == 'garh\n'
175
self.runbzr('ignore garh')
176
self.assertEquals(list(b.unknowns()), [])
177
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
182
class OldTests(ExternalBase):
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):
183
76
# old tests moved from ./testbzr
184
77
def runTest(self):
185
78
from os import chdir, mkdir
186
79
from os.path import exists
190
83
backtick = self.backtick
191
84
progress = self.log
193
86
progress("basic branch creation")
87
runcmd(['mkdir', 'branch1'])
198
91
self.assertEquals(backtick('bzr root').rstrip(),
199
92
os.path.join(self.test_dir, 'branch1'))
242
135
progress("command help")
245
runbzr("help commands")
246
runbzr("help slartibartfast", 1)
136
runcmd("bzr help st")
138
runcmd("bzr help commands")
139
runcmd("bzr help slartibartfast", 1)
248
141
out = backtick("bzr help ci")
249
142
out.index('aliases: ')
251
144
progress("can't rename unversioned file")
252
runbzr("rename test.txt new-test.txt", 1)
145
runcmd("bzr rename test.txt new-test.txt", 1)
254
147
progress("adding a file")
256
runbzr("add test.txt")
149
runcmd("bzr add test.txt")
257
150
assert backtick("bzr unknowns") == ''
258
151
assert backtick("bzr status --all") == ("added:\n"
261
154
progress("rename newly-added file")
262
runbzr("rename test.txt hello.txt")
155
runcmd("bzr rename test.txt hello.txt")
263
156
assert os.path.exists("hello.txt")
264
157
assert not os.path.exists("test.txt")
266
159
assert backtick("bzr revno") == '0\n'
268
161
progress("add first revision")
269
runbzr(['commit', '-m', 'add first revision'])
162
runcmd(["bzr", "commit", "-m", 'add first revision'])
271
164
progress("more complex renames")
273
runbzr("rename hello.txt sub1", 1)
274
runbzr("rename hello.txt sub1/hello.txt", 1)
275
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)
278
runbzr("rename sub1 sub2")
279
runbzr("move hello.txt sub2")
170
runcmd("bzr add sub1")
171
runcmd("bzr rename sub1 sub2")
172
runcmd("bzr move hello.txt sub2")
280
173
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
282
175
assert exists("sub2")
284
177
assert not exists("sub1")
285
178
assert not exists("hello.txt")
287
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
180
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
291
runbzr('move sub2/hello.txt sub1')
183
runcmd('bzr add sub1')
184
runcmd('bzr move sub2/hello.txt sub1')
292
185
assert not exists('sub2/hello.txt')
293
186
assert exists('sub1/hello.txt')
294
runbzr('move sub2 sub1')
187
runcmd('bzr move sub2 sub1')
295
188
assert not exists('sub2')
296
189
assert exists('sub1/sub2')
298
runbzr(['commit', '-m', 'rename nested subdirectories'])
191
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
300
193
chdir('sub1/sub2')
301
194
self.assertEquals(backtick('bzr root')[:-1],
302
195
os.path.join(self.test_dir, 'branch1'))
303
runbzr('move ../hello.txt .')
196
runcmd('bzr move ../hello.txt .')
304
197
assert exists('./hello.txt')
305
198
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
306
199
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
307
runbzr(['commit', '-m', 'move to parent directory'])
200
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
309
202
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
311
runbzr('move sub2/hello.txt .')
204
runcmd('bzr move sub2/hello.txt .')
312
205
assert exists('hello.txt')
314
207
f = file('hello.txt', 'wt')
319
212
f.write('this is my new commit\n')
322
runbzr('commit -F msg.tmp')
215
runcmd('bzr commit -F msg.tmp')
324
217
assert backtick('bzr revno') == '5\n'
325
runbzr('export -r 5 export-5.tmp')
326
runbzr('export export.tmp')
330
runbzr('log -v --forward')
331
runbzr('log -m', retcode=1)
332
log_out = backtick('bzr log -m commit')
333
assert "this is my new commit" in log_out
334
assert "rename nested" not in log_out
335
assert 'revision-id' not in log_out
336
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')
339
226
progress("file with spaces in name")
340
227
mkdir('sub directory')
341
228
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
344
runbzr('commit -m add-spaces')
348
runbzr('log --forward')
357
class RevertCommand(ExternalBase):
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):
358
349
def runTest(self):
350
self.runcmd('bzr init')
361
352
file('hello', 'wt').write('foo')
362
self.runbzr('add hello')
363
self.runbzr('commit -m setup hello')
365
file('goodbye', 'wt').write('baz')
366
self.runbzr('add goodbye')
367
self.runbzr('commit -m setup goodbye')
353
self.runcmd('bzr add hello')
354
self.runcmd('bzr commit -m setup hello')
369
356
file('hello', 'wt').write('bar')
370
file('goodbye', 'wt').write('qux')
371
self.runbzr('revert hello')
357
self.runcmd('bzr revert hello')
372
358
self.check_file_contents('hello', 'foo')
373
self.check_file_contents('goodbye', 'qux')
374
self.runbzr('revert')
375
self.check_file_contents('goodbye', 'baz')
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(),