1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
#!/usr/bin/env python
#
# runtests.py - wrapper script for running SCons tests
#
# This script mainly exists to set PYTHONPATH to the right list of
# directories to test the SCons modules.
#
# By default, it directly uses the modules in the local tree:
# ./src/ (source files we ship) and ./etc/ (other modules we don't)
#
# When "-b aegis" is specified, it assumes it's in a directory
# in which an Aegis build (aeb) has been performed, and sets
# PYTHONPATH so that it *only* references the modules that have
# unpacked from the built packages, to test whether the packages
# are good.
#
# Options:
#
# -1 Use the test configuration in build/test1
# (installed from the scons package)
#
# -2 Use the test configuration in build/test2
# (installed from the python-scons and scons-script
# packages)
#
# -a Run all tests; does a virtual 'find' for
# all SCons tests under the current directory.
#
# -b system Assume you're in the specified built system.
# 'aegis' is the only one currently defined.
#
# -d Debug. Runs the script under the Python
# debugger (pdb.py) so you don't have to
# muck with PYTHONPATH yourself.
#
# -q Quiet. By default, runtest.py prints the
# command line it will execute before
# executing it. This suppresses that print.
#
# -v Version. Specifies the version number to
# be used for Aegis interaction.
#
import getopt
import os
import os.path
import re
import string
import sys
all = 0
build = None
debug = ''
tests = []
printcmd = 1
version = None
testver = 1
if sys.platform == 'win32':
lib_dir = os.path.join(sys.exec_prefix, "lib")
else:
lib_dir = os.path.join(sys.exec_prefix, "lib", "python" + sys.version[0:3])
opts, tests = getopt.getopt(sys.argv[1:], "12ab:dqv:",
['all','build=','debug','quiet','version='])
for o, a in opts:
if o == '-1': testver = 1
elif o == '-2': testver = 2
elif o == '-a' or o == '--all': all = 1
elif o == '-b' or o == '--build': build = a
elif o == '-d' or o == '--debug': debug = os.path.join(lib_dir, "pdb.py")
elif o == '-q' or o == '--quiet': printcmd = 0
elif o == '-v' or o == '--version': version = a
cwd = os.getcwd()
if tests:
map(os.path.abspath, tests)
elif all:
def find_Test_py(arg, dirname, names):
global tests
n = filter(lambda n: n[-8:] == "Tests.py", names)
n = map(lambda x,d=dirname: os.path.join(d, x), n)
tests = tests + n
os.path.walk('src', find_Test_py, 0)
def find_py(arg, dirname, names):
global tests
n = filter(lambda n: n[-3:] == ".py", names)
n = map(lambda x,d=dirname: os.path.join(d, x), n)
tests = tests + n
os.path.walk('test', find_py, 0)
if build == 'aegis':
if not version:
version = os.popen("aesub '$version'").read()[:-1]
match = re.compile(r'^[CD]0*')
def aegis_to_version(aever):
arr = string.split(aever, '.')
end = max(len(arr) - 1, 2)
arr = map(lambda e: match.sub('', e), arr[:end])
def rep(e):
if len(e) == 1:
e = '0' + e
return e
arr[1:] = map(rep, arr[1:])
return string.join(arr, '.')
version = aegis_to_version(version)
scons_dir = os.path.join(cwd, 'build', 'test' + str(testver), 'bin')
if testver == 1:
test_dir = os.path.join('test1', 'lib', 'scons')
# Our original packaging scheme placed the build engine
# in a private library directory that contained the SCons
# version number in the directory name. Here's how this
# was supported here. See the Construct file for details
# on other files that would need to be changed to support
# this as well.
#test_dir = os.path.join('test1', 'lib', 'scons-' + str(version))
elif testver == 2:
test_dir = os.path.join('test2', 'lib', 'python' + sys.version[0:3],
'site-packages')
os.environ['PYTHONPATH'] = os.path.join(cwd, 'build', test_dir)
else:
scons_dir = os.path.join(cwd, 'src', 'script')
os.environ['PYTHONPATH'] = string.join([os.path.join(cwd, 'src', 'engine'),
os.path.join(cwd, 'etc')],
os.pathsep)
os.chdir(scons_dir)
fail = []
no_result = []
for path in tests:
if os.path.isabs(path):
abs = path
else:
abs = os.path.join(cwd, path)
cmd = string.join(["python", debug, abs], " ")
if printcmd:
print cmd
s = os.system(cmd)
if s == 1 or s == 256:
fail.append(path)
elif s == 2 or s == 512:
no_result.append(path)
elif s != 0:
print "Unexpected exit status %d" % s
if len(tests) != 1:
if fail:
if len(fail) == 1:
str = "test"
else:
str = "%d tests" % len(fail)
print "\nFailed the following %s:" % str
print "\t", string.join(fail, "\n\t")
if no_result:
if len(no_result) == 1:
str = "test"
else:
str = "%d tests" % len(no_result)
print "\nNO RESULT from the following %s:" % str
print "\t", string.join(no_result, "\n\t")
sys.exit(len(fail) + len(no_result))
|