From 8f04622cc1507a3954490a03a1dfcff9e340359e Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 13:45:27 -0400 Subject: [PATCH 1/4] 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 2/4] 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 be94bf501e649dfa6790b3cce2bbe300949b6e74 Mon Sep 17 00:00:00 2001 From: Herbert Thielen Date: Tue, 5 Sep 2017 17:45:48 +0200 Subject: [PATCH 3/4] 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 4/4] 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);