3 # runtests.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 # -q Quiet. By default, runtest.py prints the
27 # command line it will execute before
28 # executing it. This suppresses that print.
30 # -p package Test against the specified package.
32 # (Note: There used to be a -v option that specified the SCons
33 # version to be tested, when we were installing in a version-specific
34 # library directory. If we ever resurrect that as the default, then
35 # you can find the appropriate code in the 0.04 version of this script,
36 # rather than reinventing that wheel.)
52 if sys.platform == 'win32':
53 lib_dir = os.path.join(sys.exec_prefix, "lib")
55 lib_dir = os.path.join(sys.exec_prefix, "lib", "python" + sys.version[0:3])
57 opts, tests = getopt.getopt(sys.argv[1:], "adqp:",
58 ['all', 'debug', 'quiet', 'package='])
61 if o == '-a' or o == '--all': all = 1
62 elif o == '-d' or o == '--debug': debug = os.path.join(lib_dir, "pdb.py")
63 elif o == '-q' or o == '--quiet': printcmd = 0
64 elif o == '-p' or o == '--package': package = a
69 map(os.path.abspath, tests)
71 def find_Test_py(arg, dirname, names):
73 n = filter(lambda n: n[-8:] == "Tests.py", names)
74 tests.extend(map(lambda x,d=dirname: os.path.join(d, x), n))
75 os.path.walk('src', find_Test_py, 0)
77 def find_py(arg, dirname, names):
79 n = filter(lambda n: n[-3:] == ".py", names)
80 tests.extend(map(lambda x,d=dirname: os.path.join(d, x), n))
81 os.path.walk('test', find_py, 0)
94 if not dir.has_key(package):
95 sys.stderr.write("Unknown package '%s'\n" % package)
98 test_dir = os.path.join(cwd, 'build', 'test-%s' % package)
100 scons_dir = os.path.join(test_dir, dir[package], 'bin')
102 lib_dir = os.path.join(test_dir, dir[package], 'lib', 'scons')
106 scons_dir = os.path.join(cwd, 'src', 'script')
108 lib_dir = os.path.join(cwd, 'src', 'engine')
110 os.environ['PYTHONPATH'] = lib_dir + \
112 os.path.join(cwd, 'build', 'etc') + \
114 os.path.join(cwd, 'etc')
122 if os.path.isabs(path):
125 abs = os.path.join(cwd, path)
126 cmd = string.join(["python", debug, abs], " ")
130 if s == 1 or s == 256:
132 elif s == 2 or s == 512:
133 no_result.append(path)
135 print "Unexpected exit status %d" % s
142 str = "%d tests" % len(fail)
143 print "\nFailed the following %s:" % str
144 print "\t", string.join(fail, "\n\t")
146 if len(no_result) == 1:
149 str = "%d tests" % len(no_result)
150 print "\nNO RESULT from the following %s:" % str
151 print "\t", string.join(no_result, "\n\t")
153 sys.exit(len(fail) + len(no_result))