22
23
This always runs bzr as an external process to try to catch bugs
23
24
related to argument processing, startup, etc.
28
testbzr [-p PYTHON] [BZR]
30
By default this tests the copy of bzr found in the same directory as
31
testbzr, or the first one found on the $PATH. A copy of bzr may be
32
given on the command line to override this, for example when applying
33
a new test suite to an old copy of bzr or vice versa.
35
testbzr normally invokes bzr using the same version of python as it
36
would normally use to run -- that is, the system default python,
37
unless that is older than 2.3. The -p option allows specification of
38
a different Python interpreter, such as when testing that bzr still
25
41
This replaces the previous test.sh which was not very portable."""
27
43
import sys, os, traceback
49
67
if isinstance(cmd, basestring):
50
logfile.write('$ %s\n' % cmd)
53
logfile.write('$ %r\n' % cmd)
55
70
if cmd[0] == 'bzr':
73
cmd.insert(0, OVERRIDE_PYTHON)
75
logfile.write('$ %r\n' % cmd)
118
137
if os.path.exists(TESTDIR):
119
138
shutil.rmtree(TESTDIR)
140
start_dir = os.getcwd()
122
143
logfile = open(LOGFILENAME, 'wt', buffering=1)
147
from getopt import getopt
148
opts, args = getopt(sys.argv[1:], 'p:')
150
for option, value in opts:
152
OVERRIDE_PYTHON = value
126
155
mypath = os.path.abspath(sys.argv[0])
127
156
print '%-30s %s' % ('running tests from', mypath)
131
if len(sys.argv) > 1:
132
BZRPATH = sys.argv[1]
134
163
BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
136
165
print '%-30s %s' % ('against bzr', BZRPATH)
137
166
print '%-30s %s' % ('in directory', os.getcwd())
167
print '%-30s %s' % ('with python', (OVERRIDE_PYTHON or '(default)'))
139
169
print backtick([BZRPATH, 'version'])
179
209
assert out == 'test.txt\n'
181
211
out = backtick("bzr status")
182
assert out == '''? test.txt\n'''
212
assert out == 'unknown:\n test.txt\n'
184
214
out = backtick("bzr status --all")
185
assert out == "? test.txt\n"
215
assert out == "unknown:\n test.txt\n"
187
217
out = backtick("bzr status test.txt --all")
188
assert out == "? test.txt\n"
218
assert out == "unknown:\n test.txt\n"
190
220
f = file('test2.txt', 'wt')
191
221
f.write('goodbye cruel world...\n')
194
224
out = backtick("bzr status test.txt")
195
assert out == "? test.txt\n"
225
assert out == "unknown:\n test.txt\n"
197
227
out = backtick("bzr status")
198
assert out == "? test.txt\n" \
228
assert out == ("unknown:\n"
201
232
os.unlink('test2.txt')
203
234
progress("command aliases")
204
235
out = backtick("bzr st --all")
205
assert out == "? test.txt\n"
236
assert out == ("unknown:\n"
206
239
out = backtick("bzr stat")
207
assert out == "? test.txt\n"
240
assert out == ("unknown:\n"
209
243
progress("command help")
210
244
runcmd("bzr help st")
223
257
runcmd("bzr add test.txt")
224
258
assert backtick("bzr unknowns") == ''
225
assert backtick("bzr status --all") == "A test.txt\n"
259
assert backtick("bzr status --all") == ("added:\n"
227
262
progress("rename newly-added file")
228
263
runcmd("bzr rename test.txt hello.txt")
243
278
runcmd("bzr add sub1")
244
279
runcmd("bzr rename sub1 sub2")
245
280
runcmd("bzr move hello.txt sub2")
246
assert backtick("bzr relpath sub2/hello.txt") == "sub2/hello.txt\n"
281
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
248
283
assert exists("sub2")
249
284
assert exists("sub2/hello.txt")
267
302
assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
268
303
runcmd('bzr move ../hello.txt .')
269
304
assert exists('./hello.txt')
270
assert backtick('bzr relpath hello.txt') == 'sub1/sub2/hello.txt\n'
271
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
305
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
306
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
272
307
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
274
assert backtick('bzr relpath sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
309
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
276
311
runcmd('bzr move sub2/hello.txt .')
277
312
assert exists('hello.txt')
293
328
runcmd('bzr log')
294
329
runcmd('bzr log -v')
333
progress("file with spaces in name")
334
mkdir('sub directory')
335
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
338
runcmd('bzr commit -m add-spaces')
342
runcmd('bzr log --forward')
354
progress('status after remove')
355
mkdir('status-after-remove')
356
# see mail from William Dodé, 2005-05-25
357
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
358
# * looking for changes...
363
# bzr: local variable 'kind' referenced before assignment
364
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
365
# see ~/.bzr.log for debug information
366
cd('status-after-remove')
368
file('a', 'w').write('foo')
370
runcmd(['bzr', 'commit', '-m', 'add a'])
371
runcmd('bzr remove a')
299
376
progress('ignore patterns')
310
387
runcmd('bzr add foo.c')
311
388
assert backtick('bzr unknowns') == ''
390
# 'ignore' works when creating the .bzignore file
313
391
file('foo.blah', 'wt').write('blah')
314
392
assert backtick('bzr unknowns') == 'foo.blah\n'
315
393
runcmd('bzr ignore *.blah')
316
394
assert backtick('bzr unknowns') == ''
317
assert file('.bzrignore', 'rt').read() == '*.blah\n'
395
assert file('.bzrignore', 'rb').read() == '*.blah\n'
397
# 'ignore' works when then .bzrignore file already exists
398
file('garh', 'wt').write('garh')
399
assert backtick('bzr unknowns') == 'garh\n'
400
runcmd('bzr ignore garh')
401
assert backtick('bzr unknowns') == ''
402
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
409
progress("recursive and non-recursive add")
414
fp = os.path.join('foo', 'test.txt')
418
runcmd('bzr add --no-recurse foo')
419
runcmd('bzr file-id foo')
420
runcmd('bzr file-id ' + fp, 1) # not versioned yet
421
runcmd('bzr commit -m add-dir-only')
423
runcmd('bzr file-id ' + fp, 1) # still not versioned
425
runcmd('bzr add foo')
426
runcmd('bzr file-id ' + fp)
427
runcmd('bzr commit -m add-sub-file')
320
434
progress("all tests passed!")
325
439
+ '*' * 50 + '\n')
326
440
logfile.write('tests failed!\n')
327
441
traceback.print_exc(None, logfile)
444
sys.stdout.writelines(file(os.path.join(start_dir, LOGFILENAME), 'rt').readlines()[-50:])