OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "tools/gn/exec_process.h" | 5 #include "tools/gn/exec_process.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #endif | 15 #endif |
16 | 16 |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 // TODO(cjhopman): Enable these tests when windows ExecProcess handles stderr. | 19 // TODO(cjhopman): Enable these tests when windows ExecProcess handles stderr. |
20 // 'python' is not runnable on Windows. Adding ["cmd", "/c"] fails because | 20 // 'python' is not runnable on Windows. Adding ["cmd", "/c"] fails because |
21 // CommandLine does unusual reordering of args. | 21 // CommandLine does unusual reordering of args. |
22 #if !defined(OS_WIN) | 22 #if !defined(OS_WIN) |
23 namespace { | 23 namespace { |
24 bool ExecPython(const std::string& command, | 24 bool ExecPython(const std::string& command, |
25 std::string* std_out, | 25 std::string* std_out, |
26 std::string* std_err, | 26 std::string* std_err, |
27 int* exit_code) { | 27 int* exit_code) { |
28 base::ScopedTempDir temp_dir; | 28 base::ScopedTempDir temp_dir; |
29 CHECK(temp_dir.CreateUniqueTempDir()); | |
vabr (Chromium)
2016/09/15 14:18:47
The directory needs to be created before getting i
| |
29 base::CommandLine::StringVector args; | 30 base::CommandLine::StringVector args; |
30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
31 args.push_back(L"python"); | 32 args.push_back(L"python"); |
32 args.push_back(L"-c"); | 33 args.push_back(L"-c"); |
33 args.push_back(base::UTF8ToUTF16(command)); | 34 args.push_back(base::UTF8ToUTF16(command)); |
34 #else | 35 #else |
35 args.push_back("python"); | 36 args.push_back("python"); |
36 args.push_back("-c"); | 37 args.push_back("-c"); |
37 args.push_back(command); | 38 args.push_back(command); |
38 #endif | 39 #endif |
39 return ExecProcess( | 40 return ExecProcess(base::CommandLine(args), temp_dir.GetPath(), std_out, |
40 base::CommandLine(args), temp_dir.path(), std_out, std_err, exit_code); | 41 std_err, exit_code); |
41 } | 42 } |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 TEST(ExecProcessTest, TestExitCode) { | 45 TEST(ExecProcessTest, TestExitCode) { |
45 std::string std_out, std_err; | 46 std::string std_out, std_err; |
46 int exit_code; | 47 int exit_code; |
47 | 48 |
48 ASSERT_TRUE( | 49 ASSERT_TRUE( |
49 ExecPython("import sys; sys.exit(0)", &std_out, &std_err, &exit_code)); | 50 ExecPython("import sys; sys.exit(0)", &std_out, &std_err, &exit_code)); |
50 EXPECT_EQ(0, exit_code); | 51 EXPECT_EQ(0, exit_code); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 "import sys; sys.stdout.close(); print >>sys.stderr, 'e' * 10000", | 122 "import sys; sys.stdout.close(); print >>sys.stderr, 'e' * 10000", |
122 &std_out, | 123 &std_out, |
123 &std_err, | 124 &std_err, |
124 &exit_code)); | 125 &exit_code)); |
125 EXPECT_EQ(0, exit_code); | 126 EXPECT_EQ(0, exit_code); |
126 EXPECT_EQ(0u, std_out.size()); | 127 EXPECT_EQ(0u, std_out.size()); |
127 EXPECT_EQ(10001u, std_err.size()); | 128 EXPECT_EQ(10001u, std_err.size()); |
128 } | 129 } |
129 #endif | 130 #endif |
130 } // namespace internal | 131 } // namespace internal |
OLD | NEW |