Chromium Code Reviews| 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..a3040b3cb4a064ac5016293f2d982490bb2ffd23 100644 |
| --- a/base/test/gtest_xml_unittest_result_printer.cc |
| +++ b/base/test/gtest_xml_unittest_result_printer.cc |
| @@ -5,15 +5,24 @@ |
| #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."; |
| } |
|
Paweł Hajdan Jr.
2017/05/15 12:39:00
nit: // namespace
alex-ac
2017/05/15 12:53:16
Done.
|
| +XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {} |
| + |
| XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { |
| if (output_file_) { |
| fprintf(output_file_, "</testsuites>\n"); |
| @@ -73,12 +82,31 @@ 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); |
| + } |
| + |
| + 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_); |
| } |