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 '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 'against bzr', BZRPATH
138
print backtick([BZRPATH, 'version'])
118
140
runcmd(['mkdir', TESTDIR])
121
143
progress("introductory commands")
122
144
runcmd("bzr version")
145
runcmd("bzr --version")
123
146
runcmd("bzr help")
124
147
runcmd("bzr --help")
149
progress("internal tests")
150
runcmd("bzr selftest")
126
152
progress("user identity")
127
153
# this should always identify something, if only "john@localhost"
128
154
runcmd("bzr whoami")
132
158
progress("invalid commands")
133
159
runcmd("bzr pants", retcode=1)
134
160
runcmd("bzr --pants off", retcode=1)
161
runcmd("bzr diff --message foo", retcode=1)
136
163
progress("basic branch creation")
137
164
runcmd(['mkdir', 'branch1'])
153
180
out = backtick("bzr status --all")
154
181
assert out == "? test.txt\n"
183
progress("command aliases")
184
out = backtick("bzr st --all")
185
assert out == "? test.txt\n"
186
out = backtick("bzr stat")
187
assert out == "? test.txt\n"
189
progress("command help")
190
runcmd("bzr help st")
192
runcmd("bzr help commands")
193
runcmd("bzr help slartibartfast", 1)
195
out = backtick("bzr help ci")
196
out.index('aliases: ')
156
198
progress("can't rename unversioned file")
157
199
runcmd("bzr rename test.txt new-test.txt", 1)
170
212
assert backtick("bzr revno") == '0\n'
214
progress("add first revision")
215
runcmd(["bzr", "commit", "-m", 'add first revision'])
217
progress("more complex renames")
219
runcmd("bzr rename hello.txt sub1", 1)
220
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
221
runcmd("bzr move hello.txt sub1", 1)
223
runcmd("bzr add sub1")
224
runcmd("bzr rename sub1 sub2")
225
runcmd("bzr move hello.txt sub2")
226
assert backtick("bzr relpath sub2/hello.txt") == "sub2/hello.txt\n"
228
assert exists("sub2")
229
assert exists("sub2/hello.txt")
230
assert not exists("sub1")
231
assert not exists("hello.txt")
233
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
236
runcmd('bzr add sub1')
237
runcmd('bzr move sub2/hello.txt sub1')
238
assert not exists('sub2/hello.txt')
239
assert exists('sub1/hello.txt')
240
runcmd('bzr move sub2 sub1')
241
assert not exists('sub2')
242
assert exists('sub1/sub2')
244
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
247
runcmd('bzr move ../hello.txt .')
248
assert exists('./hello.txt')
249
assert backtick('bzr relpath hello.txt') == 'sub1/sub2/hello.txt\n'
250
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
251
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
253
assert backtick('bzr relpath sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
255
runcmd('bzr move sub2/hello.txt .')
256
assert exists('hello.txt')
258
f = file('hello.txt', 'wt')
259
f.write('some nice new content\n')
262
f = file('msg.tmp', 'wt')
263
f.write('this is my new commit\n')
266
runcmd('bzr commit -F msg.tmp')
268
assert backtick('bzr revno') == '5\n'
269
runcmd('bzr export -r 5 export-5.tmp')
270
runcmd('bzr export export.tmp')
174
274
progress("all tests passed!")
175
275
except Exception, e:
176
276
sys.stderr.write('*' * 50 + '\n'
177
277
+ 'testbzr: tests failed\n'
178
+ 'see testbzr.log for more information\n'
278
+ 'see ' + LOGFILENAME + ' for more information\n'
179
279
+ '*' * 50 + '\n')
180
280
logfile.write('tests failed!\n')
181
281
traceback.print_exc(None, logfile)