3 # runtest.py - wrapper script for running SCons tests
5 # This script mainly exists to set PYTHONPATH to the right list of
6 # directories to test the SCons modules.
8 # By default, it directly uses the modules in the local tree:
9 # ./src/ (source files we ship) and ./etc/ (other modules we don't)
11 # When "-b aegis" is specified, it assumes it's in a directory
12 # in which an Aegis build (aeb) has been performed, and sets
13 # PYTHONPATH so that it *only* references the modules that have
14 # unpacked from the built packages, to test whether the packages
19 # -a Run all tests; does a virtual 'find' for
20 # all SCons tests under the current directory.
22 # -d Debug. Runs the script under the Python
23 # debugger (pdb.py) so you don't have to
24 # muck with PYTHONPATH yourself.
26 # -p package Test against the specified package.
28 # -q Quiet. By default, runtest.py prints the
29 # command line it will execute before
30 # executing it. This suppresses that print.
32 # -X The scons "script" is an executable; don't
35 # -x scons The scons script to use for tests.
37 # (Note: There used to be a -v option that specified the SCons
38 # version to be tested, when we were installing in a version-specific
39 # library directory. If we ever resurrect that as the default, then
40 # you can find the appropriate code in the 0.04 version of this script,
41 # rather than reinventing that wheel.)
59 if sys.platform == 'win32':
60 lib_dir = os.path.join(sys.exec_prefix, "lib")
62 lib_dir = os.path.join(sys.exec_prefix, "lib", "python" + sys.version[0:3])
64 opts, tests = getopt.getopt(sys.argv[1:], "adqp:Xx:",
65 ['all', 'debug', 'exec=', 'quiet', 'package='])
68 if o == '-a' or o == '--all': all = 1
69 elif o == '-d' or o == '--debug': debug = os.path.join(lib_dir, "pdb.py")
70 elif o == '-q' or o == '--quiet': printcmd = 0
71 elif o == '-p' or o == '--package': package = a
72 elif o == '-X': scons_exec = 1
73 elif o == '-x' or o == '--exec': scons = a
78 map(os.path.abspath, tests)
80 def find_Test_py(arg, dirname, names):
82 n = filter(lambda n: n[-8:] == "Tests.py", names)
83 tests.extend(map(lambda x,d=dirname: os.path.join(d, x), n))
84 os.path.walk('src', find_Test_py, 0)
86 def find_py(arg, dirname, names):
88 n = filter(lambda n: n[-3:] == ".py", names)
89 tests.extend(map(lambda x,d=dirname: os.path.join(d, x), n))
90 os.path.walk('test', find_py, 0)
106 'deb' : os.path.join('python2.1', 'site-packages')
109 if not dir.has_key(package):
110 sys.stderr.write("Unknown package '%s'\n" % package)
113 test_dir = os.path.join(cwd, 'build', 'test-%s' % package)
115 if sys.platform == 'win32':
116 scons_dir = os.path.join(test_dir, dir[package], 'Scripts')
117 lib_dir = os.path.join(test_dir, dir[package])
119 scons_dir = os.path.join(test_dir, dir[package], 'bin')
120 l = lib.get(package, 'scons')
121 lib_dir = os.path.join(test_dir, dir[package], 'lib', l)
125 scons_dir = os.path.join(cwd, 'src', 'script')
127 lib_dir = os.path.join(cwd, 'src', 'engine')
130 # Let the version of SCons that the -x option pointed to find
132 os.environ['SCONS'] = scons
134 # Because SCons is really aggressive about finding its modules,
135 # it sometimes finds SCons modules elsewhere on the system.
136 # This forces SCons to use the modules that are being tested.
137 os.environ['SCONS_LIB_DIR'] = lib_dir
140 os.environ['SCONS_EXEC'] = '1'
142 os.environ['PYTHONPATH'] = lib_dir + \
144 os.path.join(cwd, 'build', 'etc') + \
146 os.path.join(cwd, 'etc')
154 if os.path.isabs(path):
157 abs = os.path.join(cwd, path)
158 cmd = string.join(["python", debug, abs], " ")
162 if s == 1 or s == 256:
164 elif s == 2 or s == 512:
165 no_result.append(path)
167 print "Unexpected exit status %d" % s
174 str = "%d tests" % len(fail)
175 print "\nFailed the following %s:" % str
176 print "\t", string.join(fail, "\n\t")
178 if len(no_result) == 1:
181 str = "%d tests" % len(no_result)
182 print "\nNO RESULT from the following %s:" % str
183 print "\t", string.join(no_result, "\n\t")
185 sys.exit(len(fail) + len(no_result))