diff options
-rw-r--r-- | googlemock/cmake/gmock.pc.in | 2 | ||||
-rw-r--r-- | googlemock/cmake/gmock_main.pc.in | 2 | ||||
-rw-r--r-- | googlemock/docs/pump_manual.md | 21 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 2 | ||||
-rwxr-xr-x | googlemock/scripts/pump.py | 13 | ||||
-rw-r--r-- | googletest/cmake/gtest.pc.in | 2 | ||||
-rw-r--r-- | googletest/cmake/gtest_main.pc.in | 2 | ||||
-rw-r--r-- | googletest/include/gtest/gtest-typed-test.h | 17 | ||||
-rw-r--r-- | googletest/include/gtest/internal/gtest-internal.h | 36 | ||||
-rwxr-xr-x | googletest/scripts/gen_gtest_pred_impl.py | 6 | ||||
-rw-r--r-- | googletest/src/gtest-death-test.cc | 2 | ||||
-rw-r--r-- | googletest/test/gtest_unittest.cc | 13 |
12 files changed, 84 insertions, 34 deletions
diff --git a/googlemock/cmake/gmock.pc.in b/googlemock/cmake/gmock.pc.in index 2ef0fbc..5780fca 100644 --- a/googlemock/cmake/gmock.pc.in +++ b/googlemock/cmake/gmock.pc.in @@ -7,4 +7,4 @@ Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Requires: gtest Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/googlemock/cmake/gmock_main.pc.in b/googlemock/cmake/gmock_main.pc.in index 04658fe..f2dfe69 100644 --- a/googlemock/cmake/gmock_main.pc.in +++ b/googlemock/cmake/gmock_main.pc.in @@ -7,4 +7,4 @@ Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Requires: gmock Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/googlemock/docs/pump_manual.md b/googlemock/docs/pump_manual.md index 10b3c5f..cdf7c57 100644 --- a/googlemock/docs/pump_manual.md +++ b/googlemock/docs/pump_manual.md @@ -6,18 +6,15 @@ Template and macro libraries often need to define many classes, functions, or macros that vary only (or almost only) in the number of arguments they take. It's a lot of repetitive, mechanical, and error-prone work. -Variadic templates and variadic macros can alleviate the problem. However, while -both are being considered by the C++ committee, neither is in the standard yet -or widely supported by compilers. Thus they are often not a good choice, -especially when your code needs to be portable. And their capabilities are still -limited. - -As a result, authors of such libraries often have to write scripts to generate -their implementation. However, our experience is that it's tedious to write such -scripts, which tend to reflect the structure of the generated code poorly and -are often hard to read and edit. For example, a small change needed in the -generated code may require some non-intuitive, non-trivial changes in the -script. This is especially painful when experimenting with the code. +Our experience is that it's tedious to write custom scripts, which tend to +reflect the structure of the generated code poorly and are often hard to read +and edit. For example, a small change needed in the generated code may require +some non-intuitive, non-trivial changes in the script. This is especially +painful when experimenting with the code. + +This script may be useful for generating meta code, for example a series of +macros of FOO1, FOO2, etc. Nevertheless, please make it your last resort +technique by favouring C++ template metaprogramming or variadic macros. # Our Solution diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b8ec24d..e71570b 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1323,7 +1323,7 @@ class PredicateFormatterFromMatcher { << "Expected: "; matcher.DescribeTo(&ss); - // Rerun the matcher to "PrintAndExain" the failure. + // Rerun the matcher to "PrintAndExplain" the failure. StringMatchResultListener listener; if (MatchPrintAndExplain(x, matcher, &listener)) { ss << "\n The matcher failed on the initial attempt; but passed when " diff --git a/googlemock/scripts/pump.py b/googlemock/scripts/pump.py index 66e3217..5523a19 100755 --- a/googlemock/scripts/pump.py +++ b/googlemock/scripts/pump.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python # # Copyright 2008, Google Inc. # All rights reserved. @@ -64,6 +64,7 @@ GRAMMAR: from __future__ import print_function +import io import os import re import sys @@ -834,7 +835,7 @@ def main(argv): sys.exit(1) file_path = argv[-1] - output_str = ConvertFromPumpSource(file(file_path, 'r').read()) + output_str = ConvertFromPumpSource(io.open(file_path, 'r').read()) if file_path.endswith('.pump'): output_file_path = file_path[:-5] else: @@ -842,11 +843,11 @@ def main(argv): if output_file_path == '-': print(output_str,) else: - output_file = file(output_file_path, 'w') - output_file.write('// This file was GENERATED by command:\n') - output_file.write('// %s %s\n' % + output_file = io.open(output_file_path, 'w') + output_file.write(u'// This file was GENERATED by command:\n') + output_file.write(u'// %s %s\n' % (os.path.basename(__file__), os.path.basename(file_path))) - output_file.write('// DO NOT EDIT BY HAND!!!\n\n') + output_file.write(u'// DO NOT EDIT BY HAND!!!\n\n') output_file.write(output_str) output_file.close() diff --git a/googletest/cmake/gtest.pc.in b/googletest/cmake/gtest.pc.in index e7967ad..b4148fa 100644 --- a/googletest/cmake/gtest.pc.in +++ b/googletest/cmake/gtest.pc.in @@ -6,4 +6,4 @@ Description: GoogleTest (without main() function) Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/googletest/cmake/gtest_main.pc.in b/googletest/cmake/gtest_main.pc.in index fe25d9c..1e01bd1 100644 --- a/googletest/cmake/gtest_main.pc.in +++ b/googletest/cmake/gtest_main.pc.in @@ -7,4 +7,4 @@ Version: @PROJECT_VERSION@ URL: https://github.com/google/googletest Requires: gtest Libs: -L${libdir} -lgtest_main @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ +Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/googletest/include/gtest/gtest-typed-test.h b/googletest/include/gtest/gtest-typed-test.h index 151fc8f..6f635c8 100644 --- a/googletest/include/gtest/gtest-typed-test.h +++ b/googletest/include/gtest/gtest-typed-test.h @@ -169,6 +169,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); #endif // 0 +#include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-type-util.h" @@ -194,6 +195,8 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); GTEST_NAME_GENERATOR_(CaseName) #define TYPED_TEST(CaseName, TestName) \ + static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ + "test-name must not be empty"); \ template <typename gtest_TypeParam_> \ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ : public CaseName<gtest_TypeParam_> { \ @@ -211,7 +214,8 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); CaseName)>::Register("", \ ::testing::internal::CodeLocation( \ __FILE__, __LINE__), \ - #CaseName, #TestName, 0, \ + GTEST_STRINGIFY_(CaseName), \ + GTEST_STRINGIFY_(TestName), 0, \ ::testing::internal::GenerateNames< \ GTEST_NAME_GENERATOR_(CaseName), \ GTEST_TYPE_PARAMS_(CaseName)>()); \ @@ -278,12 +282,14 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); }; \ static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ - __FILE__, __LINE__, #SuiteName, #TestName); \ + __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ + GTEST_STRINGIFY_(TestName)); \ } \ template <typename gtest_TypeParam_> \ void GTEST_SUITE_NAMESPACE_( \ SuiteName)::TestName<gtest_TypeParam_>::TestBody() +// Note: this won't work correctly if the trailing arguments are macros. #define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \ @@ -302,13 +308,16 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ + static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ + "test-suit-prefix must not be empty"); \ static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \ ::testing::internal::TypeParameterizedTestSuite< \ SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ ::testing::internal::GenerateTypeList<Types>::type>:: \ - Register(#Prefix, \ + Register(GTEST_STRINGIFY_(Prefix), \ ::testing::internal::CodeLocation(__FILE__, __LINE__), \ - >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \ + >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ + GTEST_STRINGIFY_(SuiteName), \ GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ ::testing::internal::GenerateNames< \ ::testing::internal::NameGeneratorSelector< \ diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index edf0afa..f9da489 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -825,6 +825,16 @@ struct GTEST_API_ ConstCharPtr { const char* value; }; +// Helper for declaring std::string within 'if' statement +// in pre C++17 build environment. +struct GTEST_API_ TrueWithString { + TrueWithString() = default; + explicit TrueWithString(const char* str) : value(str) {} + explicit TrueWithString(const std::string& str) : value(str) {} + explicit operator bool() const { return true; } + std::string value; +}; + // A simple Linear Congruential Generator for generating random // numbers with a uniform distribution. Unlike rand() and srand(), it // doesn't use global state (and therefore can't interfere with user @@ -1284,19 +1294,39 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; } GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ fail(gtest_msg.value) +#if GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ + catch (std::exception const& e) { \ + gtest_msg.value = ( \ + "it throws std::exception-derived exception with description: \"" \ + ); \ + gtest_msg.value += e.what(); \ + gtest_msg.value += "\"."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } + +#else // GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() + +#endif // GTEST_HAS_EXCEPTIONS + #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ + if (::testing::internal::TrueWithString gtest_msg{}) { \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ + GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ catch (...) { \ + gtest_msg.value = "it throws."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail("Expected: " #statement " doesn't throw an exception.\n" \ - " Actual: it throws.") + fail(("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: " + gtest_msg.value).c_str()) #define GTEST_TEST_ANY_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/scripts/gen_gtest_pred_impl.py b/googletest/scripts/gen_gtest_pred_impl.py index 20206e3..e76fcb0 100755 --- a/googletest/scripts/gen_gtest_pred_impl.py +++ b/googletest/scripts/gen_gtest_pred_impl.py @@ -78,7 +78,7 @@ def HeaderPreamble(n): } return ( -"""// Copyright 2006, Google Inc. + """// Copyright 2006, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -337,7 +337,7 @@ def UnitTestPreamble(): } return ( -"""// Copyright 2006, Google Inc. + """// Copyright 2006, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -431,7 +431,7 @@ def TestsForArity(n): } tests = ( -"""// Sample functions/functors for testing %(arity)s predicate assertions. + """// Sample functions/functors for testing %(arity)s predicate assertions. // A %(arity)s predicate function. template <%(types)s> diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index da09a1c..5d1031b 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -1364,7 +1364,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { if (!use_fork) { static const bool stack_grows_down = StackGrowsDown(); - const auto stack_size = static_cast<size_t>(getpagesize()); + const auto stack_size = static_cast<size_t>(getpagesize() * 2); // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead. void* const stack = mmap(nullptr, stack_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index d17a155..74379ab 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3348,6 +3348,9 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } +void ThrowRuntimeError(const char* what) { + throw std::runtime_error(what); +} // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3827,6 +3830,11 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); + EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowRuntimeError("A description")), + "Expected: ThrowRuntimeError(\"A description\") " + "doesn't throw an exception.\n " + "Actual: it throws std::exception-derived exception " + "with description: \"A description\"."); } // Tests ASSERT_ANY_THROW. @@ -4564,6 +4572,11 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); + EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowRuntimeError("A description")), + "Expected: ThrowRuntimeError(\"A description\") " + "doesn't throw an exception.\n " + "Actual: it throws std::exception-derived exception " + "with description: \"A description\"."); } // Tests EXPECT_ANY_THROW. |