diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-02-02 01:25:37 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-02-02 01:25:37 (GMT) |
commit | 40d0ba7a62a8bc749fbaf0747621b0aa10ddf1b9 (patch) | |
tree | 856fa37e8b637bae48943f0e9fe6df3d73ad125c /src | |
parent | b147ec394bc024dc63860f0a982ecd82106b8e40 (diff) | |
download | googletest-40d0ba7a62a8bc749fbaf0747621b0aa10ddf1b9.zip googletest-40d0ba7a62a8bc749fbaf0747621b0aa10ddf1b9.tar.gz googletest-40d0ba7a62a8bc749fbaf0747621b0aa10ddf1b9.tar.bz2 |
Add markers to death test messages to make them more recogizable (by Jeff Shute).
Diffstat (limited to 'src')
-rw-r--r-- | src/gtest-death-test.cc | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 3ab9cf9..3e65193 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -438,6 +438,24 @@ void DeathTestImpl::Abort(AbortReason reason) { _exit(1); // Exits w/o any normal exit hooks (we were supposed to crash) } +// Returns an indented copy of stderr output for a death test. +// This makes distinguishing death test output lines from regular log lines +// much easier. +static ::std::string FormatDeathTestOutput(const ::std::string& output) { + ::std::string ret; + for (size_t at = 0; ; ) { + const size_t line_end = output.find('\n', at); + ret += "[ DEATH ] "; + if (line_end == ::std::string::npos) { + ret += output.substr(at); + break; + } + ret += output.substr(at, line_end + 1 - at); + at = line_end + 1; + } + return ret; +} + // Assesses the success or failure of a death test, using both private // members which have previously been set, and one argument: // @@ -473,15 +491,15 @@ bool DeathTestImpl::Passed(bool status_ok) { switch (outcome()) { case LIVED: buffer << " Result: failed to die.\n" - << " Error msg: " << error_message; + << " Error msg:\n" << FormatDeathTestOutput(error_message); break; case THREW: buffer << " Result: threw an exception.\n" - << " Error msg: " << error_message; + << " Error msg:\n" << FormatDeathTestOutput(error_message); break; case RETURNED: buffer << " Result: illegal return in test statement.\n" - << " Error msg: " << error_message; + << " Error msg:\n" << FormatDeathTestOutput(error_message); break; case DIED: if (status_ok) { @@ -491,11 +509,12 @@ bool DeathTestImpl::Passed(bool status_ok) { } else { buffer << " Result: died but not with expected error.\n" << " Expected: " << regex()->pattern() << "\n" - << "Actual msg: " << error_message; + << "Actual msg:\n" << FormatDeathTestOutput(error_message); } } else { buffer << " Result: died but not with expected exit code:\n" - << " " << ExitSummary(status()) << "\n"; + << " " << ExitSummary(status()) << "\n" + << "Actual msg:\n" << FormatDeathTestOutput(error_message); } break; case IN_PROGRESS: |