Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / base / test / launcher / unit_test_launcher_nacl_nonsfi.cc
blobb2cf14ac882d30cd9a2bb809f682aaa205149045
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
3 // found in the LICENSE file.
5 #include "base/test/launcher/unit_test_launcher.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/test/gtest_util.h"
10 #include "base/test/gtest_xml_unittest_result_printer.h"
11 #include "base/test/test_switches.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace base {
16 int LaunchUnitTests(int argc,
17 char** argv,
18 const RunTestSuiteCallback& run_test_suite) {
19 CHECK(CommandLine::InitializedForCurrentProcess() ||
20 CommandLine::Init(argc, argv));
21 const CommandLine* command_line = CommandLine::ForCurrentProcess();
22 if (command_line->HasSwitch(switches::kTestLauncherListTests)) {
23 // Dump all test list into a file.
24 FilePath list_path(
25 command_line->GetSwitchValuePath(switches::kTestLauncherListTests));
26 if (!WriteCompiledInTestsToFile(list_path)) {
27 LOG(ERROR) << "Failed to write list of tests.";
28 return 1;
31 // Successfully done.
32 return 0;
35 // Register XML output printer, if --test-launcher-output flag is set.
36 if (command_line->HasSwitch(switches::kTestLauncherOutput)) {
37 FilePath output_path = command_line->GetSwitchValuePath(
38 switches::kTestLauncherOutput);
39 if (PathExists(output_path)) {
40 LOG(WARNING) << "Test launcher output path exists. Do not override";
41 } else {
42 XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter;
43 CHECK(printer->Initialize(output_path));
44 testing::UnitTest::GetInstance()->listeners().Append(printer);
48 return run_test_suite.Run();
51 } // namespace base