104
113
logfile.write(' at %s:%d\n' % stack[:2])
107
TESTDIR = "testbzr.tmp"
109
117
# prepare an empty scratch directory
110
118
if os.path.exists(TESTDIR):
111
119
shutil.rmtree(TESTDIR)
114
logfile = open('testbzr.log', 'wt', buffering=1)
122
logfile = open(LOGFILENAME, 'wt', buffering=1)
126
mypath = os.path.abspath(sys.argv[0])
127
print '%-30s %s' % ('running tests from', mypath)
131
if len(sys.argv) > 1:
132
BZRPATH = sys.argv[1]
134
BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
136
print '%-30s %s' % ('against bzr', BZRPATH)
137
print '%-30s %s' % ('in directory', os.getcwd())
139
print backtick([BZRPATH, 'version'])
118
141
runcmd(['mkdir', TESTDIR])
143
test_root = os.getcwd()
121
145
progress("introductory commands")
122
146
runcmd("bzr version")
147
runcmd("bzr --version")
123
148
runcmd("bzr help")
124
149
runcmd("bzr --help")
151
progress("internal tests")
152
runcmd("bzr selftest")
126
154
progress("user identity")
127
155
# this should always identify something, if only "john@localhost"
128
156
runcmd("bzr whoami")
132
160
progress("invalid commands")
133
161
runcmd("bzr pants", retcode=1)
134
162
runcmd("bzr --pants off", retcode=1)
163
runcmd("bzr diff --message foo", retcode=1)
136
165
progress("basic branch creation")
137
166
runcmd(['mkdir', 'branch1'])
139
168
runcmd('bzr init')
170
assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
141
172
progress("status of new file")
143
174
f = file('test.txt', 'wt')
148
179
assert out == 'test.txt\n'
150
181
out = backtick("bzr status")
151
assert out == '''? test.txt\n'''
182
assert out == 'unknown:\n test.txt\n'
153
184
out = backtick("bzr status --all")
154
assert out == "? test.txt\n"
185
assert out == "unknown:\n test.txt\n"
187
out = backtick("bzr status test.txt --all")
188
assert out == "unknown:\n test.txt\n"
190
f = file('test2.txt', 'wt')
191
f.write('goodbye cruel world...\n')
194
out = backtick("bzr status test.txt")
195
assert out == "unknown:\n test.txt\n"
197
out = backtick("bzr status")
198
assert out == ("unknown:\n"
202
os.unlink('test2.txt')
204
progress("command aliases")
205
out = backtick("bzr st --all")
206
assert out == ("unknown:\n"
209
out = backtick("bzr stat")
210
assert out == ("unknown:\n"
213
progress("command help")
214
runcmd("bzr help st")
216
runcmd("bzr help commands")
217
runcmd("bzr help slartibartfast", 1)
219
out = backtick("bzr help ci")
220
out.index('aliases: ')
156
222
progress("can't rename unversioned file")
157
223
runcmd("bzr rename test.txt new-test.txt", 1)
170
237
assert backtick("bzr revno") == '0\n'
239
progress("add first revision")
240
runcmd(["bzr", "commit", "-m", 'add first revision'])
242
progress("more complex renames")
244
runcmd("bzr rename hello.txt sub1", 1)
245
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
246
runcmd("bzr move hello.txt sub1", 1)
248
runcmd("bzr add sub1")
249
runcmd("bzr rename sub1 sub2")
250
runcmd("bzr move hello.txt sub2")
251
assert backtick("bzr relpath sub2/hello.txt") == "sub2/hello.txt\n"
253
assert exists("sub2")
254
assert exists("sub2/hello.txt")
255
assert not exists("sub1")
256
assert not exists("hello.txt")
258
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
261
runcmd('bzr add sub1')
262
runcmd('bzr move sub2/hello.txt sub1')
263
assert not exists('sub2/hello.txt')
264
assert exists('sub1/hello.txt')
265
runcmd('bzr move sub2 sub1')
266
assert not exists('sub2')
267
assert exists('sub1/sub2')
269
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
272
assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
273
runcmd('bzr move ../hello.txt .')
274
assert exists('./hello.txt')
275
assert backtick('bzr relpath hello.txt') == 'sub1/sub2/hello.txt\n'
276
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
277
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
279
assert backtick('bzr relpath sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
281
runcmd('bzr move sub2/hello.txt .')
282
assert exists('hello.txt')
284
f = file('hello.txt', 'wt')
285
f.write('some nice new content\n')
288
f = file('msg.tmp', 'wt')
289
f.write('this is my new commit\n')
292
runcmd('bzr commit -F msg.tmp')
294
assert backtick('bzr revno') == '5\n'
295
runcmd('bzr export -r 5 export-5.tmp')
296
runcmd('bzr export export.tmp')
304
progress('ignore patterns')
305
mkdir('ignorebranch')
308
assert backtick('bzr unknowns') == ''
310
file('foo.tmp', 'wt').write('tmp files are ignored')
311
assert backtick('bzr unknowns') == ''
313
file('foo.c', 'wt').write('int main() {}')
314
assert backtick('bzr unknowns') == 'foo.c\n'
315
runcmd('bzr add foo.c')
316
assert backtick('bzr unknowns') == ''
318
file('foo.blah', 'wt').write('blah')
319
assert backtick('bzr unknowns') == 'foo.blah\n'
320
runcmd('bzr ignore *.blah')
321
assert backtick('bzr unknowns') == ''
322
assert file('.bzrignore', 'rt').read() == '*.blah\n'
174
325
progress("all tests passed!")
175
326
except Exception, e:
176
327
sys.stderr.write('*' * 50 + '\n'
177
328
+ 'testbzr: tests failed\n'
178
+ 'see testbzr.log for more information\n'
329
+ 'see ' + LOGFILENAME + ' for more information\n'
179
330
+ '*' * 50 + '\n')
180
331
logfile.write('tests failed!\n')
181
332
traceback.print_exc(None, logfile)