MCPcopy Create free account
hub / github.com/apache/brpc / TEST

Function TEST

test/popen_unittest.cpp:36–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34};
35
36TEST(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

Callers

nothing calls this directly

Calls 7

berrorFunction · 0.85
ends_withMethod · 0.80
emptyMethod · 0.45
lengthMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected