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 { |
15 } | 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."; |
| 22 } // namespace |
| 23 |
| 24 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() : output_file_(NULL) {} |
16 | 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) { |
(...skipping 40 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 } else { |
| 96 limit = std::min(limit, kDefaultTestPartResultsLimit); |
| 97 } |
| 98 |
| 99 for (int i = 0; i < limit; ++i) { |
77 const auto& test_part_result = test_info.result()->GetTestPartResult(i); | 100 const auto& test_part_result = test_info.result()->GetTestPartResult(i); |
78 WriteTestPartResult(test_part_result.file_name(), | 101 WriteTestPartResult(test_part_result.file_name(), |
79 test_part_result.line_number(), test_part_result.type(), | 102 test_part_result.line_number(), test_part_result.type(), |
80 test_part_result.summary(), test_part_result.message()); | 103 test_part_result.summary(), test_part_result.message()); |
81 } | 104 } |
| 105 |
| 106 if (test_info.result()->total_part_count() > limit) { |
| 107 WriteTestPartResult( |
| 108 "<unknown>", 0, testing::TestPartResult::kNonFatalFailure, |
| 109 kTestPartLesultsLimitExceeded, kTestPartLesultsLimitExceeded); |
| 110 } |
| 111 |
82 fprintf(output_file_, " </testcase>\n"); | 112 fprintf(output_file_, " </testcase>\n"); |
83 fflush(output_file_); | 113 fflush(output_file_); |
84 } | 114 } |
85 | 115 |
86 void XmlUnitTestResultPrinter::OnTestCaseEnd( | 116 void XmlUnitTestResultPrinter::OnTestCaseEnd( |
87 const testing::TestCase& test_case) { | 117 const testing::TestCase& test_case) { |
88 fprintf(output_file_, " </testsuite>\n"); | 118 fprintf(output_file_, " </testsuite>\n"); |
89 fflush(output_file_); | 119 fflush(output_file_); |
90 } | 120 } |
91 | 121 |
(...skipping 22 matching lines...) Expand all Loading... |
114 fprintf(output_file_, | 144 fprintf(output_file_, |
115 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" | 145 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" |
116 " <summary>%s</summary>\n" | 146 " <summary>%s</summary>\n" |
117 " <message>%s</message>\n" | 147 " <message>%s</message>\n" |
118 " </x-test-result-part>\n", | 148 " </x-test-result-part>\n", |
119 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); | 149 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); |
120 fflush(output_file_); | 150 fflush(output_file_); |
121 } | 151 } |
122 | 152 |
123 } // namespace base | 153 } // namespace base |
OLD | NEW |