From 8f04622cc1507a3954490a03a1dfcff9e340359e Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 13:45:27 -0400 Subject: [PATCH 01/13] Use GTEST_LOG instead of printf --- googletest/src/gtest.cc | 49 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d882ab2e..b8579d3c 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2571,10 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name, << "probably rename one of the classes to put the tests into different\n" << "test cases."; - fprintf(stderr, "%s %s", - FormatFileLocation(code_location.file.c_str(), - code_location.line).c_str(), - errors.GetString().c_str()); + GTEST_LOG_(ERROR) + << FormatFileLocation(code_location.file.c_str(), + code_location.line), + << " " << errors.GetString(); } #endif // GTEST_HAS_PARAM_TEST @@ -3422,8 +3422,10 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file) : output_file_(output_file) { if (output_file_.c_str() == NULL || output_file_.empty()) { - fprintf(stderr, "XML output file may not be null\n"); - fflush(stderr); + { + // scoped to make sure the log is flushed before we exit + GTEST_LOG_(FATAL) << "XML output file may not be null"; + } exit(EXIT_FAILURE); } } @@ -3449,10 +3451,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, // 3. To interpret the meaning of errno in a thread-safe way, // we need the strerror_r() function, which is not available on // Windows. - fprintf(stderr, - "Unable to open file \"%s\"\n", - output_file_.c_str()); - fflush(stderr); + { // scoped to ensure the log is flushed before we exit + GTEST_LOG_(FATAL) << "Unable to open file \"" + << output_file_ << "\""; + } exit(EXIT_FAILURE); } std::stringstream stream; @@ -4403,9 +4405,9 @@ void UnitTestImpl::ConfigureXmlOutput() { listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter( UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); } else if (output_format != "") { - printf("WARNING: unrecognized output format \"%s\" ignored.\n", - output_format.c_str()); - fflush(stdout); + GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" + << output_format + << "\" ignored."; } } @@ -4420,9 +4422,9 @@ void UnitTestImpl::ConfigureStreamingOutput() { listeners()->Append(new StreamingListener(target.substr(0, pos), target.substr(pos+1))); } else { - printf("WARNING: unrecognized streaming target \"%s\" ignored.\n", - target.c_str()); - fflush(stdout); + GTEST_LOG_(WARNING) << "unrecognized streaming target \"" + << target + << "\" ignored."; } } } @@ -4551,9 +4553,9 @@ static void TearDownEnvironment(Environment* env) { env->TearDown(); } bool UnitTestImpl::RunAllTests() { // Makes sure InitGoogleTest() was called. if (!GTestIsInitialized()) { - printf("%s", - "\nThis test program did NOT call ::testing::InitGoogleTest " - "before calling RUN_ALL_TESTS(). Please fix it.\n"); + GTEST_LOG_(ERROR) << + "\nThis test program did NOT call ::testing::InitGoogleTest " + "before calling RUN_ALL_TESTS(). Please fix it."; return false; } @@ -5253,10 +5255,11 @@ bool ParseGoogleTestFlag(const char* const arg) { void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { - fprintf(stderr, - "Unable to open file \"%s\"\n", - GTEST_FLAG(flagfile).c_str()); - fflush(stderr); + { // scoped to ensure the log is flushed before we exit + GTEST_LOG_(FATAL) << "Unable to open file \"" + << GTEST_FLAG(flagfile) + << "\""; + } exit(EXIT_FAILURE); } std::string contents(ReadEntireFile(flagfile)); From ca76206f4268a009427afa96dfd792012db64583 Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 15:30:01 -0400 Subject: [PATCH 02/13] Removed extra colon in error log --- googletest/src/gtest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 07b028b6..b2d2a282 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2571,7 +2571,7 @@ void ReportInvalidTestCaseType(const char* test_case_name, GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(), - code_location.line), + code_location.line) << " " << errors.GetString(); } #endif // GTEST_HAS_PARAM_TEST From b567aadd1b3eeccdb85305cdb65664f0245e90bc Mon Sep 17 00:00:00 2001 From: Herbert Thielen Date: Tue, 9 May 2017 18:54:04 +0200 Subject: [PATCH 03/13] remove unused TestCase import --- googletest/samples/sample10_unittest.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/googletest/samples/sample10_unittest.cc b/googletest/samples/sample10_unittest.cc index 977e5ff6..10aa7620 100644 --- a/googletest/samples/sample10_unittest.cc +++ b/googletest/samples/sample10_unittest.cc @@ -38,7 +38,6 @@ using ::testing::EmptyTestEventListener; using ::testing::InitGoogleTest; using ::testing::Test; -using ::testing::TestCase; using ::testing::TestEventListeners; using ::testing::TestInfo; using ::testing::TestPartResult; From e7c9e80e63e5cdcd3252ed81c9d3dbf0a7fb6841 Mon Sep 17 00:00:00 2001 From: Bernhard Bauer Date: Thu, 4 Feb 2016 11:50:08 +0000 Subject: [PATCH 04/13] Allow macros inside of parametrized test names. This allows doing things like TEST_P(TestFixture, MAYBE(TestName)) for nicer conditional test disabling. --- googletest/include/gtest/gtest-param-test.h | 15 +++++++++------ googletest/include/gtest/gtest-param-test.h.pump | 9 ++++++--- googletest/test/gtest-param-test_test.cc | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 038f9ba7..e01c3ff6 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -1375,7 +1375,10 @@ internal::CartesianProductHolder10AddTestPattern(\ - #test_case_name, \ - #test_name, \ + GTEST_STRINGIFY_(test_case_name), \ + GTEST_STRINGIFY_(test_name), \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ @@ -1412,11 +1415,11 @@ internal::CartesianProductHolder10, and return std::string. // // testing::PrintToStringParamName is a builtin test suffix generator that -// returns the value of testing::PrintToString(GetParam()). It does not work -// for std::string or C strings. +// returns the value of testing::PrintToString(GetParam()). // // Note: test names must be non-empty, unique, and may only contain ASCII -// alphanumeric characters or underscore. +// alphanumeric characters or underscore. Because PrintToString adds quotes +// to std::string and C strings, it won't work for these types. # define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \ ::testing::internal::ParamGenerator \ diff --git a/googletest/include/gtest/gtest-param-test.h.pump b/googletest/include/gtest/gtest-param-test.h.pump index 3078d6d2..8ab18dd0 100644 --- a/googletest/include/gtest/gtest-param-test.h.pump +++ b/googletest/include/gtest/gtest-param-test.h.pump @@ -441,7 +441,10 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( ]] # endif // GTEST_HAS_COMBINE - +// Use a macro to stringify the test (case) name, because direct stringification +// does not work if one of the arguments is itself a macro +// (https://gcc.gnu.org/onlinedocs/cpp/Stringification.html). +# define GTEST_STRINGIFY_(name) #name # define TEST_P(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ @@ -456,8 +459,8 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( #test_case_name, \ ::testing::internal::CodeLocation(\ __FILE__, __LINE__))->AddTestPattern(\ - #test_case_name, \ - #test_name, \ + GTEST_STRINGIFY_(test_case_name), \ + GTEST_STRINGIFY_(test_name), \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 857f6c5e..a6ecef65 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -809,6 +809,22 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); +// Tests that macros in test names are expanded correctly. +class MacroNamingTest : public TestWithParam {}; + +#define PREFIX_WITH_FOO(test_name) FOO_##test_name +#define PREFIX_WITH_MACRO(test_name) Macro##test_name + +TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name()); + EXPECT_STREQ("FOO_SomeTestName", test_info->name()); +} + +INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); + // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible From 86e5f0083e5217e37eb94a391a2f7349bcef4660 Mon Sep 17 00:00:00 2001 From: Bernhard Bauer Date: Wed, 10 Feb 2016 17:41:18 +0000 Subject: [PATCH 05/13] Add a non-parametrized test. --- googletest/test/gtest-param-test_test.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index a6ecef65..f6f59558 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -825,6 +825,18 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); +// Tests the same thing for non-parametrized tests. +class MacroNamingTestNonParametrized : public ::testing::Test {}; + +TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), + PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name()); + EXPECT_STREQ("FOO_SomeTestName", test_info->name()); +} + // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible From e8c6942ac1570c9598cf2d177f6c69cc5ab2bd7b Mon Sep 17 00:00:00 2001 From: Herbert Thielen Date: Tue, 5 Sep 2017 12:01:14 +0200 Subject: [PATCH 06/13] remove obsolete link_directories command It's not necessary, as the target_link_libraries command contains an absolute path already, and the path given doesn't exist anymore, leading only to linker warnings like: ld: warning: directory not found for option '-L/Users/travis/build/google/googletest/build/googlemock/gtest/src' --- googletest/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 59343ed2..8391dbd0 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -75,9 +75,6 @@ include_directories( ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) -# Where Google Test's libraries can be found. -link_directories(${gtest_BINARY_DIR}/src) - # Summary of tuple support for Microsoft Visual Studio: # Compiler version(MS) version(cmake) Support # ---------- ----------- -------------- ----------------------------- From be94bf501e649dfa6790b3cce2bbe300949b6e74 Mon Sep 17 00:00:00 2001 From: Herbert Thielen Date: Tue, 5 Sep 2017 17:45:48 +0200 Subject: [PATCH 07/13] remove unused variables from travis environment --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 417d2c51..27094676 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,8 +36,8 @@ compiler: script: ./travis.sh env: matrix: - - SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=Debug VERBOSE=1 - - SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=Debug VERBOSE=1 CXX_FLAGS=-std=c++11 + - BUILD_TYPE=Debug VERBOSE=1 + - BUILD_TYPE=Debug VERBOSE=1 CXX_FLAGS=-std=c++11 notifications: email: false sudo: false From f6dde80e94b982fa74b7da78e56263eee59e4887 Mon Sep 17 00:00:00 2001 From: Gasprd Petit Date: Thu, 7 Sep 2017 07:47:09 -0400 Subject: [PATCH 08/13] Removed flush scopes around GTEST_LOG(FATAL) and exit call since FATAL is expected to abort() --- googletest/src/gtest.cc | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 0895b42a..fa170e75 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3449,11 +3449,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file) : output_file_(output_file) { if (output_file_.c_str() == NULL || output_file_.empty()) { - { - // scoped to make sure the log is flushed before we exit - GTEST_LOG_(FATAL) << "XML output file may not be null"; - } - exit(EXIT_FAILURE); + GTEST_LOG_(FATAL) << "XML output file may not be null"; } } @@ -3478,11 +3474,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, // 3. To interpret the meaning of errno in a thread-safe way, // we need the strerror_r() function, which is not available on // Windows. - { // scoped to ensure the log is flushed before we exit - GTEST_LOG_(FATAL) << "Unable to open file \"" - << output_file_ << "\""; - } - exit(EXIT_FAILURE); + GTEST_LOG_(FATAL) << "Unable to open file \"" + << output_file_ << "\""; } std::stringstream stream; PrintXmlUnitTest(&stream, unit_test); @@ -5283,12 +5276,9 @@ bool ParseGoogleTestFlag(const char* const arg) { void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { - { // scoped to ensure the log is flushed before we exit - GTEST_LOG_(FATAL) << "Unable to open file \"" - << GTEST_FLAG(flagfile) - << "\""; - } - exit(EXIT_FAILURE); + GTEST_LOG_(FATAL) << "Unable to open file \"" + << GTEST_FLAG(flagfile) + << "\""; } std::string contents(ReadEntireFile(flagfile)); posix::FClose(flagfile); From 4f68ab5b84dda2b364ea3350fc2a96d1cb15adf5 Mon Sep 17 00:00:00 2001 From: Alex Yursha <31780593+yursha@users.noreply.github.com> Date: Fri, 8 Sep 2017 17:20:59 -0700 Subject: [PATCH 09/13] Fix ellipsis position in examples --- googlemock/docs/ForDummies.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/googlemock/docs/ForDummies.md b/googlemock/docs/ForDummies.md index 0bf528e9..76910569 100644 --- a/googlemock/docs/ForDummies.md +++ b/googlemock/docs/ForDummies.md @@ -217,7 +217,8 @@ The macro can be followed by some optional _clauses_ that provide more informati This syntax is designed to make an expectation read like English. For example, you can probably guess that ``` -using ::testing::Return;... +using ::testing::Return; +... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) @@ -251,7 +252,8 @@ EXPECT_CALL(turtle, Forward(_)); A list of built-in matchers can be found in the [CheatSheet](CheatSheet.md). For example, here's the `Ge` (greater than or equal) matcher: ``` -using ::testing::Ge;... +using ::testing::Ge; +... EXPECT_CALL(turtle, Forward(Ge(100))); ``` @@ -280,7 +282,8 @@ First, if the return type of a mock function is a built-in type or a pointer, th Second, if a mock function doesn't have a default action, or the default action doesn't suit you, you can specify the action to be taken each time the expectation matches using a series of `WillOnce()` clauses followed by an optional `WillRepeatedly()`. For example, ``` -using ::testing::Return;... +using ::testing::Return; +... EXPECT_CALL(turtle, GetX()) .WillOnce(Return(100)) .WillOnce(Return(200)) @@ -290,7 +293,8 @@ EXPECT_CALL(turtle, GetX()) This says that `turtle.GetX()` will be called _exactly three times_ (Google Mock inferred this from how many `WillOnce()` clauses we've written, since we didn't explicitly write `Times()`), and will return 100, 200, and 300 respectively. ``` -using ::testing::Return;... +using ::testing::Return; +... EXPECT_CALL(turtle, GetY()) .WillOnce(Return(100)) .WillOnce(Return(200)) @@ -317,7 +321,8 @@ Instead of returning 100, 101, 102, ..., consecutively, this mock function will Time for another quiz! What do you think the following means? ``` -using ::testing::Return;... +using ::testing::Return; +... EXPECT_CALL(turtle, GetY()) .Times(4) .WillOnce(Return(100)); @@ -331,7 +336,8 @@ So far we've only shown examples where you have a single expectation. More reali By default, when a mock method is invoked, Google Mock will search the expectations in the **reverse order** they are defined, and stop when an active expectation that matches the arguments is found (you can think of it as "newer rules override older ones."). If the matching expectation cannot take any more calls, you will get an upper-bound-violated failure. Here's an example: ``` -using ::testing::_;... +using ::testing::_; +... EXPECT_CALL(turtle, Forward(_)); // #1 EXPECT_CALL(turtle, Forward(10)) // #2 .Times(2); @@ -347,7 +353,8 @@ By default, an expectation can match a call even though an earlier expectation h Sometimes, you may want all the expected calls to occur in a strict order. To say this in Google Mock is easy: ``` -using ::testing::InSequence;... +using ::testing::InSequence; +... TEST(FooTest, DrawsLineSegment) { ... { @@ -373,7 +380,8 @@ Now let's do a quick quiz to see how well you can use this mock stuff already. H After you've come up with your answer, take a look at ours and compare notes (solve it yourself first - don't cheat!): ``` -using ::testing::_;... +using ::testing::_; +... EXPECT_CALL(turtle, GoTo(_, _)) // #1 .Times(AnyNumber()); EXPECT_CALL(turtle, GoTo(0, 0)) // #2 From c9cf07a8ba4de21e528a2f2e0e38767c34d54412 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 1 Sep 2017 14:21:43 +0100 Subject: [PATCH 10/13] Make the failure messages from EXPECT_EQ and friends actually symmetric, instead of reading more like reversing the former "expected" and "actual" roles of the LHS and RHS arguments. This patch is manually applied from internal version (125109873) --- googletest/src/gtest.cc | 9 +- .../test/gtest_output_test_golden_lin.txt | 132 ++++++++++-------- googletest/test/gtest_unittest.cc | 106 +++++++------- googletest/test/gtest_xml_output_unittest.py | 21 +-- 4 files changed, 151 insertions(+), 117 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index fa170e75..2d1b5b98 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -1313,13 +1313,14 @@ AssertionResult EqFailure(const char* lhs_expression, const std::string& rhs_value, bool ignoring_case) { Message msg; - msg << " Expected: " << lhs_expression; + msg << "Expected equality of these values:"; + msg << "\n " << lhs_expression; if (lhs_value != lhs_expression) { - msg << "\n Which is: " << lhs_value; + msg << "\n Which is: " << lhs_value; } - msg << "\nTo be equal to: " << rhs_expression; + msg << "\n " << rhs_expression; if (rhs_value != rhs_expression) { - msg << "\n Which is: " << rhs_value; + msg << "\n Which is: " << rhs_value; } if (ignoring_case) { diff --git a/googletest/test/gtest_output_test_golden_lin.txt b/googletest/test/gtest_output_test_golden_lin.txt index 2223d560..677d9f40 100644 --- a/googletest/test/gtest_output_test_golden_lin.txt +++ b/googletest/test/gtest_output_test_golden_lin.txt @@ -5,8 +5,9 @@ Value of: false Actual: false Expected: true gtest_output_test_.cc:#: Failure - Expected: 2 -To be equal to: 3 +Expected equality of these values: + 2 + 3 [==========] Running 66 tests from 29 test cases. [----------] Global test environment set-up. FooEnvironment::SetUp() called. @@ -34,21 +35,24 @@ BarEnvironment::SetUp() called. [----------] 2 tests from NonfatalFailureTest [ RUN ] NonfatalFailureTest.EscapesStringOperands gtest_output_test_.cc:#: Failure - Expected: kGoldenString - Which is: "\"Line" -To be equal to: actual - Which is: "actual \"string\"" +Expected equality of these values: + kGoldenString + Which is: "\"Line" + actual + Which is: "actual \"string\"" gtest_output_test_.cc:#: Failure - Expected: golden - Which is: "\"Line" -To be equal to: actual - Which is: "actual \"string\"" +Expected equality of these values: + golden + Which is: "\"Line" + actual + Which is: "actual \"string\"" [ FAILED ] NonfatalFailureTest.EscapesStringOperands [ RUN ] NonfatalFailureTest.DiffForLongStrings gtest_output_test_.cc:#: Failure - Expected: golden_str - Which is: "\"Line\0 1\"\nLine 2" -To be equal to: "Line 2" +Expected equality of these values: + golden_str + Which is: "\"Line\0 1\"\nLine 2" + "Line 2" With diff: @@ -1,2 @@ -\"Line\0 1\" @@ -59,16 +63,18 @@ With diff: [ RUN ] FatalFailureTest.FatalFailureInSubroutine (expecting a failure that x should be 1) gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: x - Which is: 2 +Expected equality of these values: + 1 + x + Which is: 2 [ FAILED ] FatalFailureTest.FatalFailureInSubroutine [ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine (expecting a failure that x should be 1) gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: x - Which is: 2 +Expected equality of these values: + 1 + x + Which is: 2 [ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine [ RUN ] FatalFailureTest.NonfatalFailureInSubroutine (expecting a failure on false) @@ -107,39 +113,44 @@ This failure is expected, and shouldn't have a trace. [ RUN ] SCOPED_TRACETest.WorksInLoop (expected to fail) gtest_output_test_.cc:#: Failure - Expected: 2 -To be equal to: n - Which is: 1 +Expected equality of these values: + 2 + n + Which is: 1 Google Test trace: gtest_output_test_.cc:#: i = 1 gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: n - Which is: 2 +Expected equality of these values: + 1 + n + Which is: 2 Google Test trace: gtest_output_test_.cc:#: i = 2 [ FAILED ] SCOPED_TRACETest.WorksInLoop [ RUN ] SCOPED_TRACETest.WorksInSubroutine (expected to fail) gtest_output_test_.cc:#: Failure - Expected: 2 -To be equal to: n - Which is: 1 +Expected equality of these values: + 2 + n + Which is: 1 Google Test trace: gtest_output_test_.cc:#: n = 1 gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: n - Which is: 2 +Expected equality of these values: + 1 + n + Which is: 2 Google Test trace: gtest_output_test_.cc:#: n = 2 [ FAILED ] SCOPED_TRACETest.WorksInSubroutine [ RUN ] SCOPED_TRACETest.CanBeNested (expected to fail) gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: n - Which is: 2 +Expected equality of these values: + 1 + n + Which is: 2 Google Test trace: gtest_output_test_.cc:#: n = 2 gtest_output_test_.cc:#: @@ -437,9 +448,10 @@ Expected: 1 fatal failure [ OK ] TypedTest/0.Success [ RUN ] TypedTest/0.Failure gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: TypeParam() - Which is: 0 +Expected equality of these values: + 1 + TypeParam() + Which is: 0 Expected failure [ FAILED ] TypedTest/0.Failure, where TypeParam = int [----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char @@ -447,10 +459,11 @@ Expected failure [ OK ] Unsigned/TypedTestP/0.Success [ RUN ] Unsigned/TypedTestP/0.Failure gtest_output_test_.cc:#: Failure - Expected: 1U - Which is: 1 -To be equal to: TypeParam() - Which is: '\0' +Expected equality of these values: + 1U + Which is: 1 + TypeParam() + Which is: '\0' Expected failure [ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char [----------] 2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int @@ -458,10 +471,11 @@ Expected failure [ OK ] Unsigned/TypedTestP/1.Success [ RUN ] Unsigned/TypedTestP/1.Failure gtest_output_test_.cc:#: Failure - Expected: 1U - Which is: 1 -To be equal to: TypeParam() - Which is: 0 +Expected equality of these values: + 1U + Which is: 1 + TypeParam() + Which is: 0 Expected failure [ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int [----------] 4 tests from ExpectFailureTest @@ -597,18 +611,20 @@ Expected non-fatal failure. [----------] 1 test from PrintingFailingParams/FailingParamTest [ RUN ] PrintingFailingParams/FailingParamTest.Fails/0 gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: GetParam() - Which is: 2 +Expected equality of these values: + 1 + GetParam() + Which is: 2 [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [----------] 2 tests from PrintingStrings/ParamTest [ RUN ] PrintingStrings/ParamTest.Success/a [ OK ] PrintingStrings/ParamTest.Success/a [ RUN ] PrintingStrings/ParamTest.Failure/a gtest_output_test_.cc:#: Failure - Expected: "b" -To be equal to: GetParam() - Which is: "a" +Expected equality of these values: + "b" + GetParam() + Which is: "a" Expected failure [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" [----------] Global test environment tear-down @@ -678,16 +694,18 @@ Expected fatal failure. [ RUN ] FatalFailureTest.FatalFailureInSubroutine (expecting a failure that x should be 1) gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: x - Which is: 2 +Expected equality of these values: + 1 + x + Which is: 2 [ FAILED ] FatalFailureTest.FatalFailureInSubroutine (? ms) [ RUN ] FatalFailureTest.FatalFailureInNestedSubroutine (expecting a failure that x should be 1) gtest_output_test_.cc:#: Failure - Expected: 1 -To be equal to: x - Which is: 2 +Expected equality of these values: + 1 + x + Which is: 2 [ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine (? ms) [ RUN ] FatalFailureTest.NonfatalFailureInSubroutine (expecting a failure on false) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 745c9506..00d9f061 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -2429,8 +2429,9 @@ TEST(StringAssertionTest, ASSERT_STREQ) { const char p2[] = "good"; ASSERT_STREQ(p1, p2); - EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"), - "Expected: \"bad\""); + EXPECT_FATAL_FAILURE( + ASSERT_STREQ("bad", "good"), + "Expected equality of these values:\n \"bad\"\n \"good\""); } // Tests ASSERT_STREQ with NULL arguments. @@ -3528,35 +3529,39 @@ TEST(AssertionTest, EqFailure) { EqFailure("foo", "bar", foo_val, bar_val, false) .failure_message()); EXPECT_STREQ( - " Expected: foo\n" - " Which is: 5\n" - "To be equal to: bar\n" - " Which is: 6", + "Expected equality of these values:\n" + " foo\n" + " Which is: 5\n" + " bar\n" + " Which is: 6", msg1.c_str()); const std::string msg2( EqFailure("foo", "6", foo_val, bar_val, false) .failure_message()); EXPECT_STREQ( - " Expected: foo\n" - " Which is: 5\n" - "To be equal to: 6", + "Expected equality of these values:\n" + " foo\n" + " Which is: 5\n" + " 6", msg2.c_str()); const std::string msg3( EqFailure("5", "bar", foo_val, bar_val, false) .failure_message()); EXPECT_STREQ( - " Expected: 5\n" - "To be equal to: bar\n" - " Which is: 6", + "Expected equality of these values:\n" + " 5\n" + " bar\n" + " Which is: 6", msg3.c_str()); const std::string msg4( EqFailure("5", "6", foo_val, bar_val, false).failure_message()); EXPECT_STREQ( - " Expected: 5\n" - "To be equal to: 6", + "Expected equality of these values:\n" + " 5\n" + " 6", msg4.c_str()); const std::string msg5( @@ -3564,10 +3569,11 @@ TEST(AssertionTest, EqFailure) { std::string("\"x\""), std::string("\"y\""), true).failure_message()); EXPECT_STREQ( - " Expected: foo\n" - " Which is: \"x\"\n" - "To be equal to: bar\n" - " Which is: \"y\"\n" + "Expected equality of these values:\n" + " foo\n" + " Which is: \"x\"\n" + " bar\n" + " Which is: \"y\"\n" "Ignoring case", msg5.c_str()); } @@ -3580,11 +3586,12 @@ TEST(AssertionTest, EqFailureWithDiff) { const std::string msg1( EqFailure("left", "right", left, right, false).failure_message()); EXPECT_STREQ( - " Expected: left\n" - " Which is: " + "Expected equality of these values:\n" + " left\n" + " Which is: " "1\\n2XXX\\n3\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n12XXX\\n13\\n14\\n15\n" - "To be equal to: right\n" - " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n" + " right\n" + " Which is: 1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n11\\n12\\n13\\n14\n" "With diff:\n@@ -1,5 +1,6 @@\n 1\n-2XXX\n+2\n 3\n+4\n 5\n 6\n" "@@ -7,8 +8,6 @@\n 8\n 9\n-10\n 11\n-12XXX\n+12\n 13\n 14\n-15\n", msg1.c_str()); @@ -3679,9 +3686,10 @@ TEST(ExpectTest, ASSERT_EQ_Double) { TEST(AssertionTest, ASSERT_EQ) { ASSERT_EQ(5, 2 + 3); EXPECT_FATAL_FAILURE(ASSERT_EQ(5, 2*3), - " Expected: 5\n" - "To be equal to: 2*3\n" - " Which is: 6"); + "Expected equality of these values:\n" + " 5\n" + " 2*3\n" + " Which is: 6"); } // Tests ASSERT_EQ(NULL, pointer). @@ -3698,7 +3706,7 @@ TEST(AssertionTest, ASSERT_EQ_NULL) { // A failure. static int n = 0; EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n), - "To be equal to: &n\n"); + " &n\n Which is:"); } #endif // GTEST_CAN_COMPARE_NULL @@ -3714,7 +3722,7 @@ TEST(ExpectTest, ASSERT_EQ_0) { // A failure. EXPECT_FATAL_FAILURE(ASSERT_EQ(0, 5.6), - "Expected: 0"); + " 0\n 5.6"); } // Tests ASSERT_NE. @@ -3813,7 +3821,7 @@ void TestEq1(int x) { // Tests calling a test subroutine that's not part of a fixture. TEST(AssertionTest, NonFixtureSubroutine) { EXPECT_FATAL_FAILURE(TestEq1(2), - "To be equal to: x"); + "Which is: 2"); } // An uncopyable class. @@ -3862,7 +3870,8 @@ TEST(AssertionTest, AssertWorksWithUncopyableObject) { EXPECT_FATAL_FAILURE(TestAssertNonPositive(), "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); EXPECT_FATAL_FAILURE(TestAssertEqualsUncopyable(), - "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1"); + "Expected equality of these values:\n" + " x\n Which is: 5\n y\n Which is: -1"); } // Tests that uncopyable objects can be used in expects. @@ -3874,7 +3883,8 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) { "IsPositiveUncopyable(y) evaluates to false, where\ny evaluates to -1"); EXPECT_EQ(x, x); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(x, y), - "Expected: x\n Which is: 5\nTo be equal to: y\n Which is: -1"); + "Expected equality of these values:\n" + " x\n Which is: 5\n y\n Which is: -1"); } enum NamedEnum { @@ -3950,7 +3960,7 @@ TEST(AssertionTest, AnonymousEnum) { // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), - "To be equal to: kCaseB"); + "kCaseB"); EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), "Which is: 42"); # endif @@ -4390,9 +4400,10 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) { TEST(ExpectTest, EXPECT_EQ) { EXPECT_EQ(5, 2 + 3); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2*3), - " Expected: 5\n" - "To be equal to: 2*3\n" - " Which is: 6"); + "Expected equality of these values:\n" + " 5\n" + " 2*3\n" + " Which is: 6"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(5, 2 - 3), "2 - 3"); } @@ -4423,7 +4434,7 @@ TEST(ExpectTest, EXPECT_EQ_NULL) { // A failure. int n = 0; EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n), - "To be equal to: &n\n"); + "&n\n"); } #endif // GTEST_CAN_COMPARE_NULL @@ -4439,7 +4450,7 @@ TEST(ExpectTest, EXPECT_EQ_0) { // A failure. EXPECT_NONFATAL_FAILURE(EXPECT_EQ(0, 5.6), - "Expected: 0"); + "Expected equality of these values:\n 0\n 5.6"); } // Tests EXPECT_NE. @@ -4539,7 +4550,7 @@ TEST(ExpectTest, EXPECT_ANY_THROW) { TEST(ExpectTest, ExpectPrecedence) { EXPECT_EQ(1 < 2, true); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false), - "To be equal to: true && false"); + "true && false"); } @@ -4686,7 +4697,7 @@ TEST(EqAssertionTest, Bool) { EXPECT_FATAL_FAILURE({ bool false_value = false; ASSERT_EQ(false_value, true); - }, "To be equal to: true"); + }, "Which is: false"); } // Tests using int values in {EXPECT|ASSERT}_EQ. @@ -4720,10 +4731,11 @@ TEST(EqAssertionTest, WideChar) { EXPECT_EQ(L'b', L'b'); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(L'\0', L'x'), - " Expected: L'\0'\n" - " Which is: L'\0' (0, 0x0)\n" - "To be equal to: L'x'\n" - " Which is: L'x' (120, 0x78)"); + "Expected equality of these values:\n" + " L'\0'\n" + " Which is: L'\0' (0, 0x0)\n" + " L'x'\n" + " Which is: L'x' (120, 0x78)"); static wchar_t wchar; wchar = L'b'; @@ -4731,7 +4743,7 @@ TEST(EqAssertionTest, WideChar) { "wchar"); wchar = 0x8119; EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast(0x8120), wchar), - "To be equal to: wchar"); + "wchar"); } // Tests using ::std::string values in {EXPECT|ASSERT}_EQ. @@ -4760,8 +4772,8 @@ TEST(EqAssertionTest, StdString) { static ::std::string str3(str1); str3.at(2) = '\0'; EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3), - "To be equal to: str3\n" - " Which is: \"A \\0 in the middle\""); + " str3\n" + " Which is: \"A \\0 in the middle\""); } #if GTEST_HAS_STD_WSTRING @@ -4881,7 +4893,7 @@ TEST(EqAssertionTest, CharPointer) { ASSERT_EQ(p1, p1); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), - "To be equal to: p2"); + "p2"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), "p2"); EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast(0x1234), @@ -4903,7 +4915,7 @@ TEST(EqAssertionTest, WideCharPointer) { EXPECT_EQ(p0, p0); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), - "To be equal to: p2"); + "p2"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), "p2"); void* pv3 = (void*)0x1234; // NOLINT diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index e940a5aa..9f92f982 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -64,20 +64,23 @@ EXPECTED_NON_EMPTY_XML = """ - + - - + + From 9681b4c8e6aae36ac1d0ae0c4e99bdf013b41913 Mon Sep 17 00:00:00 2001 From: ly2048 <31530391+ly2048@users.noreply.github.com> Date: Thu, 14 Sep 2017 13:22:04 +0800 Subject: [PATCH 11/13] Add explicit `CMAKE_DEBUG_POSTFIX` option Enable generating different library name to be compatible with CMake's `FindGTest`. --- googletest/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 8391dbd0..b9a920b7 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -27,6 +27,8 @@ option( "Build gtest with internal symbols hidden in shared libraries." OFF) +set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Generate debug library name with a postfix.") + # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). include(cmake/hermetic_build.cmake OPTIONAL) From d4af64ca13173c76f6da1aa32dcda7dd3abeb522 Mon Sep 17 00:00:00 2001 From: Benjamin Kircher Date: Sat, 16 Sep 2017 11:51:36 +0200 Subject: [PATCH 12/13] Remove redundant declaration TempDir() function is declared twice, once in `internal/gtest-port.h` and a second time in `gtest.h`. Fixes a warning with GCC when -Wredundant-decls is given. --- googletest/include/gtest/internal/gtest-port.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 643beff9..12bdb4c3 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2591,10 +2591,6 @@ std::string StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal -// Returns a path to temporary directory. -// Tries to determine an appropriate directory for the platform. -GTEST_API_ std::string TempDir(); - } // namespace testing #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ From d30a37e743e45de88b85333756bb938d2f6eeecd Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 21 Sep 2017 10:54:14 -0400 Subject: [PATCH 13/13] Revert "Allow macros inside of parametrized test names." --- googletest/include/gtest/gtest-param-test.h | 15 ++++------ .../include/gtest/gtest-param-test.h.pump | 9 ++---- googletest/test/gtest-param-test_test.cc | 28 ------------------- 3 files changed, 9 insertions(+), 43 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index e01c3ff6..038f9ba7 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -1375,10 +1375,7 @@ internal::CartesianProductHolder10AddTestPattern(\ - GTEST_STRINGIFY_(test_case_name), \ - GTEST_STRINGIFY_(test_name), \ + #test_case_name, \ + #test_name, \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ @@ -1415,11 +1412,11 @@ internal::CartesianProductHolder10, and return std::string. // // testing::PrintToStringParamName is a builtin test suffix generator that -// returns the value of testing::PrintToString(GetParam()). +// returns the value of testing::PrintToString(GetParam()). It does not work +// for std::string or C strings. // // Note: test names must be non-empty, unique, and may only contain ASCII -// alphanumeric characters or underscore. Because PrintToString adds quotes -// to std::string and C strings, it won't work for these types. +// alphanumeric characters or underscore. # define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \ ::testing::internal::ParamGenerator \ diff --git a/googletest/include/gtest/gtest-param-test.h.pump b/googletest/include/gtest/gtest-param-test.h.pump index 8ab18dd0..3078d6d2 100644 --- a/googletest/include/gtest/gtest-param-test.h.pump +++ b/googletest/include/gtest/gtest-param-test.h.pump @@ -441,10 +441,7 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( ]] # endif // GTEST_HAS_COMBINE -// Use a macro to stringify the test (case) name, because direct stringification -// does not work if one of the arguments is itself a macro -// (https://gcc.gnu.org/onlinedocs/cpp/Stringification.html). -# define GTEST_STRINGIFY_(name) #name + # define TEST_P(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ @@ -459,8 +456,8 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( #test_case_name, \ ::testing::internal::CodeLocation(\ __FILE__, __LINE__))->AddTestPattern(\ - GTEST_STRINGIFY_(test_case_name), \ - GTEST_STRINGIFY_(test_name), \ + #test_case_name, \ + #test_name, \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 9d6f09fd..d1b0644f 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -809,34 +809,6 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); -// Tests that macros in test names are expanded correctly. -class MacroNamingTest : public TestWithParam {}; - -#define PREFIX_WITH_FOO(test_name) FOO_##test_name -#define PREFIX_WITH_MACRO(test_name) Macro##test_name - -TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { - const ::testing::TestInfo* const test_info = - ::testing::UnitTest::GetInstance()->current_test_info(); - - EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name()); - EXPECT_STREQ("FOO_SomeTestName", test_info->name()); -} - -INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); - -// Tests the same thing for non-parametrized tests. -class MacroNamingTestNonParametrized : public ::testing::Test {}; - -TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), - PREFIX_WITH_FOO(SomeTestName)) { - const ::testing::TestInfo* const test_info = - ::testing::UnitTest::GetInstance()->current_test_info(); - - EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name()); - EXPECT_STREQ("FOO_SomeTestName", test_info->name()); -} - // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible