From bcf926ec656688d7eb03159faaddbf56bd4ec8e2 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 13 Nov 2009 02:54:23 +0000 Subject: Improves the scons scripts and run_tests.py (by Vlad Losev); uses typed tests in gtest-port_test.cc only when typed tests are available (by Zhanyong Wan); makes gtest-param-util-generated.h conform to the C++ standard (by Zhanyong Wan). --- .../gtest/internal/gtest-param-util-generated.h | 15 ++++++ .../internal/gtest-param-util-generated.h.pump | 15 ++++++ run_tests.py | 23 +++++---- scons/SConscript | 57 +++++++++++----------- scons/SConstruct.common | 6 +-- test/gtest-port_test.cc | 4 ++ test/run_tests_test.py | 6 +-- 7 files changed, 80 insertions(+), 46 deletions(-) diff --git a/include/gtest/internal/gtest-param-util-generated.h b/include/gtest/internal/gtest-param-util-generated.h index 04f4c3a..ab4ab56 100644 --- a/include/gtest/internal/gtest-param-util-generated.h +++ b/include/gtest/internal/gtest-param-util-generated.h @@ -53,6 +53,21 @@ #if GTEST_HAS_PARAM_TEST namespace testing { + +// Forward declarations of ValuesIn(), which is implemented in +// include/gtest/gtest-param-test.h. +template +internal::ParamGenerator< + typename ::std::iterator_traits::value_type> ValuesIn( + ForwardIterator begin, ForwardIterator end); + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]); + +template +internal::ParamGenerator ValuesIn( + const Container& container); + namespace internal { // Used in the Values() function to provide polymorphic capabilities. diff --git a/include/gtest/internal/gtest-param-util-generated.h.pump b/include/gtest/internal/gtest-param-util-generated.h.pump index 8cfcf0b..baedfbc 100644 --- a/include/gtest/internal/gtest-param-util-generated.h.pump +++ b/include/gtest/internal/gtest-param-util-generated.h.pump @@ -54,6 +54,21 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. #if GTEST_HAS_PARAM_TEST namespace testing { + +// Forward declarations of ValuesIn(), which is implemented in +// include/gtest/gtest-param-test.h. +template +internal::ParamGenerator< + typename ::std::iterator_traits::value_type> ValuesIn( + ForwardIterator begin, ForwardIterator end); + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]); + +template +internal::ParamGenerator ValuesIn( + const Container& container); + namespace internal { // Used in the Values() function to provide polymorphic capabilities. diff --git a/run_tests.py b/run_tests.py index 67014f3..6f11bc2 100755 --- a/run_tests.py +++ b/run_tests.py @@ -50,7 +50,7 @@ OPTIONS Specify build directories via build configurations. CONFIGURATIONS is either a comma-separated list of build configurations or 'all'. Each configuration is equivalent to - adding 'scons/build//scons' to BUILD_DIRs. + adding 'scons/build//gtest/scons' to BUILD_DIRs. Specifying -c=all is equivalent to providing all directories listed in KNOWN BUILD DIRECTORIES section below. @@ -98,16 +98,16 @@ KNOWN BUILD DIRECTORIES defines them as follows (the default build directory is the first one listed in each group): On Windows: - /scons/build/win-dbg8/scons/ - /scons/build/win-opt8/scons/ - /scons/build/win-dbg/scons/ - /scons/build/win-opt/scons/ + /scons/build/win-dbg8/gtest/scons/ + /scons/build/win-opt8/gtest/scons/ + /scons/build/win-dbg/gtest/scons/ + /scons/build/win-opt/gtest/scons/ On Mac: - /scons/build/mac-dbg/scons/ - /scons/build/mac-opt/scons/ + /scons/build/mac-dbg/gtest/scons/ + /scons/build/mac-opt/gtest/scons/ On other platforms: - /scons/build/dbg/scons/ - /scons/build/opt/scons/ + /scons/build/dbg/gtest/scons/ + /scons/build/opt/gtest/scons/ AUTHOR Written by Zhanyong Wan (wan@google.com) @@ -177,7 +177,10 @@ class TestRunner(object): """Returns the build directory for a given configuration.""" return self.os.path.normpath( - self.os.path.join(self.script_dir, 'scons/build', config, 'scons')) + self.os.path.join(self.script_dir, + 'scons/build', + config, + 'gtest/scons')) def Run(self, args): """Runs the executable with given args (args[0] is the executable name). diff --git a/scons/SConscript b/scons/SConscript index e1ccb7e..25220ee 100644 --- a/scons/SConscript +++ b/scons/SConscript @@ -99,34 +99,34 @@ Import('env') env = env.Clone() BUILD_TESTS = env.get('GTEST_BUILD_TESTS', False) -if BUILD_TESTS: - common_exports = SConscript('SConscript.common') - EnvCreator = common_exports['EnvCreator'] +common_exports = SConscript('SConscript.common') +EnvCreator = common_exports['EnvCreator'] # Note: The relative paths in SConscript files are relative to the location # of the SConscript file itself. To make a path relative to the location of # the main SConstruct file, prepend the path with the # sign. # -# But if a project uses variant builds without source duplication, the above -# rule gets muddied a bit. In that case the paths must be counted from the -# location of the copy of the SConscript file in scons/build//scons. +# But if a project uses variant builds without source duplication (see +# http://www.scons.org/wiki/VariantDir%28%29 for more information), the +# above rule gets muddied a bit. In that case the paths must be counted from +# the location of the copy of the SConscript file in +# scons/build//gtest/scons. # # Include paths to gtest headers are relative to either the gtest # directory or the 'include' subdirectory of it, and this SConscript # file is one directory deeper than the gtest directory. env.Prepend(CPPPATH = ['..', '../include']) -if BUILD_TESTS: - env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple) - env_less_optimized = EnvCreator.Create(env, EnvCreator.LessOptimized) - env_with_threads = EnvCreator.Create(env, EnvCreator.WithThreads) - # The following environments are used to compile gtest_unittest.cc, which - # triggers a warning in all but the most recent GCC versions when compiling - # the EXPECT_EQ(NULL, ptr) statement. - env_warning_ok = EnvCreator.Create(env, EnvCreator.WarningOk) - env_with_exceptions = EnvCreator.Create(env_warning_ok, - EnvCreator.WithExceptions) - env_without_rtti = EnvCreator.Create(env_warning_ok, EnvCreator.NoRtti) +env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple) +env_less_optimized = EnvCreator.Create(env, EnvCreator.LessOptimized) +env_with_threads = EnvCreator.Create(env, EnvCreator.WithThreads) +# The following environments are used to compile gtest_unittest.cc, which +# triggers a warning in all but the most recent GCC versions when compiling +# the EXPECT_EQ(NULL, ptr) statement. +env_warning_ok = EnvCreator.Create(env, EnvCreator.WarningOk) +env_with_exceptions = EnvCreator.Create(env_warning_ok, + EnvCreator.WithExceptions) +env_without_rtti = EnvCreator.Create(env_warning_ok, EnvCreator.NoRtti) ############################################################ # Helpers for creating build targets. @@ -229,10 +229,9 @@ def GtestSample(build_env, target, additional_sources=None): # gtest_main.lib can be used if you just want a basic main function; it is also # used by some tests for Google Test itself. gtest, gtest_main = GtestStaticLibraries(env) -if BUILD_TESTS: - gtest_ex, gtest_main_ex = GtestStaticLibraries(env_with_exceptions) - gtest_no_rtti, gtest_main_no_rtti = GtestStaticLibraries(env_without_rtti) - gtest_use_own_tuple, gtest_use_own_tuple_main = GtestStaticLibraries( +gtest_ex, gtest_main_ex = GtestStaticLibraries(env_with_exceptions) +gtest_no_rtti, gtest_main_no_rtti = GtestStaticLibraries(env_without_rtti) +gtest_use_own_tuple, gtest_main_use_own_tuple = GtestStaticLibraries( env_use_own_tuple) # Install the libraries if needed. @@ -282,10 +281,10 @@ if BUILD_TESTS: GtestTest(env_with_threads, 'gtest_stress_test', gtest) GtestTest(env_less_optimized, 'gtest_env_var_test_', gtest) GtestTest(env_less_optimized, 'gtest_uninitialized_test_', gtest) - GtestTest(env_use_own_tuple, 'gtest-tuple_test', gtest_use_own_tuple_main) + GtestTest(env_use_own_tuple, 'gtest-tuple_test', gtest_main_use_own_tuple) GtestBinary(env_use_own_tuple, 'gtest_use_own_tuple_test', - gtest_use_own_tuple_main, + gtest_main_use_own_tuple, ['../test/gtest-param-test_test.cc', '../test/gtest-param-test2_test.cc']) GtestBinary(env_with_exceptions, 'gtest_ex_unittest', gtest_main_ex, @@ -320,16 +319,16 @@ if env.get('GTEST_BUILD_SAMPLES', False): gtest_exports = {'gtest': gtest, 'gtest_main': gtest_main, + 'gtest_ex': gtest_ex, + 'gtest_main_ex': gtest_main_ex, + 'gtest_no_rtti': gtest_no_rtti, + 'gtest_main_no_rtti': gtest_main_no_rtti, + 'gtest_use_own_tuple': gtest_use_own_tuple, + 'gtest_main_use_own_tuple': gtest_main_use_own_tuple, # These exports are used by Google Mock. 'GtestObject': GtestObject, 'GtestBinary': GtestBinary, 'GtestTest': GtestTest} -if BUILD_TESTS: - # These environments are needed for tests only. - gtest_exports.update({'gtest_ex': gtest_ex, - 'gtest_no_rtti': gtest_no_rtti, - 'gtest_use_own_tuple': gtest_use_own_tuple}) - # Makes the gtest_exports dictionary available to the invoking SConstruct. Return('gtest_exports') diff --git a/scons/SConstruct.common b/scons/SConstruct.common index d9915b9..ed896d0 100644 --- a/scons/SConstruct.common +++ b/scons/SConstruct.common @@ -243,10 +243,8 @@ class SConstructHelper: # Invokes SConscript with variant_dir being build/. # Counter-intuitively, src_dir is relative to the build dir and has # to be '..' to point to the scons directory. - SConscript('SConscript', - src_dir='..', - variant_dir=env['BUILD_DIR'], - duplicate=0) + VariantDir(env['BUILD_DIR'], src_dir='../..', duplicate=0); + SConscript(env['BUILD_DIR'] + '/gtest/scons/SConscript') sconstruct_helper = SConstructHelper() diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index df59f9e..0fbe5c5 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -161,6 +161,8 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) { #if GTEST_USES_POSIX_RE +#if GTEST_HAS_TYPED_TEST + template class RETest : public ::testing::Test {}; @@ -223,6 +225,8 @@ TYPED_TEST(RETest, PartialMatchWorks) { EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re)); } +#endif // GTEST_HAS_TYPED_TEST + #elif GTEST_USES_SIMPLE_RE TEST(IsInSetTest, NulCharIsNotInAnySet) { diff --git a/test/run_tests_test.py b/test/run_tests_test.py index 79524a6..a9f0b5d 100755 --- a/test/run_tests_test.py +++ b/test/run_tests_test.py @@ -42,9 +42,9 @@ sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), os.pardir)) import run_tests -GTEST_DBG_DIR = 'scons/build/dbg/scons' -GTEST_OPT_DIR = 'scons/build/opt/scons' -GTEST_OTHER_DIR = 'scons/build/other/scons' +GTEST_DBG_DIR = 'scons/build/dbg/gtest/scons' +GTEST_OPT_DIR = 'scons/build/opt/gtest/scons' +GTEST_OTHER_DIR = 'scons/build/other/gtest/scons' def AddExeExtension(path): -- cgit v0.12