~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testbzr

  • Committer: Martin Pool
  • Date: 2005-06-06 12:33:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050606123311-cdd099f5d3b50343
- add deferred patch for finding touching patches from a list

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/python
 
2
# -*- coding: utf-8 -*-
2
3
 
3
4
# Copyright (C) 2005 Canonical Ltd
4
5
 
22
23
This always runs bzr as an external process to try to catch bugs
23
24
related to argument processing, startup, etc.
24
25
 
 
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
 
25
41
This replaces the previous test.sh which was not very portable."""
26
42
 
27
43
import sys, os, traceback
30
46
 
31
47
TESTDIR = "testbzr.tmp"
32
48
 
 
49
 
 
50
# we always invoke bzr as 'python bzr' (or e.g. 'python2.3 bzr')
 
51
# partly so as to cope if the bzr binary is not marked executable
 
52
OVERRIDE_PYTHON = 'python'
 
53
 
33
54
LOGFILENAME = 'testbzr.log'
34
55
 
35
56
try:
47
68
 
48
69
def formcmd(cmd):
49
70
    if isinstance(cmd, basestring):
50
 
        logfile.write('$ %s\n' % cmd)
51
71
        cmd = cmd.split()
52
 
    else:
53
 
        logfile.write('$ %r\n' % cmd)
54
 
 
 
72
 
 
73
    if cmd[0] == 'bzr':
 
74
        cmd[0] = BZRPATH
 
75
        if OVERRIDE_PYTHON:
 
76
            cmd.insert(0, OVERRIDE_PYTHON)
 
77
 
 
78
    logfile.write('$ %r\n' % cmd)
 
79
    
55
80
    return cmd
56
81
 
57
82
 
115
140
if os.path.exists(TESTDIR):
116
141
    shutil.rmtree(TESTDIR)
117
142
 
 
143
start_dir = os.getcwd()
 
144
 
118
145
 
119
146
logfile = open(LOGFILENAME, 'wt', buffering=1)
120
147
 
121
148
 
122
149
try:
 
150
    from getopt import getopt
 
151
    opts, args = getopt(sys.argv[1:], 'p:')
 
152
 
 
153
    for option, value in opts:
 
154
        if option == '-p':
 
155
            OVERRIDE_PYTHON = value
 
156
            
 
157
    
 
158
    mypath = os.path.abspath(sys.argv[0])
 
159
    print '%-30s %s' % ('running tests from', mypath)
 
160
 
 
161
    global BZRPATH
 
162
 
 
163
    if args:
 
164
        BZRPATH = args[0]
 
165
    else:
 
166
        BZRPATH = os.path.join(os.path.split(mypath)[0], 'bzr')
 
167
 
 
168
    print '%-30s %s' % ('against bzr', BZRPATH)
 
169
    print '%-30s %s' % ('in directory', os.getcwd())
 
170
    print '%-30s %s' % ('with python', (OVERRIDE_PYTHON or '(default)'))
 
171
    print
 
172
    print backtick('bzr version')
 
173
    
123
174
    runcmd(['mkdir', TESTDIR])
124
175
    cd(TESTDIR)
 
176
    test_root = os.getcwd()
125
177
 
126
178
    progress("introductory commands")
127
179
    runcmd("bzr version")
129
181
    runcmd("bzr help")
130
182
    runcmd("bzr --help")
131
183
 
 
184
    progress("internal tests")
 
185
    runcmd("bzr selftest")
 
186
 
132
187
    progress("user identity")
133
188
    # this should always identify something, if only "john@localhost"
134
189
    runcmd("bzr whoami")
138
193
    progress("invalid commands")
139
194
    runcmd("bzr pants", retcode=1)
140
195
    runcmd("bzr --pants off", retcode=1)
 
196
    runcmd("bzr diff --message foo", retcode=1)
141
197
 
142
198
    progress("basic branch creation")
143
199
    runcmd(['mkdir', 'branch1'])
144
200
    cd('branch1')
145
201
    runcmd('bzr init')
146
202
 
 
203
    assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
 
204
 
147
205
    progress("status of new file")
148
206
    
149
207
    f = file('test.txt', 'wt')
154
212
    assert out == 'test.txt\n'
155
213
 
156
214
    out = backtick("bzr status")
157
 
    assert out == '''?       test.txt\n'''
 
215
    assert out == 'unknown:\n  test.txt\n'
158
216
 
159
217
    out = backtick("bzr status --all")
160
 
    assert out == "?       test.txt\n"
 
218
    assert out == "unknown:\n  test.txt\n"
 
219
 
 
220
    out = backtick("bzr status test.txt --all")
 
221
    assert out == "unknown:\n  test.txt\n"
 
222
 
 
223
    f = file('test2.txt', 'wt')
 
224
    f.write('goodbye cruel world...\n')
 
225
    f.close()
 
226
 
 
227
    out = backtick("bzr status test.txt")
 
228
    assert out == "unknown:\n  test.txt\n"
 
229
 
 
230
    out = backtick("bzr status")
 
231
    assert out == ("unknown:\n"
 
232
                   "  test.txt\n"
 
233
                   "  test2.txt\n")
 
234
 
 
235
    os.unlink('test2.txt')
161
236
 
162
237
    progress("command aliases")
163
238
    out = backtick("bzr st --all")
164
 
    assert out == "?       test.txt\n"
 
239
    assert out == ("unknown:\n"
 
240
                   "  test.txt\n")
 
241
    
165
242
    out = backtick("bzr stat")
166
 
    assert out == "?       test.txt\n"
 
243
    assert out == ("unknown:\n"
 
244
                   "  test.txt\n")
167
245
 
168
246
    progress("command help")
169
247
    runcmd("bzr help st")
181
259
 
182
260
    runcmd("bzr add test.txt")
183
261
    assert backtick("bzr unknowns") == ''
184
 
    assert backtick("bzr status --all") == "A       test.txt\n"
 
262
    assert backtick("bzr status --all") == ("added:\n"
 
263
                                            "  test.txt\n")
185
264
 
186
265
    progress("rename newly-added file")
187
266
    runcmd("bzr rename test.txt hello.txt")
202
281
    runcmd("bzr add sub1")
203
282
    runcmd("bzr rename sub1 sub2")
204
283
    runcmd("bzr move hello.txt sub2")
 
284
    assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
205
285
 
206
286
    assert exists("sub2")
207
287
    assert exists("sub2/hello.txt")
222
302
    runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
223
303
 
224
304
    cd('sub1/sub2')
 
305
    assert backtick('bzr root')[:-1] == os.path.join(test_root, 'branch1')
225
306
    runcmd('bzr move ../hello.txt .')
226
307
    assert exists('./hello.txt')
 
308
    assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
 
309
    assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
227
310
    runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
228
311
    cd('..')
 
312
    assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
229
313
 
230
314
    runcmd('bzr move sub2/hello.txt .')
231
315
    assert exists('hello.txt')
232
 
    
233
 
    
234
 
    cd('..')
 
316
 
 
317
    f = file('hello.txt', 'wt')
 
318
    f.write('some nice new content\n')
 
319
    f.close()
 
320
 
 
321
    f = file('msg.tmp', 'wt')
 
322
    f.write('this is my new commit\n')
 
323
    f.close()
 
324
 
 
325
    runcmd('bzr commit -F msg.tmp')
 
326
 
 
327
    assert backtick('bzr revno') == '5\n'
 
328
    runcmd('bzr export -r 5 export-5.tmp')
 
329
    runcmd('bzr export export.tmp')
 
330
 
 
331
    runcmd('bzr log')
 
332
    runcmd('bzr log -v')
 
333
 
 
334
 
 
335
 
 
336
    progress("file with spaces in name")
 
337
    mkdir('sub directory')
 
338
    file('sub directory/file with spaces ', 'wt').write('see how this works\n')
 
339
    runcmd('bzr add .')
 
340
    runcmd('bzr diff')
 
341
    runcmd('bzr commit -m add-spaces')
 
342
    runcmd('bzr check')
 
343
 
 
344
    runcmd('bzr log')
 
345
    runcmd('bzr log --forward')
 
346
 
 
347
    runcmd('bzr info')
 
348
 
 
349
 
 
350
    
 
351
 
 
352
 
 
353
 
 
354
    cd('..')
 
355
    cd('..')
 
356
    progress('branch')
 
357
    # Can't create a branch if it already exists
 
358
    runcmd('bzr branch branch1', retcode=1)
 
359
    # Can't create a branch if its parent doesn't exist
 
360
    runcmd('bzr branch /unlikely/to/exist', retcode=1)
 
361
    runcmd('bzr branch branch1 branch2')
 
362
 
 
363
    progress("pull")
 
364
    cd('branch1')
 
365
    runcmd('bzr pull', retcode=1)
 
366
    runcmd('bzr pull ../branch2')
 
367
    cd('.bzr')
 
368
    runcmd('bzr pull')
 
369
    runcmd('bzr commit -m empty')
 
370
    runcmd('bzr pull')
 
371
    cd('../../branch2')
 
372
    runcmd('bzr pull')
 
373
    runcmd('bzr commit -m empty')
 
374
    cd('../branch1')
 
375
    runcmd('bzr commit -m empty')
 
376
    runcmd('bzr pull', retcode=1)
 
377
    cd ('..')
 
378
 
 
379
    progress('status after remove')
 
380
    mkdir('status-after-remove')
 
381
    # see mail from William Dodé, 2005-05-25
 
382
    # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
 
383
    #     * looking for changes...
 
384
    #     added a
 
385
    #     * commited r1
 
386
    #     $ bzr remove a
 
387
    #     $ bzr status
 
388
    #     bzr: local variable 'kind' referenced before assignment
 
389
    #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
 
390
    #     see ~/.bzr.log for debug information
 
391
    cd('status-after-remove')
 
392
    runcmd('bzr init')
 
393
    file('a', 'w').write('foo')
 
394
    runcmd('bzr add a')
 
395
    runcmd(['bzr', 'commit', '-m', 'add a'])
 
396
    runcmd('bzr remove a')
 
397
    runcmd('bzr status')
 
398
 
 
399
    cd('..')
 
400
 
 
401
    progress('ignore patterns')
 
402
    mkdir('ignorebranch')
 
403
    cd('ignorebranch')
 
404
    runcmd('bzr init')
 
405
    assert backtick('bzr unknowns') == ''
 
406
 
 
407
    file('foo.tmp', 'wt').write('tmp files are ignored')
 
408
    assert backtick('bzr unknowns') == ''
 
409
 
 
410
    file('foo.c', 'wt').write('int main() {}')
 
411
    assert backtick('bzr unknowns') == 'foo.c\n'
 
412
    runcmd('bzr add foo.c')
 
413
    assert backtick('bzr unknowns') == ''
 
414
 
 
415
    # 'ignore' works when creating the .bzignore file
 
416
    file('foo.blah', 'wt').write('blah')
 
417
    assert backtick('bzr unknowns') == 'foo.blah\n'
 
418
    runcmd('bzr ignore *.blah')
 
419
    assert backtick('bzr unknowns') == ''
 
420
    assert file('.bzrignore', 'rb').read() == '*.blah\n'
 
421
 
 
422
    # 'ignore' works when then .bzrignore file already exists
 
423
    file('garh', 'wt').write('garh')
 
424
    assert backtick('bzr unknowns') == 'garh\n'
 
425
    runcmd('bzr ignore garh')
 
426
    assert backtick('bzr unknowns') == ''
 
427
    assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
 
428
 
 
429
    cd('..')
 
430
 
 
431
 
 
432
 
 
433
 
 
434
    progress("recursive and non-recursive add")
 
435
    mkdir('no-recurse')
 
436
    cd('no-recurse')
 
437
    runcmd('bzr init')
 
438
    mkdir('foo')
 
439
    fp = os.path.join('foo', 'test.txt')
 
440
    f = file(fp, 'w')
 
441
    f.write('hello!\n')
 
442
    f.close()
 
443
    runcmd('bzr add --no-recurse foo')
 
444
    runcmd('bzr file-id foo')
 
445
    runcmd('bzr file-id ' + fp, 1)      # not versioned yet
 
446
    runcmd('bzr commit -m add-dir-only')
 
447
 
 
448
    runcmd('bzr file-id ' + fp, 1)      # still not versioned 
 
449
 
 
450
    runcmd('bzr add foo')
 
451
    runcmd('bzr file-id ' + fp)
 
452
    runcmd('bzr commit -m add-sub-file')
 
453
    
 
454
    cd('..')
 
455
 
 
456
 
 
457
 
235
458
 
236
459
    progress("all tests passed!")
237
460
except Exception, e:
241
464
                     + '*' * 50 + '\n')
242
465
    logfile.write('tests failed!\n')
243
466
    traceback.print_exc(None, logfile)
 
467
    logfile.close()
 
468
 
 
469
    sys.stdout.writelines(file(os.path.join(start_dir, LOGFILENAME), 'rt').readlines()[-50:])
 
470
    
244
471
    sys.exit(1)
 
472