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

Unified Diff: base/test/gtest_xml_unittest_result_printer.cc

Issue 2846673004: Set limit for number of failed EXPECTs per test in test launcher output. (Closed)
Patch Set: Fix missed constant usage. Created 3 years, 7 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
« no previous file with comments | « no previous file | base/test/launcher/unit_test_launcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/gtest_xml_unittest_result_printer.cc
diff --git a/base/test/gtest_xml_unittest_result_printer.cc b/base/test/gtest_xml_unittest_result_printer.cc
index 31ac4ad39c70490f810083f6622021a2a34e1b9f..81a3d9fbc626c9a4e10a63529c0689a073b491e2 100644
--- a/base/test/gtest_xml_unittest_result_printer.cc
+++ b/base/test/gtest_xml_unittest_result_printer.cc
@@ -5,14 +5,23 @@
#include "base/test/gtest_xml_unittest_result_printer.h"
#include "base/base64.h"
+#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
+#include "base/test/test_switches.h"
#include "base/time/time.h"
namespace base {
-XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {
-}
+namespace {
+const int kDefaultTestPartResultsLimit = 10;
+
+const char kTestPartLesultsLimitExceeded[] =
+ "Test part results limit exceeded. Use --test-launcher-test-part-limit to "
+ "increase or disable limit.";
+} // namespace
+
+XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {}
XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() {
if (output_file_) {
@@ -73,12 +82,33 @@ void XmlUnitTestResultPrinter::OnTestEnd(const testing::TestInfo& test_info) {
fprintf(output_file_,
" <failure message=\"\" type=\"\"></failure>\n");
}
- for (int i = 0; i < test_info.result()->total_part_count(); ++i) {
+
+ int limit = test_info.result()->total_part_count();
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kTestLauncherTestPartResultsLimit)) {
+ std::string limit_str =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kTestLauncherTestPartResultsLimit);
+ int test_part_results_limit = std::strtol(limit_str.c_str(), nullptr, 10);
+ if (test_part_results_limit >= 0)
+ limit = std::min(limit, test_part_results_limit);
+ } else {
+ limit = std::min(limit, kDefaultTestPartResultsLimit);
+ }
+
+ for (int i = 0; i < limit; ++i) {
const auto& test_part_result = test_info.result()->GetTestPartResult(i);
WriteTestPartResult(test_part_result.file_name(),
test_part_result.line_number(), test_part_result.type(),
test_part_result.summary(), test_part_result.message());
}
+
+ if (test_info.result()->total_part_count() > limit) {
+ WriteTestPartResult(
+ "<unknown>", 0, testing::TestPartResult::kNonFatalFailure,
+ kTestPartLesultsLimitExceeded, kTestPartLesultsLimitExceeded);
+ }
+
fprintf(output_file_, " </testcase>\n");
fflush(output_file_);
}
« no previous file with comments | « no previous file | base/test/launcher/unit_test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698