22
22
This always runs bzr as an external process to try to catch bugs
23
23
related to argument processing, startup, etc.
27
testbzr [-p PYTHON] [BZR]
29
By default this tests the copy of bzr found in the same directory as
30
testbzr, or the first one found on the $PATH. A copy of bzr may be
31
given on the command line to override this, for example when applying
32
a new test suite to an old copy of bzr or vice versa.
34
testbzr normally invokes bzr using the same version of python as it
35
would normally use to run -- that is, the system default python,
36
unless that is older than 2.3. The -p option allows specification of
37
a different Python interpreter, such as when testing that bzr still
25
40
This replaces the previous test.sh which was not very portable."""
27
42
import sys, os, traceback
44
from os.path import exists
46
TESTDIR = "testbzr.tmp"
48
OVERRIDE_PYTHON = None
50
LOGFILENAME = 'testbzr.log'
104
131
logfile.write(' at %s:%d\n' % stack[:2])
107
TESTDIR = "testbzr.tmp"
109
135
# prepare an empty scratch directory
110
136
if os.path.exists(TESTDIR):
111
137
shutil.rmtree(TESTDIR)
114
logfile = open('testbzr.log', 'wt', buffering=1)
139
start_dir = os.getcwd()
142
logfile = open(LOGFILENAME, 'wt', buffering=1)
146
from getopt import getopt
147
opts, args = getopt(sys.argv[1:], 'p:')
149
for option, value in opts:
151
OVERRIDE_PYTHON = value
154
mypath = os.path.abspath(sys.argv[0])
155
print '%-30s %s' % ('running tests from', mypath)
162
BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
164
print '%-30s %s' % ('against bzr', BZRPATH)
165
print '%-30s %s' % ('in directory', os.getcwd())
166
print '%-30s %s' % ('with python', (OVERRIDE_PYTHON or '(default)'))
168
print backtick([BZRPATH, 'version'])
118
170
runcmd(['mkdir', TESTDIR])
172
test_root = os.getcwd()
121
174
progress("introductory commands")
122
175
runcmd("bzr version")
176
runcmd("bzr --version")
123
177
runcmd("bzr help")
124
178
runcmd("bzr --help")
180
progress("internal tests")
181
runcmd("bzr selftest")
126
183
progress("user identity")
127
184
# this should always identify something, if only "john@localhost"
128
185
runcmd("bzr whoami")
148
208
assert out == 'test.txt\n'
150
210
out = backtick("bzr status")
151
assert out == '''? test.txt\n'''
211
assert out == 'unknown:\n test.txt\n'
153
213
out = backtick("bzr status --all")
154
assert out == "? test.txt\n"
214
assert out == "unknown:\n test.txt\n"
216
out = backtick("bzr status test.txt --all")
217
assert out == "unknown:\n test.txt\n"
219
f = file('test2.txt', 'wt')
220
f.write('goodbye cruel world...\n')
223
out = backtick("bzr status test.txt")
224
assert out == "unknown:\n test.txt\n"
226
out = backtick("bzr status")
227
assert out == ("unknown:\n"
231
os.unlink('test2.txt')
233
progress("command aliases")
234
out = backtick("bzr st --all")
235
assert out == ("unknown:\n"
238
out = backtick("bzr stat")
239
assert out == ("unknown:\n"
242
progress("command help")
243
runcmd("bzr help st")
245
runcmd("bzr help commands")
246
runcmd("bzr help slartibartfast", 1)
248
out = backtick("bzr help ci")
249
out.index('aliases: ')
156
251
progress("can't rename unversioned file")
157
252
runcmd("bzr rename test.txt new-test.txt", 1)
170
266
assert backtick("bzr revno") == '0\n'
268
progress("add first revision")
269
runcmd(["bzr", "commit", "-m", 'add first revision'])
271
progress("more complex renames")
273
runcmd("bzr rename hello.txt sub1", 1)
274
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
275
runcmd("bzr move hello.txt sub1", 1)
277
runcmd("bzr add sub1")
278
runcmd("bzr rename sub1 sub2")
279
runcmd("bzr move hello.txt sub2")
280
assert backtick("bzr relpath sub2/hello.txt") == "sub2/hello.txt\n"
282
assert exists("sub2")
283
assert exists("sub2/hello.txt")
284
assert not exists("sub1")
285
assert not exists("hello.txt")
287
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
290
runcmd('bzr add sub1')
291
runcmd('bzr move sub2/hello.txt sub1')
292
assert not exists('sub2/hello.txt')
293
assert exists('sub1/hello.txt')
294
runcmd('bzr move sub2 sub1')
295
assert not exists('sub2')
296
assert exists('sub1/sub2')
298
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
301
assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
302
runcmd('bzr move ../hello.txt .')
303
assert exists('./hello.txt')
304
assert backtick('bzr relpath hello.txt') == 'sub1/sub2/hello.txt\n'
305
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
306
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
308
assert backtick('bzr relpath sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
310
runcmd('bzr move sub2/hello.txt .')
311
assert exists('hello.txt')
313
f = file('hello.txt', 'wt')
314
f.write('some nice new content\n')
317
f = file('msg.tmp', 'wt')
318
f.write('this is my new commit\n')
321
runcmd('bzr commit -F msg.tmp')
323
assert backtick('bzr revno') == '5\n'
324
runcmd('bzr export -r 5 export-5.tmp')
325
runcmd('bzr export export.tmp')
332
progress("file with spaces in name")
333
mkdir('sub directory')
334
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
337
runcmd('bzr commit -m add-spaces')
346
progress('ignore patterns')
347
mkdir('ignorebranch')
350
assert backtick('bzr unknowns') == ''
352
file('foo.tmp', 'wt').write('tmp files are ignored')
353
assert backtick('bzr unknowns') == ''
355
file('foo.c', 'wt').write('int main() {}')
356
assert backtick('bzr unknowns') == 'foo.c\n'
357
runcmd('bzr add foo.c')
358
assert backtick('bzr unknowns') == ''
360
# 'ignore' works when creating the .bzignore file
361
file('foo.blah', 'wt').write('blah')
362
assert backtick('bzr unknowns') == 'foo.blah\n'
363
runcmd('bzr ignore *.blah')
364
assert backtick('bzr unknowns') == ''
365
assert file('.bzrignore', 'rb').read() == '*.blah\n'
367
# 'ignore' works when then .bzrignore file already exists
368
file('garh', 'wt').write('garh')
369
assert backtick('bzr unknowns') == 'garh\n'
370
runcmd('bzr ignore garh')
371
assert backtick('bzr unknowns') == ''
372
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
174
376
progress("all tests passed!")
175
377
except Exception, e:
176
378
sys.stderr.write('*' * 50 + '\n'
177
379
+ 'testbzr: tests failed\n'
178
+ 'see testbzr.log for more information\n'
380
+ 'see ' + LOGFILENAME + ' for more information\n'
179
381
+ '*' * 50 + '\n')
180
382
logfile.write('tests failed!\n')
181
383
traceback.print_exc(None, logfile)
386
sys.stdout.writelines(file(os.path.join(start_dir, LOGFILENAME), 'rt').readlines()[-50:])