~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testbzr

  • Committer: Martin Pool
  • Date: 2005-05-11 08:07:56 UTC
  • Revision ID: mbp@sourcefrog.net-20050511080756-ce1fdb2d72f5e028
- more status form test fixes

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()
 
52
    else:
 
53
        logfile.write('$ %r\n' % cmd)
69
54
 
70
55
    if cmd[0] == 'bzr':
71
56
        cmd[0] = BZRPATH
72
 
        if OVERRIDE_PYTHON:
73
 
            cmd.insert(0, OVERRIDE_PYTHON)
74
57
 
75
 
    logfile.write('$ %r\n' % cmd)
76
 
    
77
58
    return cmd
78
59
 
79
60
 
137
118
if os.path.exists(TESTDIR):
138
119
    shutil.rmtree(TESTDIR)
139
120
 
140
 
start_dir = os.getcwd()
141
 
 
142
121
 
143
122
logfile = open(LOGFILENAME, 'wt', buffering=1)
144
123
 
145
124
 
146
125
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
126
    mypath = os.path.abspath(sys.argv[0])
156
127
    print '%-30s %s' % ('running tests from', mypath)
157
128
 
158
129
    global BZRPATH
159
130
 
160
 
    if args:
161
 
        BZRPATH = args[1]
 
131
    if len(sys.argv) > 1:
 
132
        BZRPATH = sys.argv[1]
162
133
    else:
163
134
        BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
164
135
 
165
136
    print '%-30s %s' % ('against bzr', BZRPATH)
166
137
    print '%-30s %s' % ('in directory', os.getcwd())
167
 
    print '%-30s %s' % ('with python', (OVERRIDE_PYTHON or '(default)'))
168
138
    print
169
139
    print backtick([BZRPATH, 'version'])
170
140
    
278
248
    runcmd("bzr add sub1")
279
249
    runcmd("bzr rename sub1 sub2")
280
250
    runcmd("bzr move hello.txt sub2")
281
 
    assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
 
251
    assert backtick("bzr relpath sub2/hello.txt") == "sub2/hello.txt\n"
282
252
 
283
253
    assert exists("sub2")
284
254
    assert exists("sub2/hello.txt")
302
272
    assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
303
273
    runcmd('bzr move ../hello.txt .')
304
274
    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')
 
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'
307
277
    runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
308
278
    cd('..')
309
 
    assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
279
    assert backtick('bzr relpath sub2/hello.txt') == 'sub1/sub2/hello.txt\n'
310
280
 
311
281
    runcmd('bzr move sub2/hello.txt .')
312
282
    assert exists('hello.txt')
327
297
 
328
298
    runcmd('bzr log')
329
299
    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
 
    cd('..')
349
 
    cd('..')
350
 
 
351
 
    progress('status after remove')
352
 
    mkdir('status-after-remove')
353
 
    # see mail from William Dodé, 2005-05-25
354
 
    # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
355
 
    #     * looking for changes...
356
 
    #     added a
357
 
    #     * commited r1
358
 
    #     $ bzr remove a
359
 
    #     $ bzr status
360
 
    #     bzr: local variable 'kind' referenced before assignment
361
 
    #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
362
 
    #     see ~/.bzr.log for debug information
363
 
    cd('status-after-remove')
364
 
    runcmd('bzr init')
365
 
    file('a', 'w').write('foo')
366
 
    runcmd('bzr add a')
367
 
    runcmd(['bzr', 'commit', '-m', 'add a'])
368
 
    runcmd('bzr remove a')
369
 
    runcmd('bzr status')
370
 
 
 
300
    
 
301
    cd('..')
371
302
    cd('..')
372
303
 
373
304
    progress('ignore patterns')
384
315
    runcmd('bzr add foo.c')
385
316
    assert backtick('bzr unknowns') == ''
386
317
 
387
 
    # 'ignore' works when creating the .bzignore file
388
318
    file('foo.blah', 'wt').write('blah')
389
319
    assert backtick('bzr unknowns') == 'foo.blah\n'
390
320
    runcmd('bzr ignore *.blah')
391
321
    assert backtick('bzr unknowns') == ''
392
 
    assert file('.bzrignore', 'rb').read() == '*.blah\n'
393
 
 
394
 
    # 'ignore' works when then .bzrignore file already exists
395
 
    file('garh', 'wt').write('garh')
396
 
    assert backtick('bzr unknowns') == 'garh\n'
397
 
    runcmd('bzr ignore garh')
398
 
    assert backtick('bzr unknowns') == ''
399
 
    assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
400
 
 
 
322
    assert file('.bzrignore', 'rt').read() == '*.blah\n'
401
323
 
402
324
 
403
325
    progress("all tests passed!")
408
330
                     + '*' * 50 + '\n')
409
331
    logfile.write('tests failed!\n')
410
332
    traceback.print_exc(None, logfile)
411
 
    logfile.close()
412
 
 
413
 
    sys.stdout.writelines(file(os.path.join(start_dir, LOGFILENAME), 'rt').readlines()[-50:])
414
 
    
415
333
    sys.exit(1)
416