OLD | NEW |
---|---|
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/command_line.h" | |
8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/test/test_switches.h" | |
10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
11 | 13 |
12 namespace base { | 14 namespace base { |
13 | 15 |
14 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) { | 16 namespace { |
17 const int kDefaultTestPartResultsLimit = 10; | |
18 | |
19 const char kTestPartLesultsLimitExceeded[] = | |
20 "Test part results limit exceeded. Use --test-launcher-test-part-limit to " | |
21 "increase or disable limit."; | |
15 } | 22 } |
Paweł Hajdan Jr.
2017/05/15 12:39:00
nit: // namespace
alex-ac
2017/05/15 12:53:16
Done.
| |
16 | 23 |
24 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {} | |
25 | |
17 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { | 26 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { |
18 if (output_file_) { | 27 if (output_file_) { |
19 fprintf(output_file_, "</testsuites>\n"); | 28 fprintf(output_file_, "</testsuites>\n"); |
20 fflush(output_file_); | 29 fflush(output_file_); |
21 CloseFile(output_file_); | 30 CloseFile(output_file_); |
22 } | 31 } |
23 } | 32 } |
24 | 33 |
25 bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) { | 34 bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) { |
26 DCHECK(!output_file_); | 35 DCHECK(!output_file_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\"" | 75 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\"" |
67 " classname=\"%s\">\n", | 76 " classname=\"%s\">\n", |
68 test_info.name(), | 77 test_info.name(), |
69 static_cast<double>(test_info.result()->elapsed_time()) / | 78 static_cast<double>(test_info.result()->elapsed_time()) / |
70 Time::kMillisecondsPerSecond, | 79 Time::kMillisecondsPerSecond, |
71 test_info.test_case_name()); | 80 test_info.test_case_name()); |
72 if (test_info.result()->Failed()) { | 81 if (test_info.result()->Failed()) { |
73 fprintf(output_file_, | 82 fprintf(output_file_, |
74 " <failure message=\"\" type=\"\"></failure>\n"); | 83 " <failure message=\"\" type=\"\"></failure>\n"); |
75 } | 84 } |
76 for (int i = 0; i < test_info.result()->total_part_count(); ++i) { | 85 |
86 int limit = test_info.result()->total_part_count(); | |
87 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
88 switches::kTestLauncherTestPartResultsLimit)) { | |
89 std::string limit_str = | |
90 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
91 switches::kTestLauncherTestPartResultsLimit); | |
92 int test_part_results_limit = std::strtol(limit_str.c_str(), nullptr, 10); | |
93 if (test_part_results_limit >= 0) | |
94 limit = std::min(limit, test_part_results_limit); | |
95 } | |
96 | |
97 for (int i = 0; i < limit; ++i) { | |
77 const auto& test_part_result = test_info.result()->GetTestPartResult(i); | 98 const auto& test_part_result = test_info.result()->GetTestPartResult(i); |
78 WriteTestPartResult(test_part_result.file_name(), | 99 WriteTestPartResult(test_part_result.file_name(), |
79 test_part_result.line_number(), test_part_result.type(), | 100 test_part_result.line_number(), test_part_result.type(), |
80 test_part_result.summary(), test_part_result.message()); | 101 test_part_result.summary(), test_part_result.message()); |
81 } | 102 } |
103 | |
104 if (test_info.result()->total_part_count() > limit) { | |
105 WriteTestPartResult( | |
106 "<unknown>", 0, testing::TestPartResult::kNonFatalFailure, | |
107 kTestPartLesultsLimitExceeded, kTestPartLesultsLimitExceeded); | |
108 } | |
109 | |
82 fprintf(output_file_, " </testcase>\n"); | 110 fprintf(output_file_, " </testcase>\n"); |
83 fflush(output_file_); | 111 fflush(output_file_); |
84 } | 112 } |
85 | 113 |
86 void XmlUnitTestResultPrinter::OnTestCaseEnd( | 114 void XmlUnitTestResultPrinter::OnTestCaseEnd( |
87 const testing::TestCase& test_case) { | 115 const testing::TestCase& test_case) { |
88 fprintf(output_file_, " </testsuite>\n"); | 116 fprintf(output_file_, " </testsuite>\n"); |
89 fflush(output_file_); | 117 fflush(output_file_); |
90 } | 118 } |
91 | 119 |
(...skipping 22 matching lines...) Expand all Loading... | |
114 fprintf(output_file_, | 142 fprintf(output_file_, |
115 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" | 143 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" |
116 " <summary>%s</summary>\n" | 144 " <summary>%s</summary>\n" |
117 " <message>%s</message>\n" | 145 " <message>%s</message>\n" |
118 " </x-test-result-part>\n", | 146 " </x-test-result-part>\n", |
119 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); | 147 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); |
120 fflush(output_file_); | 148 fflush(output_file_); |
121 } | 149 } |
122 | 150 |
123 } // namespace base | 151 } // namespace base |
OLD | NEW |