tests: Create common functions for building tests

This continues to simplify my Sconscript files.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-01 14:39:30 -04:00
parent 89498ccc9e
commit 97733aa40a
3 changed files with 50 additions and 91 deletions

View File

@ -22,6 +22,46 @@ for arg in sys.argv:
valgrind = "valgrind -q --leak-check=full --error-exitcode=42"
gcov = "gcov -r tests/%s/*.gcda"
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):
obj = get_test_obj(name, dir)
if obj != None:
objs += [ obj ]
test_objs = extra + objs
else:
test_objs = extra
exe = test_env.Program(name, [ "%s.cpp" % name ] + 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
class OTest:
@ -78,12 +118,13 @@ class TestList:
return res
Export("OTest", "TestList")
Export("get_test_obj", "generic_test")
core = SConscript("core/Sconscript")
lib = SConscript("lib/Sconscript")
res = [ core, lib ]
#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])

View File

@ -1,50 +1,12 @@
#!/usr/bin/python
Import("test_env", "generic_test", "get_test_obj")
import sys, os
Import("test_env")
all = False
for arg in sys.argv[1:]:
arg = os.path.normpath(arg)
name = os.path.basename(arg)
if (arg.find("tests") == 0) and (name == "tests"):
all = True
if (arg.find("tests/core") == 0) and (name == "core"):
all = True
res = []
objs = []
def get_core_obj(name):
global objs
if not os.path.exists("../../core/%s.cpp" % name):
return []
objs += test_env.Object("%s.cpp-core" % name, "../../core/%s.cpp" % name)
return objs
def add_test(test):
global all
global res
if (all == True) and (len(res) > 0):
Depends(test, res[-1])
res += [ test ]
def test(name):
extra = get_core_obj(name)
exe = test_env.Program(name, [ "%s.cpp" % name ] + extra)
test = Command("%s.fake" % name, [], "tests/core/%s" % name);
Alias("tests/core/%s" % name, test)
Depends(test, exe)
add_test(test)
global objs
objs = generic_test(name, "core", objs, [])
###
#
# Test configuration starts here
#
test( "version" )
test( "file" )
test( "database" )
@ -56,13 +18,10 @@ test_env.UsePackage("taglib")
test( "tags" )
test( "random" )
get_core_obj("callback")
objs += [ get_test_obj("callback", "core") ]
test( "queue" )
test( "library" )
test( "playlist" )
test( "deck" )
test( "driver" )
test( "audio" )
Return("res")

View File

@ -1,18 +1,7 @@
#!/usr/bin/python
import os
Import("test_env", "generic_test")
import sys, os
Import("test_env")
all = False
for arg in sys.argv[1:]:
arg = os.path.normpath(arg)
name = os.path.basename(arg)
if (arg.find("tests") == 0) and (name == "tests"):
all = True
if (arg.find("tests/lib") == 0) and (name == "lib"):
all = True
res = []
objs = []
core = []
@ -20,43 +9,13 @@ for f in Glob("../../core/*.cpp"):
f = str(f)
core += [ test_env.Object("%s-core" % os.path.basename(f), f) ]
def get_lib_obj(name):
global objs
if not os.path.exists("../../lib/%s.cpp" % name):
return []
objs += test_env.Object("%s.cpp-lib" % name, "../../lib/%s.cpp" % name)
return objs
def add_test(test):
global all
global res
if (all == True) and (len(res) > 0):
Depends(test, res[-1])
res += [ test ]
def test(name):
global core
extra = get_lib_obj(name)
exe = test_env.Program(name, [ "%s.cpp" % name ] + extra + core)
test = Command("%s.fake" % name, [], "tests/lib/%s" % name);
Alias("tests/lib/%s" % name, test)
Depends(test, exe)
add_test(test)
global core, objs
objs = generic_test(name, "lib", objs, core)
###
#
# Test configuration starts here
#
test( "lib" )
test_env.UsePackage("gtkmm-3.0")
test( "colmgr" )
test( "model" )
Return("res")