Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4287)

Unified Diff: base/test/test_suite.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Add comment. Fix missed usage of SetLogAssertHandler. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/test_suite.cc
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index 6f4cc372cb86ad73f9388740e5a9f0c05652cc88..a1bc8cbbc38b88f597715674b3aa26c08b347ff5 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -65,6 +65,8 @@ namespace base {
namespace {
+TestSuite* g_test_suite = nullptr;
Paweł Hajdan Jr. 2017/01/27 17:19:44 This shouldn't be needed now, right?
alex-ac 2017/02/11 20:12:20 Done.
+
class MaybeTestDisabler : public testing::EmptyTestEventListener {
public:
void OnTestStart(const testing::TestInfo& test_info) override {
@@ -158,6 +160,8 @@ TestSuite::TestSuite(int argc, wchar_t** argv)
TestSuite::~TestSuite() {
if (initialized_command_line_)
CommandLine::Reset();
+
+ g_test_suite = nullptr;
}
void TestSuite::InitializeFromCommandLine(int argc, char** argv) {
@@ -180,6 +184,7 @@ void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) {
#endif // defined(OS_WIN)
void TestSuite::PreInitialize() {
+ g_test_suite = this;
#if defined(OS_WIN)
testing::GTEST_FLAG(catch_exceptions) = false;
#endif
@@ -238,11 +243,11 @@ void TestSuite::AddTestLauncherResultPrinter() {
return;
}
- XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter;
- CHECK(printer->Initialize(output_path));
+ printer_ = new XmlUnitTestResultPrinter;
+ CHECK(printer_->Initialize(output_path));
testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
- listeners.Append(printer);
+ listeners.Append(printer_);
}
// Don't add additional code to this method. Instead add it to
@@ -283,7 +288,11 @@ int TestSuite::Run() {
}
// static
-void TestSuite::UnitTestAssertHandler(const std::string& str) {
+void TestSuite::UnitTestAssertHandler(const char* file,
+ int line,
+ size_t message_start,
+ size_t stack_start,
+ const std::string& str) {
#if defined(OS_ANDROID)
// Correlating test stdio with logcat can be difficult, so we emit this
// helpful little hint about what was running. Only do this for Android
@@ -298,6 +307,12 @@ void TestSuite::UnitTestAssertHandler(const std::string& str) {
}
#endif // defined(OS_ANDROID)
+ std::string message = str.substr(message_start);
+ std::string summary;
+
+ summary = message.substr(0, stack_start - message_start);
+ printer_->OnAssert(file, line, summary, message);
+
// The logging system actually prints the message before calling the assert
// handler. Just exit now to avoid printing too many stack traces.
_exit(1);
@@ -359,7 +374,8 @@ void TestSuite::Initialize() {
!CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) {
SuppressErrorDialogs();
debug::SetSuppressDebugUI(true);
- logging::SetLogAssertHandler(UnitTestAssertHandler);
+ assert_handler_ = logging::ScopedLogAssertHandler(
+ base::Bind(&TestSuite::UnitTestAssertHandler, base::Unretained(this)));
}
base::test::InitializeICUForTesting();

Powered by Google App Engine
This is Rietveld 408576698