SConsTest 1.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
import os

def test_build_function (target, source, env):
	return None 

def test_emitter (target, source, env):
	env.Append (TESTTARGETS = source)
	return target, source

test_bld = Builder(action = test_build_function, emitter = test_emitter,
		suffix = '.test')

def check_build_one (source, env):
	ret = env.Execute (source.abspath)
	if ret == 0:
		print "PASS: %s" % source
	else:
		print "FAIL: %s" % source
	return ret

def check_pretty_print (s):
	l = len(s)
	print '=' * l
	print s
	print '=' * l

def check_build_function (target, source, env):
	nr_success = 0
	nr_fail = 0
	t = env.Dictionary('TESTTARGETS')
	for s in t:
		ret = check_build_one (s, env)
		if ret == 0:
			nr_success += 1
		else:
			nr_fail += 1
	if nr_fail == 0:
		check_pretty_print ("All %d tests passed" % (nr_success))
		return 0
	else:
		check_pretty_print ("%d of %d tests failed" %
			(nr_fail, nr_fail + nr_success))
		return 1


check_bld = Builder (action = check_build_function,
		suffix = '.check', src_suffix = ".test")

def enable_test (env):
	env.Append(BUILDERS = {'Test' : test_bld})
	env.Append(BUILDERS = {'Check' : check_bld})
	check_target = env.Check ('#/scons/phony.test')
	AlwaysBuild (check_target)
	env.Alias ('check', check_target)

Export ('enable_test')