bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
292
by Martin Pool
- start adding a pure-python blackbox test suite |
1 |
#! /usr/bin/python
|
2 |
||
3 |
# Copyright (C) 2005 Canonical Ltd
|
|
4 |
||
5 |
# This program is free software; you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU General Public License as published by
|
|
7 |
# the Free Software Foundation; either version 2 of the License, or
|
|
8 |
# (at your option) any later version.
|
|
9 |
||
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
||
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
||
19 |
||
20 |
"""External black-box test for bzr.
|
|
21 |
||
22 |
This always runs bzr as an external process to try to catch bugs
|
|
23 |
related to argument processing, startup, etc.
|
|
24 |
||
25 |
This replaces the previous test.sh which was not very portable."""
|
|
26 |
||
27 |
import sys, os |
|
28 |
||
29 |
try: |
|
30 |
import shutil |
|
31 |
from subprocess import call, Popen |
|
32 |
except ImportError, e: |
|
33 |
sys.stderr.write("testbzr: sorry, this test suite requires modules from python2.4\n" |
|
34 |
+ ' ' + str(e)) |
|
35 |
sys.exit(1) |
|
36 |
||
37 |
||
38 |
def runcmd(cmd): |
|
39 |
"""run one command and check the output. |
|
40 |
||
41 |
If a single string is based, it is split into words.
|
|
42 |
For commands that are not simple space-separated words, please
|
|
43 |
pass a list instead."""
|
|
44 |
||
45 |
if isinstance(cmd, basestring): |
|
46 |
cmd = cmd.split() |
|
|
293
by Martin Pool
- todos |
47 |
logfile.write('$ %r\n' % cmd) |
|
292
by Martin Pool
- start adding a pure-python blackbox test suite |
48 |
retcode = call(cmd, stdout=logfile, stderr=logfile) |
49 |
if retcode != 0: |
|
50 |
raise Exception("test failed: %r returned %r" % (cmd, retcode)) |
|
51 |
||
52 |
||
53 |
def progress(msg): |
|
54 |
print '* ' + msg |
|
55 |
logfile.write('* '+ msg + '\n') |
|
56 |
||
57 |
||
58 |
TESTDIR = "bzr-test.tmp" |
|
59 |
||
60 |
# prepare an empty scratch directory
|
|
61 |
if os.path.exists(TESTDIR): |
|
62 |
shutil.rmtree(TESTDIR) |
|
63 |
||
64 |
||
65 |
logfile = open('bzr-test.log', 'wt') |
|
66 |
||
67 |
||
68 |
os.mkdir(TESTDIR) |
|
69 |
os.chdir(TESTDIR) |
|
70 |
||
71 |
||
72 |
progress("testing introductory commands") |
|
73 |
runcmd("bzr version") |
|
74 |
runcmd("bzr help") |
|
75 |
runcmd("bzr --help") |
|
76 |
||
77 |
progress("all tests passed!") |