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)
39 for error in out.read().splitlines():
40 elts = error.split(':',2)
41 if len(elts) != 3 : continue
42 filename, line, message = elts
43 if not os.path.exists(filename) : continue
45 except ValueError : continue
46 message = message.strip()
48 if delay_name and not message.startswith('instantiated from '):
49 print "Passed test '%s': %s" % (delay_name, message)
53 filename = os.path.abspath(filename)
54 if filename != source[0].abspath : continue
56 for name,lines in tests.iteritems():
57 if line >= lines[0] and line <= lines[1]:
59 if message.startswith('instantiated from '):
62 print "Passed test '%s': %s" % (name, message)
64 print "Passed test '%s': <unknown message ??>" % delay_name
65 failedTests = set(tests.iterkeys()) - set(passedTests.iterkeys())
67 for test in failedTests:
68 print "Test '%s' FAILED" % test
70 print "*** %d tests FAILED" % len(failedTests)
71 if os.path.exists(target[0].abspath):
72 os.unlink(target[0].abspath)
74 file(target[0].abspath,"w").close()
77 CompileCheck = SCons.Script.Action(CompileCheck)
79 def BoostUnitTest(env, target=None, source=None, **kw):
80 target = env.arg2nodes(target)[0]
81 source = env.arg2nodes(source)
83 binnode = target.dir.File('.' + target.name + '.bin')
84 stampnode = target.dir.File('.' + target.name + '.stamp')
86 bin = env.Program(binnode, source,
87 LIBS = env['LIBS'] + [ '$TEST_EXTRA_LIBS' ],
88 _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ' + env['_LIBFLAGS'],
91 stamp = env.Command(stampnode, bin,
92 [ '$SOURCE $BOOSTTESTARGS', SCons.Script.Touch('$TARGET')],
95 alias = env.Command(env.File(target), stamp, [ env.NopAction() ] )
97 compileTests = [ src for src in source
98 if src.suffix in SCons.Tool.cplusplus.CXXSuffixes \
100 and 'COMPILE_CHECK' in file(str(src)).read() ]
102 env.Depends(alias, env.CompileCheck(source = compileTests))
104 _ALL_TESTS.append(alias)
108 def FindAllBoostUnitTests(env, target, source):
111 def NopAction(env, target, source):
112 def nop(target, source, env) : return None
113 def nopstr(target, source, env) : return ''
114 return env.Action(nop, nopstr)
120 BOOSTTESTLIB = 'boost_unit_test_framework$BOOST_VARIANT',
121 BOOSTREGEXLIB = 'boost_regex$BOOST_VARIANT',
122 BOOSTFSLIB = 'boost_filesystem$BOOST_VARIANT',
123 BOOSTIOSTREAMSLIB = 'boost_iostreams$BOOST_VARIANT',
124 BOOSTSIGNALSLIB = 'boost_signals$BOOST_VARIANT',
126 BOOSTTESTARGS = [ '--build_info=yes', '--log_level=test_suite' ],
129 env['BUILDERS']['BoostUnitTest'] = BoostUnitTest
130 env['BUILDERS']['FindAllBoostUnitTests'] = FindAllBoostUnitTests
131 env['BUILDERS']['CompileCheck'] = env.Builder(
132 action = CompileCheck,
135 source_scanner = SCons.Scanner.C.CScanner(),
138 env['BUILDERS']['NopAction'] = NopAction