From cc265df8b44e613ca118ce5da145f91d66f6c440 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Mon, 13 Jun 2011 19:00:37 +0000 Subject: Fixes broken build on VC++ 7.1. --- CMakeLists.txt | 38 ++++++++++++++--------- cmake/internal_utils.cmake | 10 ++++++ include/gtest/gtest-printers.h | 5 ++- include/gtest/internal/gtest-internal.h | 10 ++++++ test/gtest_throw_on_failure_test_.cc | 18 ++++++++++- test/gtest_xml_output_unittest.py | 54 ++++++++++++++++++--------------- test/gtest_xml_output_unittest_.cc | 9 ++++-- 7 files changed, 101 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fe2654..64527f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,10 +140,13 @@ if (gtest_build_tests) ############################################################ # C++ tests built with non-standard compiler flags. - cxx_library(gtest_no_exception "${cxx_no_exception}" - src/gtest-all.cc) - cxx_library(gtest_main_no_exception "${cxx_no_exception}" - src/gtest-all.cc src/gtest_main.cc) + # MSVC 7.1 does not support STL with exceptions disabled. + if (NOT MSVC OR MSVC_VERSION GREATER 1310) + cxx_library(gtest_no_exception "${cxx_no_exception}" + src/gtest-all.cc) + cxx_library(gtest_main_no_exception "${cxx_no_exception}" + src/gtest-all.cc src/gtest_main.cc) + endif() cxx_library(gtest_main_no_rtti "${cxx_no_rtti}" src/gtest-all.cc src/gtest_main.cc) @@ -189,11 +192,15 @@ if (gtest_build_tests) cxx_executable(gtest_break_on_failure_unittest_ test gtest) py_test(gtest_break_on_failure_unittest) - cxx_executable_with_flags( - gtest_catch_exceptions_no_ex_test_ - "${cxx_no_exception}" - gtest_main_no_exception - test/gtest_catch_exceptions_test_.cc) + # MSVC 7.1 does not support STL with exceptions disabled. + if (NOT MSVC OR MSVC_VERSION GREATER 1310) + cxx_executable_with_flags( + gtest_catch_exceptions_no_ex_test_ + "${cxx_no_exception}" + gtest_main_no_exception + test/gtest_catch_exceptions_test_.cc) + endif() + cxx_executable_with_flags( gtest_catch_exceptions_ex_test_ "${cxx_exception}" @@ -222,11 +229,14 @@ if (gtest_build_tests) cxx_executable(gtest_shuffle_test_ test gtest) py_test(gtest_shuffle_test) - cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception) - set_target_properties(gtest_throw_on_failure_test_ - PROPERTIES - COMPILE_FLAGS "${cxx_no_exception}") - py_test(gtest_throw_on_failure_test) + # MSVC 7.1 does not support STL with exceptions disabled. + if (NOT MSVC OR MSVC_VERSION GREATER 1310) + cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception) + set_target_properties(gtest_throw_on_failure_test_ + PROPERTIES + COMPILE_FLAGS "${cxx_no_exception}") + py_test(gtest_throw_on_failure_test) + endif() cxx_executable(gtest_uninitialized_test_ test gtest) py_test(gtest_uninitialized_test) diff --git a/cmake/internal_utils.cmake b/cmake/internal_utils.cmake index 7efc2ac..0561db4 100644 --- a/cmake/internal_utils.cmake +++ b/cmake/internal_utils.cmake @@ -56,6 +56,16 @@ macro(config_compiler_and_linker) # Newlines inside flags variables break CMake's NMake generator. # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds. set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi") + if (MSVC_VERSION LESS 1400) + # Suppress spurious warnings MSVC 7.1 sometimes issues. + # Forcing value to bool. + set(cxx_base_flags "${cxx_base_flags} -wd4800") + # Copy constructor and assignment operator could not be generated. + set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512") + # Compatibility warnings not applicable to Google Test. + # Resolved overload was found by argument-dependent lookup. + set(cxx_base_flags "${cxx_base_flags} -wd4675") + endif() set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32") set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN") set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") diff --git a/include/gtest/gtest-printers.h b/include/gtest/gtest-printers.h index 9cbab3f..55d44fa 100644 --- a/include/gtest/gtest-printers.h +++ b/include/gtest/gtest-printers.h @@ -694,7 +694,10 @@ inline void UniversalTersePrint(char* str, ::std::ostream* os) { // NUL-terminated string. template void UniversalPrint(const T& value, ::std::ostream* os) { - UniversalPrinter::Print(value, os); + // A workarond for the bug in VC++ 7.1 that prevents us from instantiating + // UniversalPrinter with T directly. + typedef T T1; + UniversalPrinter::Print(value, os); } #if GTEST_HAS_TR1_TUPLE diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d0fe5f7..d883450 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -802,6 +802,16 @@ struct RemoveConst { typedef typename RemoveConst::type type[N]; }; +#if defined(_MSC_VER) && _MSC_VER < 1400 +// This is the only specialization that allows VC++ 7.1 to remove const in +// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC +// and thus needs to be conditionally compiled. +template +struct RemoveConst { + typedef typename RemoveConst::type type[N]; +}; +#endif + // A handy wrapper around RemoveConst that works when the argument // T depends on template parameters. #define GTEST_REMOVE_CONST_(T) \ diff --git a/test/gtest_throw_on_failure_test_.cc b/test/gtest_throw_on_failure_test_.cc index 03776ec..2b88fe3 100644 --- a/test/gtest_throw_on_failure_test_.cc +++ b/test/gtest_throw_on_failure_test_.cc @@ -37,12 +37,28 @@ #include "gtest/gtest.h" +#include // for fflush, fprintf, NULL, etc. +#include // for exit +#include // for set_terminate + +// This terminate handler aborts the program using exit() rather than abort(). +// This avoids showing pop-ups on Windows systems and core dumps on Unix-like +// ones. +void TerminateHandler() { + fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program."); + fflush(NULL); + exit(1); +} + int main(int argc, char** argv) { +#if GTEST_HAS_EXCEPTIONS + std::set_terminate(&TerminateHandler); +#endif testing::InitGoogleTest(&argc, argv); // We want to ensure that people can use Google Test assertions in // other testing frameworks, as long as they initialize Google Test - // properly and set the thrown-on-failure mode. Therefore, we don't + // properly and set the throw-on-failure mode. Therefore, we don't // use Google Test's constructs for defining and running tests // (e.g. TEST and RUN_ALL_TESTS) here. diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index bdd5035..06637e5 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -42,6 +42,7 @@ import gtest_test_utils import gtest_xml_test_utils +GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' GTEST_OUTPUT_FLAG = "--gtest_output" GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" @@ -49,9 +50,9 @@ GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" SUPPORTS_STACK_TRACES = False if SUPPORTS_STACK_TRACES: - STACK_TRACE_TEMPLATE = "\nStack trace:\n*" + STACK_TRACE_TEMPLATE = '\nStack trace:\n*' else: - STACK_TRACE_TEMPLATE = "" + STACK_TRACE_TEMPLATE = '' EXPECTED_NON_EMPTY_XML = """ @@ -130,18 +131,26 @@ EXPECTED_EMPTY_XML = """ """ +GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) + +SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess( + [GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output + class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ Unit test for Google Test's XML output functionality. """ - def testNonEmptyXmlOutput(self): - """ - Runs a test program that generates a non-empty XML output, and - tests that the XML output is expected. - """ - self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) + # This test currently breaks on platforms that do not support typed and + # type-parameterized tests, so we don't run it under them. + if SUPPORTS_TYPED_TESTS: + def testNonEmptyXmlOutput(self): + """ + Runs a test program that generates a non-empty XML output, and + tests that the XML output is expected. + """ + self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1) def testEmptyXmlOutput(self): """ @@ -149,8 +158,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): tests that the XML output is expected. """ - self._TestXmlOutput("gtest_no_test_unittest", - EXPECTED_EMPTY_XML, 0) + self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_EMPTY_XML, 0) def testDefaultOutputFile(self): """ @@ -160,7 +168,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): output_file = os.path.join(gtest_test_utils.GetTempDir(), GTEST_DEFAULT_OUTPUT_FILE) gtest_prog_path = gtest_test_utils.GetTestExecutablePath( - "gtest_no_test_unittest") + 'gtest_no_test_unittest') try: os.remove(output_file) except OSError, e: @@ -168,7 +176,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): raise p = gtest_test_utils.Subprocess( - [gtest_prog_path, "%s=xml" % GTEST_OUTPUT_FLAG], + [gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG], working_dir=gtest_test_utils.GetTempDir()) self.assert_(p.exited) self.assertEquals(0, p.exit_code) @@ -181,24 +189,22 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ xml_path = os.path.join(gtest_test_utils.GetTempDir(), - GTEST_PROGRAM_NAME + "out.xml") + GTEST_PROGRAM_NAME + 'out.xml') if os.path.isfile(xml_path): os.remove(xml_path) - gtest_prog_path = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) - - command = [gtest_prog_path, - "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path), - "--shut_down_xml"] + command = [GTEST_PROGRAM_PATH, + '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path), + '--shut_down_xml'] p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: self.assert_(False, - "%s was killed by signal %d" % (gtest_prog_name, p.signal)) + '%s was killed by signal %d' % (gtest_prog_name, p.signal)) else: self.assert_(p.exited) self.assertEquals(1, p.exit_code, "'%s' exited with code %s, which doesn't match " - "the expected exit code %s." + 'the expected exit code %s.' % (command, p.exit_code, 1)) self.assert_(not os.path.isfile(xml_path)) @@ -212,19 +218,19 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): expected_exit_code. """ xml_path = os.path.join(gtest_test_utils.GetTempDir(), - gtest_prog_name + "out.xml") + gtest_prog_name + 'out.xml') gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) - command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)] + command = [gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] p = gtest_test_utils.Subprocess(command) if p.terminated_by_signal: self.assert_(False, - "%s was killed by signal %d" % (gtest_prog_name, p.signal)) + '%s was killed by signal %d' % (gtest_prog_name, p.signal)) else: self.assert_(p.exited) self.assertEquals(expected_exit_code, p.exit_code, "'%s' exited with code %s, which doesn't match " - "the expected exit code %s." + 'the expected exit code %s.' % (command, p.exit_code, expected_exit_code)) expected = minidom.parseString(expected_xml) diff --git a/test/gtest_xml_output_unittest_.cc b/test/gtest_xml_output_unittest_.cc index 741a887..bf0c871 100644 --- a/test/gtest_xml_output_unittest_.cc +++ b/test/gtest_xml_output_unittest_.cc @@ -45,7 +45,6 @@ using ::testing::TestEventListeners; using ::testing::TestWithParam; using ::testing::UnitTest; using ::testing::Test; -using ::testing::Types; using ::testing::Values; class SuccessfulTest : public Test { @@ -145,23 +144,27 @@ TEST_P(ValueParamTest, HasValueParamAttribute) {} TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {} INSTANTIATE_TEST_CASE_P(Single, ValueParamTest, Values(33, 42)); +#if GTEST_HAS_TYPED_TEST // Verifies that the type parameter name is output in the 'type_param' // XML attribute for typed tests. template class TypedTest : public Test {}; -typedef Types TypedTestTypes; +typedef testing::Types TypedTestTypes; TYPED_TEST_CASE(TypedTest, TypedTestTypes); TYPED_TEST(TypedTest, HasTypeParamAttribute) {} +#endif +#if GTEST_HAS_TYPED_TEST_P // Verifies that the type parameter name is output in the 'type_param' // XML attribute for type-parameterized tests. template class TypeParameterizedTestCase : public Test {}; TYPED_TEST_CASE_P(TypeParameterizedTestCase); TYPED_TEST_P(TypeParameterizedTestCase, HasTypeParamAttribute) {} REGISTER_TYPED_TEST_CASE_P(TypeParameterizedTestCase, HasTypeParamAttribute); -typedef Types TypeParameterizedTestCaseTypes; +typedef testing::Types TypeParameterizedTestCaseTypes; INSTANTIATE_TYPED_TEST_CASE_P(Single, TypeParameterizedTestCase, TypeParameterizedTestCaseTypes); +#endif int main(int argc, char** argv) { InitGoogleTest(&argc, argv); -- cgit v0.12