31
31
from unittest import TestCase
32
32
from bzrlib.selftest import TestBase, InTempDir
34
class TestVersion(TestBase):
36
class ExternalBase(InTempDir):
37
def runbzr(self, args, retcode=0):
40
from subprocess import call
41
except ImportError, e:
45
if isinstance(args, basestring):
48
return self.runcmd(['python', self.BZRPATH,] + args,
53
class TestVersion(ExternalBase):
36
55
# output is intentionally passed through to stdout so that we
37
56
# can see the version being tested
38
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
57
self.runbzr(['version'])
61
class HelpCommands(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):
65
self.runbzr('help commands')
66
self.runbzr('help help')
67
self.runbzr('commit -h')
70
class InitBranch(ExternalBase):
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
77
class UserIdentity(ExternalBase):
60
79
# this should always identify something, if only "john@localhost"
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
81
self.runbzr("whoami --email")
63
82
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
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):
86
class InvalidCommands(ExternalBase):
88
self.runbzr("pants", retcode=1)
89
self.runbzr("--pants off", retcode=1)
90
self.runbzr("diff --message foo", retcode=1)
94
class EmptyCommit(ExternalBase):
97
self.build_tree(['hello.txt'])
98
self.runbzr("commit -m empty", retcode=1)
99
self.runbzr("add hello.txt")
100
self.runbzr("commit -m added")
104
class IgnorePatterns(ExternalBase):
106
from bzrlib.branch import Branch
108
b = Branch('.', init=True)
109
self.assertEquals(list(b.unknowns()), [])
111
file('foo.tmp', 'wt').write('tmp files are ignored')
112
self.assertEquals(list(b.unknowns()), [])
113
assert self.backtick('bzr unknowns') == ''
115
file('foo.c', 'wt').write('int main() {}')
116
self.assertEquals(list(b.unknowns()), ['foo.c'])
117
assert self.backtick('bzr unknowns') == 'foo.c\n'
119
self.runbzr(['add', 'foo.c'])
120
assert self.backtick('bzr unknowns') == ''
122
# 'ignore' works when creating the .bzignore file
123
file('foo.blah', 'wt').write('blah')
124
self.assertEquals(list(b.unknowns()), ['foo.blah'])
125
self.runbzr('ignore *.blah')
126
self.assertEquals(list(b.unknowns()), [])
127
assert file('.bzrignore', 'rb').read() == '*.blah\n'
129
# 'ignore' works when then .bzrignore file already exists
130
file('garh', 'wt').write('garh')
131
self.assertEquals(list(b.unknowns()), ['garh'])
132
assert self.backtick('bzr unknowns') == 'garh\n'
133
self.runbzr('ignore garh')
134
self.assertEquals(list(b.unknowns()), [])
135
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
140
class OldTests(ExternalBase):
76
141
# old tests moved from ./testbzr
77
142
def runTest(self):
78
143
from os import chdir, mkdir
79
144
from os.path import exists
83
148
backtick = self.backtick
84
149
progress = self.log
86
151
progress("basic branch creation")
87
runcmd(['mkdir', 'branch1'])
91
156
self.assertEquals(backtick('bzr root').rstrip(),
92
157
os.path.join(self.test_dir, 'branch1'))
135
200
progress("command help")
136
runcmd("bzr help st")
138
runcmd("bzr help commands")
139
runcmd("bzr help slartibartfast", 1)
203
runbzr("help commands")
204
runbzr("help slartibartfast", 1)
141
206
out = backtick("bzr help ci")
142
207
out.index('aliases: ')
144
209
progress("can't rename unversioned file")
145
runcmd("bzr rename test.txt new-test.txt", 1)
210
runbzr("rename test.txt new-test.txt", 1)
147
212
progress("adding a file")
149
runcmd("bzr add test.txt")
214
runbzr("add test.txt")
150
215
assert backtick("bzr unknowns") == ''
151
216
assert backtick("bzr status --all") == ("added:\n"
154
219
progress("rename newly-added file")
155
runcmd("bzr rename test.txt hello.txt")
220
runbzr("rename test.txt hello.txt")
156
221
assert os.path.exists("hello.txt")
157
222
assert not os.path.exists("test.txt")
159
224
assert backtick("bzr revno") == '0\n'
161
226
progress("add first revision")
162
runcmd(["bzr", "commit", "-m", 'add first revision'])
227
runbzr(['commit', '-m', 'add first revision'])
164
229
progress("more complex renames")
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)
231
runbzr("rename hello.txt sub1", 1)
232
runbzr("rename hello.txt sub1/hello.txt", 1)
233
runbzr("move hello.txt sub1", 1)
170
runcmd("bzr add sub1")
171
runcmd("bzr rename sub1 sub2")
172
runcmd("bzr move hello.txt sub2")
236
runbzr("rename sub1 sub2")
237
runbzr("move hello.txt sub2")
173
238
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
175
240
assert exists("sub2")
177
242
assert not exists("sub1")
178
243
assert not exists("hello.txt")
180
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
245
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
183
runcmd('bzr add sub1')
184
runcmd('bzr move sub2/hello.txt sub1')
249
runbzr('move sub2/hello.txt sub1')
185
250
assert not exists('sub2/hello.txt')
186
251
assert exists('sub1/hello.txt')
187
runcmd('bzr move sub2 sub1')
252
runbzr('move sub2 sub1')
188
253
assert not exists('sub2')
189
254
assert exists('sub1/sub2')
191
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
256
runbzr(['commit', '-m', 'rename nested subdirectories'])
193
258
chdir('sub1/sub2')
194
259
self.assertEquals(backtick('bzr root')[:-1],
195
260
os.path.join(self.test_dir, 'branch1'))
196
runcmd('bzr move ../hello.txt .')
261
runbzr('move ../hello.txt .')
197
262
assert exists('./hello.txt')
198
263
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
199
264
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
200
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
265
runbzr(['commit', '-m', 'move to parent directory'])
202
267
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
204
runcmd('bzr move sub2/hello.txt .')
269
runbzr('move sub2/hello.txt .')
205
270
assert exists('hello.txt')
207
272
f = file('hello.txt', 'wt')
212
277
f.write('this is my new commit\n')
215
runcmd('bzr commit -F msg.tmp')
280
runbzr('commit -F msg.tmp')
217
282
assert backtick('bzr revno') == '5\n'
218
runcmd('bzr export -r 5 export-5.tmp')
219
runcmd('bzr export export.tmp')
283
runbzr('export -r 5 export-5.tmp')
284
runbzr('export export.tmp')
288
runbzr('log -v --forward')
289
runbzr('log -m', retcode=1)
290
log_out = backtick('bzr log -m commit')
291
assert "this is my new commit" in log_out
292
assert "rename nested" not in log_out
293
assert 'revision-id' not in log_out
294
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
226
297
progress("file with spaces in name")
227
298
mkdir('sub directory')
228
299
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
231
runcmd('bzr commit -m add-spaces')
235
runcmd('bzr log --forward')
302
runbzr('commit -m add-spaces')
306
runbzr('log --forward')
246
317
progress('branch')
318
assert os.path.exists('branch1')
319
assert not os.path.exists('branch2')
247
320
# Can't create a branch if it already exists
248
runcmd('bzr branch branch1', retcode=1)
321
runbzr('branch branch1', retcode=1)
249
322
# 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')
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)
255
runcmd('bzr pull', retcode=1)
256
runcmd('bzr pull ../branch2')
335
runbzr('pull', retcode=1)
336
runbzr('pull ../branch2')
259
runcmd('bzr commit -m empty')
339
runbzr('commit --unchanged -m empty')
261
341
chdir('../../branch2')
263
runcmd('bzr commit -m empty')
343
runbzr('commit --unchanged -m empty')
264
344
chdir('../branch1')
265
runcmd('bzr commit -m empty')
266
runcmd('bzr pull', retcode=1)
345
runbzr('commit --unchanged -m empty')
346
runbzr('pull', retcode=1)
269
349
progress('status after remove')
279
359
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
280
360
# see ~/.bzr.log for debug information
281
361
chdir('status-after-remove')
283
363
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'
365
runbzr(['commit', '-m', 'add a'])
324
373
progress("recursive and non-recursive add")
325
374
mkdir('no-recurse')
326
375
chdir('no-recurse')
329
378
fp = os.path.join('foo', 'test.txt')
330
379
f = file(fp, 'w')
331
380
f.write('hello!\n')
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')
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')
348
class RevertCommand(InTempDir):
397
class RevertCommand(ExternalBase):
349
398
def runTest(self):
350
self.runcmd('bzr init')
352
401
file('hello', 'wt').write('foo')
353
self.runcmd('bzr add hello')
354
self.runcmd('bzr commit -m setup hello')
402
self.runbzr('add hello')
403
self.runbzr('commit -m setup hello')
356
405
file('hello', 'wt').write('bar')
357
self.runcmd('bzr revert hello')
406
self.runbzr('revert hello')
358
407
self.check_file_contents('hello', 'foo')
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(),