2 import SCons.Script.SConscript
10 # ARGH ... Why do they put a '+' in the module name ????????
11 SCons.Tool.cplusplus=getattr(__import__('SCons.Tool.c++', globals(), locals(), []).Tool, 'c++')
21 if line.startswith('COMPILE_FAIL(') and ')' in line:
22 name = line.split('(',1)[-1].split(')',1)[0]
24 elif line.startswith('}') and name and start:
25 tests[name] = (start, linenr)
28 def CompileCheck(target, source, env):
29 tests = scanTests(file(source[0].abspath))
31 cenv.Append( CPPDEFINES = [ 'COMPILE_CHECK' ] )
32 out = tempfile.TemporaryFile()
33 cenv['SPAWN'] = lambda sh, escape, cmd, args, env, pspawn=cenv['PSPAWN'], out=out: \
34 pspawn(sh, escape, cmd, args, env, out, out)
35 SCons.Script.Action('$CXXCOM').execute(target, source, cenv)
40 for error in result.splitlines():
41 elts = error.split(':',2)
42 if len(elts) != 3 : continue
43 filename, line, message = elts
44 if not os.path.exists(filename) : continue
46 except ValueError : continue
47 message = message.strip()
49 if delay_name and not message.startswith('instantiated from '):
50 print "Passed test '%s': %s" % (delay_name, message)
54 filename = os.path.abspath(filename)
55 if filename != source[0].abspath : continue
57 for name,lines in tests.iteritems():
58 if line >= lines[0] and line <= lines[1]:
60 if message.startswith('instantiated from '):
63 print "Passed test '%s': %s" % (name, message)
65 print "Passed test '%s': <unknown message ??>" % delay_name
66 failedTests = set(tests.iterkeys()) - set(passedTests.iterkeys())
68 for test in failedTests:
69 print "Test '%s' FAILED" % test
71 print "*** %d tests FAILED" % len(failedTests)
72 if os.path.exists(target[0].abspath):
73 os.unlink(target[0].abspath)
75 file(target[0].abspath,"w").write(result)
78 CompileCheck = SCons.Script.Action(CompileCheck)
80 def BoostUnitTest(env, target=None, source=None, **kw):
83 target = env.arg2nodes(target)[0]
84 source = env.arg2nodes(source)
86 binnode = target.dir.File('.' + target.name + '.bin')
87 stampnode = target.dir.File('.' + target.name + '.stamp')
89 bin = env.Program(binnode, source,
90 LIBS = env['LIBS'] + [ '$TEST_EXTRA_LIBS' ],
91 _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ' + env['_LIBFLAGS'],
94 stamp = env.Command(stampnode, bin,
95 [ './$SOURCE $BOOSTTESTARGS', SCons.Script.Touch('$TARGET')],
98 alias = env.Command(env.File(target), stamp, [ env.NopAction() ] )
100 compileTests = [ src for src in source
101 if src.suffix in SCons.Tool.cplusplus.CXXSuffixes \
103 and 'COMPILE_CHECK' in file(str(src)).read() ]
105 env.Depends(alias, env.CompileCheck(source = compileTests))
107 _ALL_TESTS.append(alias)
111 def FindAllBoostUnitTests(env, target, source):
115 def NopAction(env, target, source):
116 def nop(target, source, env) : return None
117 def nopstr(target, source, env) : return ''
118 return env.Action(nop, nopstr)
123 _BOOST_VARIANT = '${BOOST_VARIANT and "-" or None}$BOOST_VARIANT',
125 BOOSTTESTLIB = 'boost_unit_test_framework$_BOOST_VARIANT',
126 BOOSTREGEXLIB = 'boost_regex$_BOOST_VARIANT',
127 BOOSTFSLIB = 'boost_filesystem$_BOOST_VARIANT',
128 BOOSTIOSTREAMSLIB = 'boost_iostreams$_BOOST_VARIANT',
129 BOOSTSIGNALSLIB = 'boost_signals$_BOOST_VARIANT',
131 BOOSTTESTARGS = [ '--build_info=yes', '--log_level=test_suite' ],
134 env['BUILDERS']['BoostUnitTest'] = BoostUnitTest
135 env['BUILDERS']['FindAllBoostUnitTests'] = FindAllBoostUnitTests
136 env['BUILDERS']['CompileCheck'] = env.Builder(
137 action = CompileCheck,
140 source_scanner = SCons.Scanner.C.CScanner(),
143 env['BUILDERS']['NopAction'] = NopAction