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):
82 target = env.arg2nodes(target)[0]
83 source = env.arg2nodes(source)
85 binnode = target.dir.File('.' + target.name + '.bin')
86 stampnode = target.dir.File('.' + target.name + '.stamp')
88 bin = env.Program(binnode, source,
89 LIBS = env['LIBS'] + [ '$TEST_EXTRA_LIBS' ],
90 _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ' + env['_LIBFLAGS'],
93 stamp = env.Command(stampnode, bin,
94 [ './$SOURCE $BOOSTTESTARGS', SCons.Script.Touch('$TARGET')],
97 alias = env.Command(env.File(target), stamp, [ env.NopAction() ] )
99 compileTests = [ src for src in source
100 if src.suffix in SCons.Tool.cplusplus.CXXSuffixes \
102 and 'COMPILE_CHECK' in file(str(src)).read() ]
104 env.Depends(alias, env.CompileCheck(source = compileTests))
106 _ALL_TESTS.append(alias)
110 def FindAllBoostUnitTests(env, target, source):
114 def NopAction(env, target, source):
115 def nop(target, source, env) : return None
116 def nopstr(target, source, env) : return ''
117 return env.Action(nop, nopstr)
123 BOOSTTESTLIB = 'boost_unit_test_framework$BOOST_VARIANT',
124 BOOSTREGEXLIB = 'boost_regex$BOOST_VARIANT',
125 BOOSTFSLIB = 'boost_filesystem$BOOST_VARIANT',
126 BOOSTIOSTREAMSLIB = 'boost_iostreams$BOOST_VARIANT',
127 BOOSTSIGNALSLIB = 'boost_signals$BOOST_VARIANT',
129 BOOSTTESTARGS = [ '--build_info=yes', '--log_level=test_suite' ],
132 env['BUILDERS']['BoostUnitTest'] = BoostUnitTest
133 env['BUILDERS']['FindAllBoostUnitTests'] = FindAllBoostUnitTests
134 env['BUILDERS']['CompileCheck'] = env.Builder(
135 action = CompileCheck,
138 source_scanner = SCons.Scanner.C.CScanner(),
141 env['BUILDERS']['NopAction'] = NopAction