ocarina/tests/Sconscript

78 lines
1.6 KiB
Python

#!/usr/bin/python
import sys, os
Import("env")
tests = []
for arg in sys.argv[1:]:
if arg.find("tests") == 0:
tests += [ arg ]
if len(tests) == 0:
Return()
env.Append(CCFLAGS = "-DCONFIG_TEST")
env.UsePackage("glib-2.0")
class UnitTest:
def __init__(self, test, sources):
name = os.path.basename(test)
make = env.Program(name, sources)
run = Command("%s.fake" % name, [], "tests/%s" % test)
Depends(run, make)
Alias("tests/%s" % test, run)
res = UnitTest("sanity", [ "sanity.cpp", "test.cpp" ])
Return("res")
res = []
def all_tests_enabled(dir):
for arg in sys.argv[1:]:
arg = os.path.normpath(arg)
name = os.path.basename(arg)
if (arg.find("tests") == 0) and (name == "tests"):
return True
if (arg.find("tests/%s" % dir) == 0) and (name == dir):
return True
return False
def add_test(test, dir):
global res
if (all_tests_enabled(dir) == True) and (len(res) > 0):
Depends(test, res[-1])
res += [ test ]
def get_test_obj(name, dir):
src = "../../%s/%s.cpp" % (dir, name)
if os.path.exists(src):
return test_env.Object("%s.cpp-%s" % (name, dir), src)
return None
def generic_test(name, dir, objs, extra):
global test_obj;
obj = get_test_obj(name, dir)
test_objs = extra
if obj != None:
objs += [ obj ]
test_objs = extra + objs
exe = test_env.Program(name, [ "%s.cpp" % name, test_lib ] + test_objs)
test = Command("%s.fake" % name, [], "tests/%s/%s" % (dir, name))
Alias("tests/%s/%s" % (dir, name), test)
Depends(test, exe)
add_test(test, dir)
return objs
Export("get_test_obj", "generic_test")
#SConscript("core/Sconscript")
Return("res")