| S. Ganesh | 154e229 | 2024-08-09 23:43:29 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/process/launch.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include "base/command_line.h" |
| 10 | #include "base/files/file_path.h" |
| 11 | #include "build/build_config.h" |
| 12 | #include "testing/gtest/include/gtest/gtest.h" |
| 13 | |
| 14 | namespace base { |
| 15 | |
| 16 | TEST(LaunchTest, GetAppOutputWithInvalidExecutableShouldFail) { |
| 17 | CommandLine cl(FilePath(FILE_PATH_LITERAL("executable_does_not_exist"))); |
| 18 | std::string output; |
| 19 | ASSERT_FALSE(GetAppOutput(cl, &output)); |
| 20 | |
| 21 | #if !BUILDFLAG(IS_IOS) |
| 22 | // iOS does not support `GetAppOutputWithExitCode`. |
| 23 | int exit_code = {}; |
| 24 | const bool succeeded = GetAppOutputWithExitCode(cl, &output, &exit_code); |
| 25 | |
| 26 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_FUCHSIA) |
| 27 | ASSERT_FALSE(succeeded); |
| 28 | #else |
| 29 | // Other platforms return code `127` for an executable that does not exist. |
| 30 | ASSERT_TRUE(succeeded); |
| 31 | ASSERT_EQ(exit_code, 127); |
| 32 | #endif // #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_FUCHSIA) |
| 33 | #endif // #if !BUILDFLAG(IS_IOS) |
| 34 | } |
| 35 | |
| 36 | } // namespace base |