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."; |
| 22 } |
| 23 |
| 24 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() |
| 25 : output_file_(NULL), |
| 26 test_part_results_limit_(kDefaultTestPartResultsLimit) { |
| 27 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 switches::kTestLauncherTestPartResultsLimit)) { |
| 29 std::string limit_str = |
| 30 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 31 switches::kTestLauncherTestPartResultsLimit); |
| 32 long int limit = std::strtol(limit_str.c_str(), nullptr, 10); |
| 33 test_part_results_limit_ = limit; |
| 34 } |
15 } | 35 } |
16 | 36 |
17 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { | 37 XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { |
18 if (output_file_) { | 38 if (output_file_) { |
19 fprintf(output_file_, "</testsuites>\n"); | 39 fprintf(output_file_, "</testsuites>\n"); |
20 fflush(output_file_); | 40 fflush(output_file_); |
21 CloseFile(output_file_); | 41 CloseFile(output_file_); |
22 } | 42 } |
23 } | 43 } |
24 | 44 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\"" | 86 " <testcase name=\"%s\" status=\"run\" time=\"%.3f\"" |
67 " classname=\"%s\">\n", | 87 " classname=\"%s\">\n", |
68 test_info.name(), | 88 test_info.name(), |
69 static_cast<double>(test_info.result()->elapsed_time()) / | 89 static_cast<double>(test_info.result()->elapsed_time()) / |
70 Time::kMillisecondsPerSecond, | 90 Time::kMillisecondsPerSecond, |
71 test_info.test_case_name()); | 91 test_info.test_case_name()); |
72 if (test_info.result()->Failed()) { | 92 if (test_info.result()->Failed()) { |
73 fprintf(output_file_, | 93 fprintf(output_file_, |
74 " <failure message=\"\" type=\"\"></failure>\n"); | 94 " <failure message=\"\" type=\"\"></failure>\n"); |
75 } | 95 } |
76 for (int i = 0; i < test_info.result()->total_part_count(); ++i) { | 96 |
| 97 int limit = test_info.result()->total_part_count(); |
| 98 if (test_part_results_limit_ >= 0) |
| 99 limit = std::min(limit, test_part_results_limit_); |
| 100 |
| 101 for (int i = 0; i < limit; ++i) { |
77 const auto& test_part_result = test_info.result()->GetTestPartResult(i); | 102 const auto& test_part_result = test_info.result()->GetTestPartResult(i); |
78 WriteTestPartResult(test_part_result.file_name(), | 103 WriteTestPartResult(test_part_result.file_name(), |
79 test_part_result.line_number(), test_part_result.type(), | 104 test_part_result.line_number(), test_part_result.type(), |
80 test_part_result.summary(), test_part_result.message()); | 105 test_part_result.summary(), test_part_result.message()); |
81 } | 106 } |
| 107 |
| 108 if (test_info.result()->total_part_count() > limit) { |
| 109 WriteTestPartResult( |
| 110 "<unknown>", 0, testing::TestPartResult::kNonFatalFailure, |
| 111 kTestPartLesultsLimitExceeded, kTestPartLesultsLimitExceeded); |
| 112 } |
| 113 |
82 fprintf(output_file_, " </testcase>\n"); | 114 fprintf(output_file_, " </testcase>\n"); |
83 fflush(output_file_); | 115 fflush(output_file_); |
84 } | 116 } |
85 | 117 |
86 void XmlUnitTestResultPrinter::OnTestCaseEnd( | 118 void XmlUnitTestResultPrinter::OnTestCaseEnd( |
87 const testing::TestCase& test_case) { | 119 const testing::TestCase& test_case) { |
88 fprintf(output_file_, " </testsuite>\n"); | 120 fprintf(output_file_, " </testsuite>\n"); |
89 fflush(output_file_); | 121 fflush(output_file_); |
90 } | 122 } |
91 | 123 |
(...skipping 22 matching lines...) Expand all Loading... |
114 fprintf(output_file_, | 146 fprintf(output_file_, |
115 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" | 147 " <x-test-result-part type=\"%s\" file=\"%s\" line=\"%d\">\n" |
116 " <summary>%s</summary>\n" | 148 " <summary>%s</summary>\n" |
117 " <message>%s</message>\n" | 149 " <message>%s</message>\n" |
118 " </x-test-result-part>\n", | 150 " </x-test-result-part>\n", |
119 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); | 151 type, file, line, summary_encoded.c_str(), message_encoded.c_str()); |
120 fflush(output_file_); | 152 fflush(output_file_); |
121 } | 153 } |
122 | 154 |
123 } // namespace base | 155 } // namespace base |
OLD | NEW |