Simplifies the implementation of GTEST_LOG_ & GTEST_LOG_; renames

GTEST_HIDE_UNREACHABLE_CODE_ to
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ (by Vlad Losev).
This commit is contained in:
zhanyong.wan
2009-09-16 06:59:17 +00:00
parent b2ee82ebf9
commit 866f4a9446
6 changed files with 63 additions and 74 deletions

View File

@@ -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];

View File

@@ -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;
}