summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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 'src')
-rw-r--r--src/gtest-death-test.cc25
-rw-r--r--src/gtest-port.cc21
2 files changed, 24 insertions, 22 deletions
diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc
index d975af7..91f16de 100644
--- a/src/gtest-death-test.cc
+++ b/src/gtest-death-test.cc
@@ -269,13 +269,12 @@ static void FailFromInternalError(int fd) {
} while (num_read == -1 && errno == EINTR);
if (num_read == 0) {
- GTEST_LOG_(FATAL, error);
+ GTEST_LOG_(FATAL) << error.GetString().c_str();
} else {
const int last_error = errno;
const String message = GetLastErrnoDescription();
- GTEST_LOG_(FATAL,
- Message() << "Error while reading death test internal: "
- << message << " [" << last_error << "]");
+ GTEST_LOG_(FATAL) << "Error while reading death test internal: "
+ << message.c_str() << " [" << last_error << "]";
}
}
@@ -397,15 +396,13 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
FailFromInternalError(read_fd()); // Does not return.
break;
default:
- GTEST_LOG_(FATAL,
- Message() << "Death test child process reported "
- << "unexpected status byte ("
- << static_cast<unsigned int>(flag) << ")");
+ GTEST_LOG_(FATAL) << "Death test child process reported "
+ << "unexpected status byte ("
+ << static_cast<unsigned int>(flag) << ")";
}
} else {
- GTEST_LOG_(FATAL,
- Message() << "Read from death test child process failed: "
- << GetLastErrnoDescription());
+ GTEST_LOG_(FATAL) << "Read from death test child process failed: "
+ << GetLastErrnoDescription().c_str();
}
GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
set_read_fd(-1);
@@ -484,8 +481,8 @@ bool DeathTestImpl::Passed(bool status_ok) {
break;
case IN_PROGRESS:
default:
- GTEST_LOG_(FATAL,
- "DeathTest::Passed somehow called before conclusion of test");
+ GTEST_LOG_(FATAL)
+ << "DeathTest::Passed somehow called before conclusion of test";
}
DeathTest::set_last_death_test_message(buffer.GetString());
@@ -741,7 +738,7 @@ class NoExecDeathTest : public ForkingDeathTest {
DeathTest::TestRole NoExecDeathTest::AssumeRole() {
const size_t thread_count = GetThreadCount();
if (thread_count != 1) {
- GTEST_LOG_(WARNING, DeathTestThreadWarning(thread_count));
+ GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);
}
int pipe_fd[2];
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index ec107a5..ba9a9a2 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -417,20 +417,25 @@ void RE::Init(const char* regex) {
#endif // GTEST_USES_POSIX_RE
-// Logs a message at the given severity level.
-void GTestLog(GTestLogSeverity severity, const char* file,
- int line, const char* msg) {
+
+GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
+ : severity_(severity) {
const char* const marker =
severity == GTEST_INFO ? "[ INFO ]" :
severity == GTEST_WARNING ? "[WARNING]" :
severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]";
- fprintf(stderr, "\n%s %s:%d: %s\n", marker, file, line, msg);
- if (severity == GTEST_FATAL) {
- fflush(NULL); // abort() is not guaranteed to flush open file streams.
+ GetStream() << ::std::endl << marker << " "
+ << FormatFileLocation(file, line).c_str() << ": ";
+}
+
+// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
+GTestLog::~GTestLog() {
+ GetStream() << ::std::endl;
+ if (severity_ == GTEST_FATAL) {
+ fflush(stderr);
posix::Abort();
}
}
-
// Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close)
#ifdef _MSC_VER
@@ -537,7 +542,7 @@ static String ReadEntireFile(FILE * file) {
// Starts capturing stderr.
void CaptureStderr() {
if (g_captured_stderr != NULL) {
- GTEST_LOG_(FATAL, "Only one stderr capturer can exist at one time.");
+ GTEST_LOG_(FATAL) << "Only one stderr capturer can exist at one time.";
}
g_captured_stderr = new CapturedStderr;
}