31
31
from unittest import TestCase
32
32
from bzrlib.selftest import TestBase, InTempDir
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):
34
class TestVersion(TestBase):
55
36
# output is intentionally passed through to stdout so that we
56
37
# can see the version being tested
57
self.runbzr(['version'])
61
class HelpCommands(ExternalBase):
38
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
65
self.runbzr('help commands')
66
self.runbzr('help help')
67
self.runbzr('commit -h')
70
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):
77
class UserIdentity(ExternalBase):
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
79
60
# this should always identify something, if only "john@localhost"
81
self.runbzr("whoami --email")
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
82
63
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
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):
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):
141
76
# old tests moved from ./testbzr
142
77
def runTest(self):
143
78
from os import chdir, mkdir
144
79
from os.path import exists
148
83
backtick = self.backtick
149
84
progress = self.log
151
86
progress("basic branch creation")
87
runcmd(['mkdir', 'branch1'])
156
91
self.assertEquals(backtick('bzr root').rstrip(),
157
92
os.path.join(self.test_dir, 'branch1'))
200
135
progress("command help")
203
runbzr("help commands")
204
runbzr("help slartibartfast", 1)
136
runcmd("bzr help st")
138
runcmd("bzr help commands")
139
runcmd("bzr help slartibartfast", 1)
206
141
out = backtick("bzr help ci")
207
142
out.index('aliases: ')
209
144
progress("can't rename unversioned file")
210
runbzr("rename test.txt new-test.txt", 1)
145
runcmd("bzr rename test.txt new-test.txt", 1)
212
147
progress("adding a file")
214
runbzr("add test.txt")
149
runcmd("bzr add test.txt")
215
150
assert backtick("bzr unknowns") == ''
216
151
assert backtick("bzr status --all") == ("added:\n"
219
154
progress("rename newly-added file")
220
runbzr("rename test.txt hello.txt")
155
runcmd("bzr rename test.txt hello.txt")
221
156
assert os.path.exists("hello.txt")
222
157
assert not os.path.exists("test.txt")
224
159
assert backtick("bzr revno") == '0\n'
226
161
progress("add first revision")
227
runbzr(['commit', '-m', 'add first revision'])
162
runcmd(["bzr", "commit", "-m", 'add first revision'])
229
164
progress("more complex renames")
231
runbzr("rename hello.txt sub1", 1)
232
runbzr("rename hello.txt sub1/hello.txt", 1)
233
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)
236
runbzr("rename sub1 sub2")
237
runbzr("move hello.txt sub2")
170
runcmd("bzr add sub1")
171
runcmd("bzr rename sub1 sub2")
172
runcmd("bzr move hello.txt sub2")
238
173
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
240
175
assert exists("sub2")
242
177
assert not exists("sub1")
243
178
assert not exists("hello.txt")
245
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
180
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
249
runbzr('move sub2/hello.txt sub1')
183
runcmd('bzr add sub1')
184
runcmd('bzr move sub2/hello.txt sub1')
250
185
assert not exists('sub2/hello.txt')
251
186
assert exists('sub1/hello.txt')
252
runbzr('move sub2 sub1')
187
runcmd('bzr move sub2 sub1')
253
188
assert not exists('sub2')
254
189
assert exists('sub1/sub2')
256
runbzr(['commit', '-m', 'rename nested subdirectories'])
191
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
258
193
chdir('sub1/sub2')
259
194
self.assertEquals(backtick('bzr root')[:-1],
260
195
os.path.join(self.test_dir, 'branch1'))
261
runbzr('move ../hello.txt .')
196
runcmd('bzr move ../hello.txt .')
262
197
assert exists('./hello.txt')
263
198
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
264
199
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
265
runbzr(['commit', '-m', 'move to parent directory'])
200
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
267
202
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
269
runbzr('move sub2/hello.txt .')
204
runcmd('bzr move sub2/hello.txt .')
270
205
assert exists('hello.txt')
272
207
f = file('hello.txt', 'wt')
277
212
f.write('this is my new commit\n')
280
runbzr('commit -F msg.tmp')
215
runcmd('bzr commit -F msg.tmp')
282
217
assert backtick('bzr revno') == '5\n'
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')
218
runcmd('bzr export -r 5 export-5.tmp')
219
runcmd('bzr export export.tmp')
297
226
progress("file with spaces in name")
298
227
mkdir('sub directory')
299
228
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
302
runbzr('commit -m add-spaces')
306
runbzr('log --forward')
231
runcmd('bzr commit -m add-spaces')
235
runcmd('bzr log --forward')
317
246
progress('branch')
318
assert os.path.exists('branch1')
319
assert not os.path.exists('branch2')
320
247
# Can't create a branch if it already exists
321
runbzr('branch branch1', retcode=1)
248
runcmd('bzr branch branch1', retcode=1)
322
249
# Can't create a branch if its parent doesn't exist
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)
250
runcmd('bzr branch /unlikely/to/exist', retcode=1)
251
runcmd('bzr branch branch1 branch2')
335
runbzr('pull', retcode=1)
336
runbzr('pull ../branch2')
255
runcmd('bzr pull', retcode=1)
256
runcmd('bzr pull ../branch2')
339
runbzr('commit --unchanged -m empty')
259
runcmd('bzr commit -m empty')
341
261
chdir('../../branch2')
343
runbzr('commit --unchanged -m empty')
263
runcmd('bzr commit -m empty')
344
264
chdir('../branch1')
345
runbzr('commit --unchanged -m empty')
346
runbzr('pull', retcode=1)
265
runcmd('bzr commit -m empty')
266
runcmd('bzr pull', retcode=1)
349
269
progress('status after remove')
359
279
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
360
280
# see ~/.bzr.log for debug information
361
281
chdir('status-after-remove')
363
283
file('a', 'w').write('foo')
365
runbzr(['commit', '-m', 'add a'])
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'
373
324
progress("recursive and non-recursive add")
374
325
mkdir('no-recurse')
375
326
chdir('no-recurse')
378
329
fp = os.path.join('foo', 'test.txt')
379
330
f = file(fp, 'w')
380
331
f.write('hello!\n')
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')
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')
397
class RevertCommand(ExternalBase):
401
file('hello', 'wt').write('foo')
402
self.runbzr('add hello')
403
self.runbzr('commit -m setup hello')
405
file('hello', 'wt').write('bar')
406
self.runbzr('revert hello')
407
self.check_file_contents('hello', 'foo')
352
# lists all tests from this module in the best order to run them. we
353
# do it this way rather than just discovering them all because it
354
# allows us to test more basic functions first where failures will be
355
# easiest to understand.
358
from unittest import TestSuite
360
s.addTests([TestVersion(),