summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-16 06:59:17 (GMT)
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-16 06:59:17 (GMT)
commit866f4a94461d765f7f9514b6cb6e82d7b9ea12d2 (patch)
treeb3e87b28fc5283e1e0ac9222b5a0df5f3ada3484 /include
parentb2ee82ebf9b8f1be859d08611b768ae6c0700090 (diff)
downloadgoogletest-866f4a94461d765f7f9514b6cb6e82d7b9ea12d2.zip
googletest-866f4a94461d765f7f9514b6cb6e82d7b9ea12d2.tar.gz
googletest-866f4a94461d765f7f9514b6cb6e82d7b9ea12d2.tar.bz2
Simplifies the implementation of GTEST_LOG_ & GTEST_LOG_; renames
GTEST_HIDE_UNREACHABLE_CODE_ to GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ (by Vlad Losev).
Diffstat (limited to 'include')
-rw-r--r--include/gtest/internal/gtest-death-test-internal.h12
-rw-r--r--include/gtest/internal/gtest-internal.h10
-rw-r--r--include/gtest/internal/gtest-port.h57
3 files changed, 33 insertions, 46 deletions
diff --git a/include/gtest/internal/gtest-death-test-internal.h b/include/gtest/internal/gtest-death-test-internal.h
index d87bfa9..78fbae9 100644
--- a/include/gtest/internal/gtest-death-test-internal.h
+++ b/include/gtest/internal/gtest-death-test-internal.h
@@ -172,7 +172,7 @@ bool ExitedUnsuccessfully(int exit_status);
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
::testing::internal::DeathTest::ReturnSentinel \
gtest_sentinel(gtest_dt); \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
break; \
} \
@@ -253,17 +253,15 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
// statement unconditionally returns or throws. The Message constructor at
// the end allows the syntax of streaming additional messages into the
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
-// TODO(vladl@google.com): rename the GTEST_HIDE_UNREACHABLE_CODE_ macro to
-// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_.
#define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \
- GTEST_LOG_(WARNING, \
- "Death tests are not supported on this platform.\n" \
- "Statement '" #statement "' cannot be verified."); \
+ GTEST_LOG_(WARNING) \
+ << "Death tests are not supported on this platform.\n" \
+ << "Statement '" #statement "' cannot be verified."; \
} else if (!::testing::internal::AlwaysTrue()) { \
::testing::internal::RE::PartialMatch(".*", (regex)); \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
terminator; \
} else \
::testing::Message()
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h
index f0a7966..72272d9 100644
--- a/include/gtest/internal/gtest-internal.h
+++ b/include/gtest/internal/gtest-internal.h
@@ -767,7 +767,7 @@ bool AlwaysTrue();
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
// statement if it returns or throws (or doesn't return or throw in some
// situations).
-#define GTEST_HIDE_UNREACHABLE_CODE_(statement) \
+#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { statement; }
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
@@ -775,7 +775,7 @@ bool AlwaysTrue();
if (const char* gtest_msg = "") { \
bool gtest_caught_expected = false; \
try { \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
catch (expected_exception const&) { \
gtest_caught_expected = true; \
@@ -799,7 +799,7 @@ bool AlwaysTrue();
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \
try { \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
catch (...) { \
gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \
@@ -815,7 +815,7 @@ bool AlwaysTrue();
if (const char* gtest_msg = "") { \
bool gtest_caught_any = false; \
try { \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
catch (...) { \
gtest_caught_any = true; \
@@ -841,7 +841,7 @@ bool AlwaysTrue();
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
- GTEST_HIDE_UNREACHABLE_CODE_(statement); \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
"failures in the current thread.\n" \
diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h
index a5adbc0..d86f780 100644
--- a/include/gtest/internal/gtest-port.h
+++ b/include/gtest/internal/gtest-port.h
@@ -672,7 +672,8 @@ class RE {
};
// Defines logging utilities:
-// GTEST_LOG_() - logs messages at the specified severity level.
+// GTEST_LOG_(severity) - logs messages at the specified severity level. The
+// message itself is streamed into the macro.
// LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages.
@@ -683,13 +684,27 @@ enum GTestLogSeverity {
GTEST_FATAL
};
-void GTestLog(GTestLogSeverity severity, const char* file,
- int line, const char* msg);
+// Formats log entry severity, provides a stream object for streaming the
+// log message, and terminates the message with a newline when going out of
+// scope.
+class GTestLog {
+ public:
+ GTestLog(GTestLogSeverity severity, const char* file, int line);
+
+ // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
+ ~GTestLog();
+
+ ::std::ostream& GetStream() { return ::std::cerr; }
+
+ private:
+ const GTestLogSeverity severity_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
+};
-#define GTEST_LOG_(severity, msg)\
- ::testing::internal::GTestLog(\
- ::testing::internal::GTEST_##severity, __FILE__, __LINE__, \
- (::testing::Message() << (msg)).GetString().c_str())
+#define GTEST_LOG_(severity) \
+ ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
+ __FILE__, __LINE__).GetStream()
inline void LogToStderr() {}
inline void FlushInfoLog() { fflush(NULL); }
@@ -1011,38 +1026,12 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
// condition itself, plus additional message streamed into it, if any,
// and then it aborts the program. It aborts the program irrespective of
// whether it is built in the debug mode or not.
-class GTestCheckProvider {
- public:
- GTestCheckProvider(const char* condition, const char* file, int line) {
- FormatFileLocation(file, line);
- ::std::cerr << " ERROR: Condition " << condition << " failed. ";
- }
- ~GTestCheckProvider() {
- ::std::cerr << ::std::endl;
- posix::Abort();
- }
- void FormatFileLocation(const char* file, int line) {
- if (file == NULL)
- file = "unknown file";
- if (line < 0) {
- ::std::cerr << file << ":";
- } else {
-#if _MSC_VER
- ::std::cerr << file << "(" << line << "):";
-#else
- ::std::cerr << file << ":" << line << ":";
-#endif
- }
- }
- ::std::ostream& GetStream() { return ::std::cerr; }
-};
#define GTEST_CHECK_(condition) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (condition) \
; \
else \
- ::testing::internal::GTestCheckProvider(\
- #condition, __FILE__, __LINE__).GetStream()
+ GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
// Macro for referencing flags.
#define GTEST_FLAG(name) FLAGS_gtest_##name