Value-parameterized tests and many bugfixes
This commit is contained in:
@@ -67,7 +67,7 @@ to the following:
|
||||
|
||||
# Build gtest library; as it is outside of our source root, we need to
|
||||
# tell SCons that the directory it will refer to as
|
||||
# e.g. $BUIlD_DIR/gtest is actually on disk in original form as
|
||||
# e.g. $BUILD_DIR/gtest is actually on disk in original form as
|
||||
# ../../gtest (relative to your project root directory). Recall that
|
||||
# SCons by default copies all source files into the build directory
|
||||
# before building.
|
||||
@@ -102,11 +102,6 @@ env = env.Clone()
|
||||
env.Prepend(CPPPATH = ['..',
|
||||
'../include'])
|
||||
|
||||
# TODO(joi@google.com) Fix the code that causes this warning so that
|
||||
# we see all warnings from the compiler about possible 64-bit porting
|
||||
# issues.
|
||||
env.Append(CCFLAGS=['-wd4267'])
|
||||
|
||||
# Sources shared by base library and library that includes main.
|
||||
gtest_sources = ['../src/gtest-all.cc']
|
||||
|
||||
@@ -125,6 +120,23 @@ if 'LIB_OUTPUT' in env.Dictionary():
|
||||
env.Install('$LIB_OUTPUT', source=[gtest, gtest_main])
|
||||
|
||||
|
||||
def GtestBinary(env, target, dir_prefix, gtest_lib, additional_sources=None):
|
||||
"""Helper to create gtest binaries: tests, samples, etc.
|
||||
|
||||
Args:
|
||||
env: The SCons construction environment to use to build.
|
||||
target: The basename of the target's main source file, also used as target
|
||||
name.
|
||||
dir_prefix: The path to prefix the main source file.
|
||||
gtest_lib: The gtest lib to use.
|
||||
"""
|
||||
source = [env.File('%s.cc' % target, env.Dir(dir_prefix))]
|
||||
if additional_sources:
|
||||
source += additional_sources
|
||||
unit_test = env.Program(target=target, source=source, LIBS=[gtest_lib])
|
||||
if 'EXE_OUTPUT' in env.Dictionary():
|
||||
env.Install('$EXE_OUTPUT', source=[unit_test])
|
||||
|
||||
def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
|
||||
"""Helper to create gtest unit tests.
|
||||
|
||||
@@ -133,15 +145,7 @@ def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
|
||||
target: The basename of the target unit test .cc file.
|
||||
gtest_lib: The gtest lib to use.
|
||||
"""
|
||||
source = [env.File('%s.cc' % target, env.Dir('../test'))]
|
||||
if additional_sources:
|
||||
source += additional_sources
|
||||
unit_test = env.Program(target=target,
|
||||
source=source,
|
||||
LIBS=[gtest_lib, 'kernel32.lib', 'user32.lib'])
|
||||
if 'EXE_OUTPUT' in env.Dictionary():
|
||||
env.Install('$EXE_OUTPUT', source=[unit_test])
|
||||
|
||||
GtestBinary(env, target, "../test", gtest_lib, additional_sources)
|
||||
|
||||
GtestUnitTest(env, 'gtest-filepath_test', gtest_main)
|
||||
GtestUnitTest(env, 'gtest-message_test', gtest_main)
|
||||
@@ -157,9 +161,13 @@ GtestUnitTest(env, 'gtest_sole_header_test', gtest_main)
|
||||
GtestUnitTest(env, 'gtest-test-part_test', gtest_main)
|
||||
GtestUnitTest(env, 'gtest-typed-test_test', gtest_main,
|
||||
additional_sources=['../test/gtest-typed-test2_test.cc'])
|
||||
GtestUnitTest(env, 'gtest-param-test_test', gtest,
|
||||
additional_sources=['../test/gtest-param-test2_test.cc'])
|
||||
GtestUnitTest(env, 'gtest_unittest', gtest)
|
||||
GtestUnitTest(env, 'gtest_output_test_', gtest)
|
||||
GtestUnitTest(env, 'gtest_color_test_', gtest)
|
||||
GtestUnitTest(env, 'gtest-linked_ptr_test', gtest_main)
|
||||
GtestUnitTest(env, 'gtest-port_test', gtest_main)
|
||||
|
||||
# TODO(wan@google.com) Add these unit tests:
|
||||
# - gtest_break_on_failure_unittest_
|
||||
@@ -179,3 +187,33 @@ for flag in ["/O1", "/Os", "/Og", "/Oy"]:
|
||||
linker_flags.remove(flag)
|
||||
GtestUnitTest(special_env, 'gtest_env_var_test_', gtest)
|
||||
GtestUnitTest(special_env, 'gtest_uninitialized_test_', gtest)
|
||||
|
||||
def GtestSample(env, target, gtest_lib, additional_sources=None):
|
||||
"""Helper to create gtest samples.
|
||||
|
||||
Args:
|
||||
env: The SCons construction environment to use to build.
|
||||
target: The basename of the target unit test .cc file.
|
||||
gtest_lib: The gtest lib to use.
|
||||
"""
|
||||
GtestBinary(env, target, "../samples", gtest_lib, additional_sources)
|
||||
|
||||
# Use the GTEST_BUILD_SAMPLES build variable to control building of samples.
|
||||
# In your SConstruct file, add
|
||||
# vars = Variables()
|
||||
# vars.Add(BoolVariable('GTEST_BUILD_SAMPLES', 'Build samples', True))
|
||||
# my_environment = Environment(variables = vars, ...)
|
||||
# Then, in the command line use GTEST_BUILD_SAMPLES=true to enable them.
|
||||
#
|
||||
if env.get('GTEST_BUILD_SAMPLES', False):
|
||||
sample1_obj = env.Object('../samples/sample1.cc')
|
||||
GtestSample(env, 'sample1_unittest', gtest_main,
|
||||
additional_sources=[sample1_obj])
|
||||
GtestSample(env, 'sample2_unittest', gtest_main,
|
||||
additional_sources=['../samples/sample2.cc'])
|
||||
GtestSample(env, 'sample3_unittest', gtest_main)
|
||||
GtestSample(env, 'sample5_unittest', gtest_main,
|
||||
additional_sources=[sample1_obj])
|
||||
GtestSample(env, 'sample6_unittest', gtest_main)
|
||||
GtestSample(env, 'sample7_unittest', gtest_main)
|
||||
GtestSample(env, 'sample8_unittest', gtest_main)
|
||||
|
||||
Reference in New Issue
Block a user