ocarina/tests/Sconscript

65 lines
1.5 KiB
Python

#!/usr/bin/python
import os, subprocess, shutil
import xdg.BaseDirectory
Import("env", "CONFIG")
GOOD = "%s.good"
def run_test(target, source, env):
res = str(target[0])
out = open(res, 'w')
ret = subprocess.call("%s" % source[0], stdout = out, stderr = out)
out.close()
if ret != 0:
print "Test returns: ", ret
if (len(source) == 2) and (ret == 0):
good = str(source[1])
if (subprocess.call("diff -u %s %s" % (good, res), shell = True) != 0):
print
else:
for line in open( str(target[0]) ):
print line.rstrip()
print
def Test(group, src):
name, extension = src.rsplit(".", 1)
lib = SConscript("../../lib/Sconscript")
prog = env.Program("%s.test" % name, [ src ] + lib)
src_files = [ "%s.test" % name ]
if os.path.exists(GOOD % name):
src_files += [ GOOD % name ]
test = Command("%s.run" % name, src_files, run_test)
Depends(test, prog)
AlwaysBuild(test)
Alias("tests", [ prog, test ])
Alias("tests/%s" % group, [ prog, test ])
Alias("tests/%s/%s" % (group, name), [ prog, test ])
Export("Test")
#
# Clean up leftover test data
#
def rm_test_dir(dir):
dir = os.path.join(dir, "ocarina-test")
if os.path.exists(dir):
shutil.rmtree(dir)
rm_test_dir(xdg.BaseDirectory.xdg_config_home);
rm_test_dir(xdg.BaseDirectory.xdg_data_home);
#
# Read SConscript files
#
scripts = [ "print", "file", "database", "index", "filter", "idle", "playlist",
"library", "playqueue", "deck", "audio" ]
for s in scripts:
CONFIG.reset(TEST = True)
SConscript("%s/Sconscript" % s)