| 34 | }; |
| 35 | |
| 36 | TEST(PopenTest, posix_popen) { |
| 37 | std::ostringstream oss; |
| 38 | int rc = butil::read_command_output_through_popen(oss, "echo \"Hello World\""); |
| 39 | ASSERT_EQ(0, rc) << berror(errno); |
| 40 | ASSERT_EQ("Hello World\n", oss.str()); |
| 41 | |
| 42 | oss.str(""); |
| 43 | rc = butil::read_command_output_through_popen(oss, "exit 1"); |
| 44 | EXPECT_EQ(1, rc) << berror(errno); |
| 45 | ASSERT_TRUE(oss.str().empty()) << oss.str(); |
| 46 | oss.str(""); |
| 47 | rc = butil::read_command_output_through_popen(oss, "kill -9 $$"); |
| 48 | ASSERT_EQ(-1, rc); |
| 49 | ASSERT_EQ(errno, ECHILD); |
| 50 | ASSERT_TRUE(butil::StringPiece(oss.str()).ends_with("was killed by signal 9")); |
| 51 | oss.str(""); |
| 52 | rc = butil::read_command_output_through_popen(oss, "kill -15 $$"); |
| 53 | ASSERT_EQ(-1, rc); |
| 54 | ASSERT_EQ(errno, ECHILD); |
| 55 | ASSERT_TRUE(butil::StringPiece(oss.str()).ends_with("was killed by signal 15")); |
| 56 | |
| 57 | // TODO(zhujiashun): Fix this in macos |
| 58 | /* |
| 59 | oss.str(""); |
| 60 | ASSERT_EQ(0, butil::read_command_output_through_popen(oss, "for i in `seq 1 100000`; do echo -n '=' ; done")); |
| 61 | ASSERT_EQ(100000u, oss.str().length()); |
| 62 | std::string expected; |
| 63 | expected.resize(100000, '='); |
| 64 | ASSERT_EQ(expected, oss.str()); |
| 65 | */ |
| 66 | } |
| 67 | |
| 68 | #if defined(OS_LINUX) |
| 69 |
nothing calls this directly
no test coverage detected