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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/gtest_xml_unittest_result_printer.h" 5 #include "base/test/gtest_xml_unittest_result_printer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) { 14 namespace {
15 const int kDefaultTestPartResultsLimit = 10;
15 } 16 }
16 17
18 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter()
19 : output_file_(NULL),
20 test_part_results_limit_(kDefaultTestPartResultsLimit) {}
21
17 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { 22 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() {
18 if (output_file_) { 23 if (output_file_) {
19 fprintf(output_file_, "</testsuites>\n"); 24 fprintf(output_file_, "</testsuites>\n");
20 fflush(output_file_); 25 fflush(output_file_);
21 CloseFile(output_file_); 26 CloseFile(output_file_);
22 } 27 }
23 } 28 }
24 29
25 bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) { 30 bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) {
26 DCHECK(!output_file_); 31 DCHECK(!output_file_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\"" 71 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\""
67 " classname=\"%s\">\n", 72 " classname=\"%s\">\n",
68 test_info.name(), 73 test_info.name(),
69 static_cast<double>(test_info.result()->elapsed_time()) / 74 static_cast<double>(test_info.result()->elapsed_time()) /
70 Time::kMillisecondsPerSecond, 75 Time::kMillisecondsPerSecond,
71 test_info.test_case_name()); 76 test_info.test_case_name());
72 if (test_info.result()->Failed()) { 77 if (test_info.result()->Failed()) {
73 fprintf(output_file_, 78 fprintf(output_file_,
74 " <failure message=\"\" type=\"\"></failure>\n"); 79 " <failure message=\"\" type=\"\"></failure>\n");
75 } 80 }
76 for (int i = 0; i < test_info.result()->total_part_count(); ++i) { 81
82 int limit = test_info.result()->total_part_count();
83 if (has_test_part_results_limit())
84 limit = std::min(limit, test_part_results_limit());
85
86 for (int i = 0; i < limit; ++i) {
Paweł Hajdan Jr. 2017/05/05 17:33:03 We need to add something in case the limit is exce
alex-ac 2017/05/07 12:07:24 Done.
77 const auto& test_part_result = test_info.result()->GetTestPartResult(i); 87 const auto& test_part_result = test_info.result()->GetTestPartResult(i);
78 WriteTestPartResult(test_part_result.file_name(), 88 WriteTestPartResult(test_part_result.file_name(),
79 test_part_result.line_number(), test_part_result.type(), 89 test_part_result.line_number(), test_part_result.type(),
80 test_part_result.summary(), test_part_result.message()); 90 test_part_result.summary(), test_part_result.message());
81 } 91 }
92
82 fprintf(output_file_, " </testcase>\n"); 93 fprintf(output_file_, " </testcase>\n");
83 fflush(output_file_); 94 fflush(output_file_);
84 } 95 }
85 96
86 void XmlUnitTestResultPrinter::OnTestCaseEnd( 97 void XmlUnitTestResultPrinter::OnTestCaseEnd(
87 const testing::TestCase& test_case) { 98 const testing::TestCase& test_case) {
88 fprintf(output_file_, " </testsuite>\n"); 99 fprintf(output_file_, " </testsuite>\n");
89 fflush(output_file_); 100 fflush(output_file_);
90 } 101 }
91 102
(...skipping 22 matching lines...) Expand all
114 fprintf(output_file_, 125 fprintf(output_file_,
115 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" 126 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n"
116 " <summary>%s</summary>\n" 127 " <summary>%s</summary>\n"
117 " <message>%s</message>\n" 128 " <message>%s</message>\n"
118 " </x-test-result-part>\n", 129 " </x-test-result-part>\n",
119 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); 130 type, file, line, summary_encoded.c_str(), message_encoded.c_str());
120 fflush(output_file_); 131 fflush(output_file_);
121 } 132 }
122 133
123 } // namespace base 134 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698