#!/usr/bin/python import sys, os Import("test_env") test_env.UsePackage("glib-2.0") test_env.DEBUG = True if test_env.Coverage == True: test_env.Append( CCFLAGS = [ "--coverage" ] ) test_env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] ) check_depends = True for arg in sys.argv: if arg.find("tests/core") == 0 and len(arg) > 11: check_depends = False break if arg.find("tests/lib") == 0 and len(arg) > 10: check_depends = False break valgrind = "valgrind -q --leak-check=full --error-exitcode=42" gcov = "gcov -r tests/%s/*.gcda" class OTest: Prev = None Env = test_env def __init__(self, src, pkg = None): self.Name = src.rsplit(".")[0] self.Src = src if pkg != None: test_env.UsePackage(pkg) def get_program(self): return test_env.Program(self.Name, self.Src) def prepare(self, subdir): prog = self.get_program() path = "./tests/%s/%s" % (subdir, self.Name) cmd = "%s | tee %s.out" % (path, path) if test_env.Valgrind == True: cmd = "%s %s" % (valgrind, cmd) test = test_env.Command("%s.out" % self.Name, [], "set -x; set -o pipefail; %s" % cmd) Depends(test, prog) if (check_depends == True) and (OTest.Prev != None): Depends(test, OTest.Prev) Alias("tests/%s" % subdir, test) Alias("tests/%s/%s" % (subdir, self.Name), test) AlwaysBuild(test) OTest.Prev = test return test class TestList: def __init__(self, subdir, tests): self.subdir = subdir self.tests = tests f = open(".gitignore", "w") for t in tests: f.write(t.Name + "\n") f.close() def prepare(self): res = [] for t in self.tests: res += [ t.prepare(self.subdir) ] if test_env.Coverage == True: res += [ Command("%s.gcov" % self.subdir, [], gcov % self.subdir) ] Depends(res[len(res) - 1], res[len(res) - 2]) AlwaysBuild(res[len(res) - 1]) return res Export("OTest", "TestList") core = SConscript("core/Sconscript") lib = SConscript("lib/Sconscript") res = [ core, lib ] if test_env.CppCheck == True: res += [ Command("cpp.check", [], "cppcheck -q --error-exitcode=42 .") ] Depends(res[len(res) - 1], res[len(res) - 2]) Return("res")