OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/test/test_launcher/test_runner.h" | 5 #include "chrome/test/test_launcher/test_runner.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Note: as currently XML is the only supported format by gtest, we don't | 33 // Note: as currently XML is the only supported format by gtest, we don't |
34 // check output format (e.g. "xml:" prefix) here and output an XML file | 34 // check output format (e.g. "xml:" prefix) here and output an XML file |
35 // unconditionally. | 35 // unconditionally. |
36 // Note: we don't output per-test-case or total summary info like | 36 // Note: we don't output per-test-case or total summary info like |
37 // total failed_test_count, disabled_test_count, elapsed_time and so on. | 37 // total failed_test_count, disabled_test_count, elapsed_time and so on. |
38 // Only each test (testcase element in the XML) will have the correct | 38 // Only each test (testcase element in the XML) will have the correct |
39 // failed/disabled/elapsed_time information. Each test won't include | 39 // failed/disabled/elapsed_time information. Each test won't include |
40 // detailed failure messages either. | 40 // detailed failure messages either. |
41 class ResultsPrinter { | 41 class ResultsPrinter { |
42 public: | 42 public: |
43 ResultsPrinter(const CommandLine& command_line); | 43 explicit ResultsPrinter(const CommandLine& command_line); |
44 ~ResultsPrinter(); | 44 ~ResultsPrinter(); |
45 void OnTestCaseStart(const char* name, int test_count) const; | 45 void OnTestCaseStart(const char* name, int test_count) const; |
46 void OnTestCaseEnd() const; | 46 void OnTestCaseEnd() const; |
47 void OnTestEnd(const char* name, const char* case_name, bool run, | 47 void OnTestEnd(const char* name, const char* case_name, bool run, |
48 bool failure, double elapsed_time) const; | 48 bool failure, double elapsed_time) const; |
49 private: | 49 private: |
50 FILE* out_; | 50 FILE* out_; |
51 }; | 51 }; |
52 | 52 |
53 ResultsPrinter::ResultsPrinter(const CommandLine& command_line) : out_(NULL) { | 53 ResultsPrinter::ResultsPrinter(const CommandLine& command_line) : out_(NULL) { |
(...skipping 10 matching lines...) Expand all Loading... |
64 // Note: This does NOT check that a directory (or file) actually exists | 64 // Note: This does NOT check that a directory (or file) actually exists |
65 // (the behavior is same as what gtest does). | 65 // (the behavior is same as what gtest does). |
66 if (file_util::EndsWithSeparator(path)) { | 66 if (file_util::EndsWithSeparator(path)) { |
67 FilePath executable = command_line.GetProgram().BaseName(); | 67 FilePath executable = command_line.GetProgram().BaseName(); |
68 path = path.Append(executable.ReplaceExtension( | 68 path = path.Append(executable.ReplaceExtension( |
69 FilePath::StringType(FILE_PATH_LITERAL("xml")))); | 69 FilePath::StringType(FILE_PATH_LITERAL("xml")))); |
70 } | 70 } |
71 } | 71 } |
72 if (path.value().empty()) | 72 if (path.value().empty()) |
73 path = FilePath(kDefaultOutputFile); | 73 path = FilePath(kDefaultOutputFile); |
| 74 FilePath dir_name = path.DirName(); |
| 75 if (!file_util::DirectoryExists(dir_name)) { |
| 76 LOG(WARNING) << "The output directory does not exist. " |
| 77 << "Creating the directory: " << dir_name.value() << std::endl; |
| 78 // Create the directory if necessary (because the gtest does the same). |
| 79 file_util::CreateDirectory(dir_name); |
| 80 } |
74 out_ = file_util::OpenFile(path, "w"); | 81 out_ = file_util::OpenFile(path, "w"); |
75 if (!out_) { | 82 if (!out_) { |
76 LOG(ERROR) << "Cannot open output file: " | 83 LOG(ERROR) << "Cannot open output file: " |
77 << path.value() << "." << std::endl; | 84 << path.value() << "." << std::endl; |
78 return; | 85 return; |
79 } | 86 } |
80 fprintf(out_, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | 87 fprintf(out_, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
81 fprintf(out_, "<testsuites name=\"AllTests\" tests=\"\" failures=\"\"" | 88 fprintf(out_, "<testsuites name=\"AllTests\" tests=\"\" failures=\"\"" |
82 " disabled=\"\" errors=\"\" time=\"\">\n"); | 89 " disabled=\"\" errors=\"\" time=\"\">\n"); |
83 } | 90 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 printf("Failing tests:\n"); | 253 printf("Failing tests:\n"); |
247 for (std::vector<std::string>::const_iterator iter = failed_tests.begin(); | 254 for (std::vector<std::string>::const_iterator iter = failed_tests.begin(); |
248 iter != failed_tests.end(); ++iter) { | 255 iter != failed_tests.end(); ++iter) { |
249 printf("%s\n", iter->c_str()); | 256 printf("%s\n", iter->c_str()); |
250 } | 257 } |
251 | 258 |
252 return false; | 259 return false; |
253 } | 260 } |
254 | 261 |
255 } // namespace | 262 } // namespace |
OLD | NEW |