~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testbzr

  • Committer: Martin Pool
  • Date: 2005-05-05 06:38:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050505063818-3eb3260343878325
- do upload CHANGELOG to web server, even though it's autogenerated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
2
 
4
3
# Copyright (C) 2005 Canonical Ltd
5
4
 
23
22
This always runs bzr as an external process to try to catch bugs
24
23
related to argument processing, startup, etc.
25
24
 
26
 
usage:
27
 
 
28
 
    testbzr [-p PYTHON] [BZR]
29
 
 
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.
34
 
 
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
39
 
works on python2.3.
40
 
 
41
25
This replaces the previous test.sh which was not very portable."""
42
26
 
43
27
import sys, os, traceback
46
30
 
47
31
TESTDIR = "testbzr.tmp"
48
32
 
49
 
OVERRIDE_PYTHON = None
50
 
 
51
33
LOGFILENAME = 'testbzr.log'
52
34
 
53
35
try:
65
47
 
66
48
def formcmd(cmd):
67
49
    if isinstance(cmd, basestring):
 
50
        logfile.write('$ %s\n' % cmd)
68
51
        cmd = cmd.split()
69
 
 
70
 
    if cmd[0] == 'bzr':
71
 
        cmd[0] = BZRPATH
72
 
        if OVERRIDE_PYTHON:
73
 
            cmd.insert(0, OVERRIDE_PYTHON)
74
 
 
75
 
    logfile.write('$ %r\n' % cmd)
76
 
    
 
52
    else:
 
53
        logfile.write('$ %r\n' % cmd)
 
54
 
77
55
    return cmd
78
56
 
79
57
 
137
115
if os.path.exists(TESTDIR):
138
116
    shutil.rmtree(TESTDIR)
139
117
 
140
 
start_dir = os.getcwd()
141
 
 
142
118
 
143
119
logfile = open(LOGFILENAME, 'wt', buffering=1)
144
120
 
145
121
 
146
122
try:
147
 
    from getopt import getopt
148
 
    opts, args = getopt(sys.argv[1:], 'p:')
149
 
 
150
 
    for option, value in opts:
151
 
        if option == '-p':
152
 
            OVERRIDE_PYTHON = value
153
 
            
154
 
    
155
 
    mypath = os.path.abspath(sys.argv[0])
156
 
    print '%-30s %s' % ('running tests from', mypath)
157
 
 
158
 
    global BZRPATH
159
 
 
160
 
    if args:
161
 
        BZRPATH = args[0]
162
 
    else:
163
 
        BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
164
 
 
165
 
    print '%-30s %s' % ('against bzr', BZRPATH)
166
 
    print '%-30s %s' % ('in directory', os.getcwd())
167
 
    print '%-30s %s' % ('with python', (OVERRIDE_PYTHON or '(default)'))
168
 
    print
169
 
    print backtick([BZRPATH, 'version'])
170
 
    
171
123
    runcmd(['mkdir', TESTDIR])
172
124
    cd(TESTDIR)
173
 
    test_root = os.getcwd()
174
125
 
175
126
    progress("introductory commands")
176
127
    runcmd("bzr version")
178
129
    runcmd("bzr help")
179
130
    runcmd("bzr --help")
180
131
 
181
 
    progress("internal tests")
182
 
    runcmd("bzr selftest")
183
 
 
184
132
    progress("user identity")
185
133
    # this should always identify something, if only "john@localhost"
186
134
    runcmd("bzr whoami")
190
138
    progress("invalid commands")
191
139
    runcmd("bzr pants", retcode=1)
192
140
    runcmd("bzr --pants off", retcode=1)
193
 
    runcmd("bzr diff --message foo", retcode=1)
194
141
 
195
142
    progress("basic branch creation")
196
143
    runcmd(['mkdir', 'branch1'])
197
144
    cd('branch1')
198
145
    runcmd('bzr init')
199
146
 
200
 
    assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
201
 
 
202
147
    progress("status of new file")
203
148
    
204
149
    f = file('test.txt', 'wt')
209
154
    assert out == 'test.txt\n'
210
155
 
211
156
    out = backtick("bzr status")
212
 
    assert out == 'unknown:\n  test.txt\n'
 
157
    assert out == '''?       test.txt\n'''
213
158
 
214
159
    out = backtick("bzr status --all")
215
 
    assert out == "unknown:\n  test.txt\n"
216
 
 
217
 
    out = backtick("bzr status test.txt --all")
218
 
    assert out == "unknown:\n  test.txt\n"
219
 
 
220
 
    f = file('test2.txt', 'wt')
221
 
    f.write('goodbye cruel world...\n')
222
 
    f.close()
223
 
 
224
 
    out = backtick("bzr status test.txt")
225
 
    assert out == "unknown:\n  test.txt\n"
226
 
 
227
 
    out = backtick("bzr status")
228
 
    assert out == ("unknown:\n"
229
 
                   "  test.txt\n"
230
 
                   "  test2.txt\n")
231
 
 
232
 
    os.unlink('test2.txt')
 
160
    assert out == "?       test.txt\n"
233
161
 
234
162
    progress("command aliases")
235
163
    out = backtick("bzr st --all")
236
 
    assert out == ("unknown:\n"
237
 
                   "  test.txt\n")
238
 
    
 
164
    assert out == "?       test.txt\n"
239
165
    out = backtick("bzr stat")
240
 
    assert out == ("unknown:\n"
241
 
                   "  test.txt\n")
 
166
    assert out == "?       test.txt\n"
242
167
 
243
168
    progress("command help")
244
169
    runcmd("bzr help st")
256
181
 
257
182
    runcmd("bzr add test.txt")
258
183
    assert backtick("bzr unknowns") == ''
259
 
    assert backtick("bzr status --all") == ("added:\n"
260
 
                                            "  test.txt\n")
 
184
    assert backtick("bzr status --all") == "A       test.txt\n"
261
185
 
262
186
    progress("rename newly-added file")
263
187
    runcmd("bzr rename test.txt hello.txt")
278
202
    runcmd("bzr add sub1")
279
203
    runcmd("bzr rename sub1 sub2")
280
204
    runcmd("bzr move hello.txt sub2")
281
 
    assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
282
205
 
283
206
    assert exists("sub2")
284
207
    assert exists("sub2/hello.txt")
299
222
    runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
300
223
 
301
224
    cd('sub1/sub2')
302
 
    assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
303
225
    runcmd('bzr move ../hello.txt .')
304
226
    assert exists('./hello.txt')
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')
307
227
    runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
308
228
    cd('..')
309
 
    assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
310
229
 
311
230
    runcmd('bzr move sub2/hello.txt .')
312
231
    assert exists('hello.txt')
313
 
 
314
 
    f = file('hello.txt', 'wt')
315
 
    f.write('some nice new content\n')
316
 
    f.close()
317
 
 
318
 
    f = file('msg.tmp', 'wt')
319
 
    f.write('this is my new commit\n')
320
 
    f.close()
321
 
 
322
 
    runcmd('bzr commit -F msg.tmp')
323
 
 
324
 
    assert backtick('bzr revno') == '5\n'
325
 
    runcmd('bzr export -r 5 export-5.tmp')
326
 
    runcmd('bzr export export.tmp')
327
 
 
328
 
    runcmd('bzr log')
329
 
    runcmd('bzr log -v')
330
 
 
331
 
 
332
 
 
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')
336
 
    runcmd('bzr add .')
337
 
    runcmd('bzr diff')
338
 
    runcmd('bzr commit -m add-spaces')
339
 
    runcmd('bzr check')
340
 
 
341
 
    runcmd('bzr log')
342
 
    runcmd('bzr log --forward')
343
 
 
344
 
    runcmd('bzr info')
345
 
 
346
 
 
347
 
    
348
 
 
349
 
 
350
 
 
351
 
    cd('..')
352
 
    cd('..')
353
 
 
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...
359
 
    #     added a
360
 
    #     * commited r1
361
 
    #     $ bzr remove a
362
 
    #     $ bzr status
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')
367
 
    runcmd('bzr init')
368
 
    file('a', 'w').write('foo')
369
 
    runcmd('bzr add a')
370
 
    runcmd(['bzr', 'commit', '-m', 'add a'])
371
 
    runcmd('bzr remove a')
372
 
    runcmd('bzr status')
373
 
 
374
 
    cd('..')
375
 
 
376
 
    progress('ignore patterns')
377
 
    mkdir('ignorebranch')
378
 
    cd('ignorebranch')
379
 
    runcmd('bzr init')
380
 
    assert backtick('bzr unknowns') == ''
381
 
 
382
 
    file('foo.tmp', 'wt').write('tmp files are ignored')
383
 
    assert backtick('bzr unknowns') == ''
384
 
 
385
 
    file('foo.c', 'wt').write('int main() {}')
386
 
    assert backtick('bzr unknowns') == 'foo.c\n'
387
 
    runcmd('bzr add foo.c')
388
 
    assert backtick('bzr unknowns') == ''
389
 
 
390
 
    # 'ignore' works when creating the .bzignore file
391
 
    file('foo.blah', 'wt').write('blah')
392
 
    assert backtick('bzr unknowns') == 'foo.blah\n'
393
 
    runcmd('bzr ignore *.blah')
394
 
    assert backtick('bzr unknowns') == ''
395
 
    assert file('.bzrignore', 'rb').read() == '*.blah\n'
396
 
 
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'
403
 
 
404
 
    cd('..')
405
 
 
406
 
 
407
 
 
408
 
 
409
 
    progress("recursive and non-recursive add")
410
 
    mkdir('no-recurse')
411
 
    cd('no-recurse')
412
 
    runcmd('bzr init')
413
 
    mkdir('foo')
414
 
    fp = os.path.join('foo', 'test.txt')
415
 
    f = file(fp, 'w')
416
 
    f.write('hello!\n')
417
 
    f.close()
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')
422
 
 
423
 
    runcmd('bzr file-id ' + fp, 1)      # still not versioned 
424
 
 
425
 
    runcmd('bzr add foo')
426
 
    runcmd('bzr file-id ' + fp)
427
 
    runcmd('bzr commit -m add-sub-file')
428
 
    
429
 
    cd('..')
430
 
 
431
 
 
432
 
 
 
232
    
 
233
    
 
234
    cd('..')
433
235
 
434
236
    progress("all tests passed!")
435
237
except Exception, e:
439
241
                     + '*' * 50 + '\n')
440
242
    logfile.write('tests failed!\n')
441
243
    traceback.print_exc(None, logfile)
442
 
    logfile.close()
443
 
 
444
 
    sys.stdout.writelines(file(os.path.join(start_dir, LOGFILENAME), 'rt').readlines()[-50:])
445
 
    
446
244
    sys.exit(1)
447