+# FIXME: the following is necessary to pull in half of the testing
+# harness from $srcdir/etc. Those modules should be transfered
+# to QMTest/ once we completely cut over to using that as
+# the harness, in which case this manipulation of PYTHONPATH
+# should be able to go away.
+pythonpaths = [ pythonpath_dir ]
+
+for dir in sp:
+ if format == '--aegis':
+ q = os.path.join(dir, 'build', 'QMTest')
+ else:
+ q = os.path.join(dir, 'QMTest')
+ pythonpaths.append(q)
+
+os.environ['SCONS_SOURCE_PATH_EXECUTABLE'] = os.pathsep.join(spe)
+
+os.environ['PYTHONPATH'] = os.pathsep.join(pythonpaths)
+
+if old_pythonpath:
+ os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + \
+ os.pathsep + \
+ old_pythonpath
+
+tests = []
+
+def find_Tests_py(tdict, dirname, names):
+ for n in [n for n in names if n[-8:] == "Tests.py"]:
+ tdict[os.path.join(dirname, n)] = 1
+
+def find_py(tdict, dirname, names):
+ tests = [n for n in names if n[-3:] == ".py"]
+ try:
+ excludes = open(os.path.join(dirname,".exclude_tests")).readlines()
+ except (OSError, IOError):
+ pass
+ else:
+ for exclude in excludes:
+ exclude = exclude.split('#' , 1)[0]
+ exclude = exclude.strip()
+ if not exclude: continue
+ tests = [n for n in tests if n != exclude]
+ for n in tests:
+ tdict[os.path.join(dirname, n)] = 1
+
+if args:
+ if spe:
+ for a in args:
+ if os.path.isabs(a):
+ tests.extend(glob.glob(a))
+ else:
+ for dir in spe:
+ x = os.path.join(dir, a)
+ globs = glob.glob(x)
+ if globs:
+ tests.extend(globs)
+ break
+ else:
+ for a in args:
+ for path in glob.glob(a):
+ if os.path.isdir(path):
+ tdict = {}
+ if path[:3] == 'src':
+ os.path.walk(path, find_Tests_py, tdict)
+ elif path[:4] == 'test':
+ os.path.walk(path, find_py, tdict)
+ tests.extend(sorted(tdict.keys()))
+ else:
+ tests.append(path)
+elif testlistfile:
+ tests = open(testlistfile, 'r').readlines()
+ tests = [x for x in tests if x[0] != '#']
+ tests = [x[:-1] for x in tests]
+elif all and not qmtest:
+ # Find all of the SCons functional tests in the local directory
+ # tree. This is anything under the 'src' subdirectory that ends
+ # with 'Tests.py', or any Python script (*.py) under the 'test'
+ # subdirectory.
+ #
+ # Note that there are some tests under 'src' that *begin* with
+ # 'test_', but they're packaging and installation tests, not
+ # functional tests, so we don't execute them by default. (They can
+ # still be executed by hand, though, and are routinely executed
+ # by the Aegis packaging build to make sure that we're building
+ # things correctly.)
+ tdict = {}
+ os.path.walk('src', find_Tests_py, tdict)
+ os.path.walk('test', find_py, tdict)
+ if format == '--aegis' and aegis:
+ cmd = "aegis -list -unf pf 2>/dev/null"
+ for line in os.popen(cmd, "r").readlines():
+ a = line.split()
+ if a[0] == "test" and a[-1] not in tdict:
+ tdict[a[-1]] = Test(a[-1], spe)
+ cmd = "aegis -list -unf cf 2>/dev/null"
+ for line in os.popen(cmd, "r").readlines():
+ a = line.split()
+ if a[0] == "test":
+ if a[1] == "remove":
+ del tdict[a[-1]]
+ elif a[-1] not in tdict:
+ tdict[a[-1]] = Test(a[-1], spe)
+
+ tests = sorted(tdict.keys())
+
+if qmtest:
+ if baseline:
+ aegis_result_stream = 'scons_tdb.AegisBaselineStream'
+ qmr_file = 'baseline.qmr'
+ else:
+ aegis_result_stream = 'scons_tdb.AegisChangeStream'
+ qmr_file = 'results.qmr'
+
+ if print_times:
+ aegis_result_stream = aegis_result_stream + "(print_time='1')"
+
+ qmtest_args = [ qmtest, ]
+
+ if format == '--aegis':
+ dir = builddir
+ if not os.path.isdir(dir):
+ dir = cwd
+ qmtest_args.extend(['-D', dir])
+
+ qmtest_args.extend([
+ 'run',
+ '--output %s' % qmr_file,
+ '--format none',
+ '--result-stream="%s"' % aegis_result_stream,
+ ])
+
+ if python:
+ qmtest_args.append('--context python="%s"' % python)
+
+ if outputfile:
+ if format == '--xml':
+ rsclass = 'scons_tdb.SConsXMLResultStream'
+ else:
+ rsclass = 'scons_tdb.AegisBatchStream'
+ qof = "r'" + outputfile + "'"
+ rs = '--result-stream="%s(filename=%s)"' % (rsclass, qof)
+ qmtest_args.append(rs)
+
+ if format == '--aegis':
+ tests = [x.replace(cwd+os.sep, '') for x in tests]
+ else:
+ os.environ['SCONS'] = os.path.join(cwd, 'src', 'script', 'scons.py')
+
+ cmd = ' '.join(qmtest_args + tests)
+ if printcommand:
+ sys.stdout.write(cmd + '\n')
+ sys.stdout.flush()
+ status = 0
+ if execute_tests:
+ status = os.WEXITSTATUS(os.system(cmd))
+ sys.exit(status)
+
+#try:
+# os.chdir(scons_script_dir)
+#except OSError:
+# pass
+
+tests = list(map(Test, tests))