diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-06-01 15:26:04 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-06-04 13:08:27 -0400 |
commit | 82544c7d08c033184104a5c9ab115e4047fdbdbd (patch) | |
tree | 69c66e59f3b8f07d464589b802a85271f692b70e | |
parent | c04922ad14ebe43d99ba056b7b3ae79860b8cd91 (diff) | |
download | mongo-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.
-rw-r--r-- | SConstruct | 6 | ||||
-rw-r--r-- | site_scons/site_tools/unittest.py | 33 | ||||
-rw-r--r-- | src/mongo/unittest/SConscript | 6 |
3 files changed, 40 insertions, 5 deletions
diff --git a/SConstruct b/SConstruct index 5080ac6abca..32f34dc1e21 100644 --- a/SConstruct +++ b/SConstruct @@ -290,7 +290,9 @@ env = Environment( BUILD_DIR=variantDir, PYTHON=utils.find_python(), SERVER_ARCHIVE='${SERVER_DIST_BASENAME}${DIST_ARCHIVE_SUFFIX}', TARGET_ARCH=msarch , - tools=["default", "gch", "jsheader", "mergelib"], + tools=["default", "gch", "jsheader", "mergelib", "unittest"], + UNITTEST_ALIAS='unittests', + UNITTEST_LIST='#build/unittests.txt', PYSYSPLATFORM=os.sys.platform, PCRE_VERSION='8.30', @@ -1085,4 +1087,4 @@ def clean_old_dist_builds(env, target, source): env.Alias("dist_clean", [], [clean_old_dist_builds]) env.AlwaysBuild("dist_clean") -env.Alias('all', ['core', 'tools', 'clientTests', 'test', 'unittests']) +env.Alias('all', ['core', 'tools', 'clientTests', 'test', '$UNITTEST_ALIAS']) 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') diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript index 43a945fe7ad..43eaf408862 100644 --- a/src/mongo/unittest/SConscript +++ b/src/mongo/unittest/SConscript @@ -10,6 +10,6 @@ env.StaticLibrary("unittest_main", ['unittest_main.cpp'], env.StaticLibrary("unittest_crutch", ['crutch.cpp']) -env.Alias('unittests', - env.Program('unittest_test', 'unittest_test.cpp', - LIBDEPS=['unittest_main', 'unittest_crutch']) + +env.CppUnitTest('unittest_test', 'unittest_test.cpp') + |