summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@10gen.com>2012-06-01 15:26:04 -0400
committerAndy Schwerin <schwerin@10gen.com>2012-06-04 13:08:27 -0400
commit82544c7d08c033184104a5c9ab115e4047fdbdbd (patch)
tree69c66e59f3b8f07d464589b802a85271f692b70e /site_scons
parentc04922ad14ebe43d99ba056b7b3ae79860b8cd91 (diff)
downloadmongo-82544c7d08c033184104a5c9ab115e4047fdbdbd.tar.gz
SERVER-5702: Add ability to register unit tests in SCons.
Tests are registered with env.RegisterUnitTest(), or by compiling a C++ unit test with env.CppUnitTest('test_name', [test_source_list], LIBDEPS=[...]) The result is that SCons knows how to build a file "build/unittests.txt", one line per test.
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/site_tools/unittest.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/site_scons/site_tools/unittest.py b/site_scons/site_tools/unittest.py
new file mode 100644
index 00000000000..0ce0ae582c1
--- /dev/null
+++ b/site_scons/site_tools/unittest.py
@@ -0,0 +1,33 @@
+"""Pseudo-builders for building and registering unit tests.
+"""
+
+def exists(env):
+ return True
+
+def register_unit_test(env, test):
+ env._UnitTestList('$UNITTEST_LIST', test)
+ env.Alias('$UNITTEST_ALIAS', test)
+
+def unit_test_list_builder_action(env, target, source):
+ print "Generating " + str(target[0])
+ ofile = open(str(target[0]), 'wb')
+ try:
+ for s in source:
+ print '\t' + str(s)
+ ofile.write('%s\n' % s)
+ finally:
+ ofile.close()
+
+def build_cpp_unit_test(env, target, source, **kwargs):
+ kwargs['LIBDEPS'] = kwargs.get('LIBDEPS', []) + ['$BUILD_DIR/mongo/unittest/unittest_main',
+ '$BUILD_DIR/mongo/unittest/unittest_crutch']
+ result = env.Program(target, source, **kwargs)
+ env.RegisterUnitTest(result[0])
+ return result
+
+def generate(env):
+ unit_test_list_builder = env.Builder(action=unit_test_list_builder_action, multi=True)
+ env.Append(BUILDERS=dict(_UnitTestList=unit_test_list_builder))
+ env.AddMethod(register_unit_test, 'RegisterUnitTest')
+ env.AddMethod(build_cpp_unit_test, 'CppUnitTest')
+ env.Alias('$UNITTEST_ALIAS', '$UNITTEST_LIST')