From c2f7c754e62a0de338a470d6987a4873827d4045 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 28 Feb 2013 22:55:25 +0000 Subject: Removes an unused variable; also refactors to support an up-coming googlemock change. git-svn-id: http://googletest.googlecode.com/svn/trunk@640 861a406c-534a-0410-8894-cb66d6ee9925 --- include/gtest/internal/gtest-internal.h | 19 +++++++++++++++++++ src/gtest-internal-inl.h | 1 - src/gtest.cc | 31 +++++++++++++------------------ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ca4e1fd..892ddec 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -46,6 +46,10 @@ # include #endif // GTEST_OS_LINUX +#if GTEST_HAS_EXCEPTIONS +# include +#endif + #include #include #include @@ -166,6 +170,21 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT GTEST_API_ std::string AppendUserMessage( const std::string& gtest_msg, const Message& user_msg); +#if GTEST_HAS_EXCEPTIONS + +// This exception is thrown by (and only by) a failed Google Test +// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions +// are enabled). We derive it from std::runtime_error, which is for +// errors presumably detectable only at run time. Since +// std::runtime_error inherits from std::exception, many testing +// frameworks know how to extract and print the message inside it. +class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error { + public: + explicit GoogleTestFailureException(const TestPartResult& failure); +}; + +#endif // GTEST_HAS_EXCEPTIONS + // A helper class for creating scoped traces in user programs. class GTEST_API_ ScopedTrace { public: diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index c96c941..d661043 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -215,7 +215,6 @@ class GTestFlagSaver { bool list_tests_; std::string output_; bool print_time_; - bool pretty_; internal::Int32 random_seed_; internal::Int32 repeat_; bool shuffle_; diff --git a/src/gtest.cc b/src/gtest.cc index c9bf458..1ade269 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -1903,6 +1903,8 @@ static std::string* FormatSehExceptionMessage(DWORD exception_code, #endif // GTEST_HAS_SEH +namespace internal { + #if GTEST_HAS_EXCEPTIONS // Adds an "exception thrown" fatal failure to the current test. @@ -1922,20 +1924,12 @@ static std::string FormatCxxExceptionMessage(const char* description, static std::string PrintTestPartResultToString( const TestPartResult& test_part_result); -// A failed Google Test assertion will throw an exception of this type when -// GTEST_FLAG(throw_on_failure) is true (if exceptions are enabled). We -// derive it from std::runtime_error, which is for errors presumably -// detectable only at run time. Since std::runtime_error inherits from -// std::exception, many testing frameworks know how to extract and print the -// message inside it. -class GoogleTestFailureException : public ::std::runtime_error { - public: - explicit GoogleTestFailureException(const TestPartResult& failure) - : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {} -}; +GoogleTestFailureException::GoogleTestFailureException( + const TestPartResult& failure) + : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {} + #endif // GTEST_HAS_EXCEPTIONS -namespace internal { // We put these helper functions in the internal namespace as IBM's xlC // compiler rejects the code if they were declared static. @@ -2001,9 +1995,10 @@ Result HandleExceptionsInMethodIfSupported( #if GTEST_HAS_EXCEPTIONS try { return HandleSehExceptionsInMethodIfSupported(object, method, location); - } catch (const GoogleTestFailureException&) { // NOLINT - // This exception doesn't originate in code under test. It makes no - // sense to report it as a test failure. + } catch (const internal::GoogleTestFailureException&) { // NOLINT + // This exception type can only be thrown by a failed Google + // Test assertion with the intention of letting another testing + // framework catch it. Therefore we just re-throw it. throw; } catch (const std::exception& e) { // NOLINT internal::ReportFailureInUnknownLocation( @@ -2390,6 +2385,8 @@ static const char * TestPartResultTypeToString(TestPartResult::Type type) { } } +namespace internal { + // Prints a TestPartResult to an std::string. static std::string PrintTestPartResultToString( const TestPartResult& test_part_result) { @@ -2421,8 +2418,6 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { // class PrettyUnitTestResultPrinter -namespace internal { - enum GTestColor { COLOR_DEFAULT, COLOR_RED, @@ -3601,7 +3596,7 @@ void UnitTest::AddTestPartResult( #endif // GTEST_OS_WINDOWS } else if (GTEST_FLAG(throw_on_failure)) { #if GTEST_HAS_EXCEPTIONS - throw GoogleTestFailureException(result); + throw internal::GoogleTestFailureException(result); #else // We cannot call abort() as it generates a pop-up in debug mode // that cannot be suppressed in VC 7.1 or below. -- cgit v1.2.1