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