summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yifan Hong <elsk@google.com> 2018-06-27 16:48:34 -0700
committer Yifan Hong <elsk@google.com> 2018-06-28 13:23:15 -0700
commitc443091cbc9d4ce9f16bc85222eda932adbd2b65 (patch)
treead877fd1c48c294814aa39c7d75f9668235bbc67
parentaa864577ff84d250ca854d87bc95b54472b843e1 (diff)
lshal: test: make mocks more robust
Setup error stream for all tests in ListParseArgsTest. Otherwise, if lshal writes to error stream, the test immediately aborts. Test: lshal_test Change-Id: I085e764528534e9d2df8e0ccf3181366d20247bc
-rw-r--r--cmds/lshal/test.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp
index 501c04de84..096b67d24e 100644
--- a/cmds/lshal/test.cpp
+++ b/cmds/lshal/test.cpp
@@ -226,12 +226,13 @@ public:
void SetUp() override {
mockLshal = std::make_unique<NiceMock<MockLshal>>();
mockList = std::make_unique<MockListCommand>(mockLshal.get());
+ ON_CALL(*mockLshal, err()).WillByDefault(Return(NullableOStream<std::ostream>(err)));
// ListCommand::parseArgs should parse arguments from the second element
optind = 1;
}
std::unique_ptr<MockLshal> mockLshal;
std::unique_ptr<MockListCommand> mockList;
- std::stringstream output;
+ std::stringstream err;
};
TEST_F(ListParseArgsTest, Args) {
@@ -241,6 +242,7 @@ TEST_F(ListParseArgsTest, Args) {
TableColumnType::SERVER_ADDR, TableColumnType::CLIENT_PIDS}),
table.getSelectedColumns());
});
+ EXPECT_EQ("", err.str());
}
TEST_F(ListParseArgsTest, Cmds) {
@@ -255,12 +257,12 @@ TEST_F(ListParseArgsTest, Cmds) {
EXPECT_THAT(table.getSelectedColumns(), Contains(TableColumnType::CLIENT_CMDS))
<< "should print client cmds with -m";
});
+ EXPECT_EQ("", err.str());
}
TEST_F(ListParseArgsTest, DebugAndNeat) {
- ON_CALL(*mockLshal, err()).WillByDefault(Return(NullableOStream<std::ostream>(output)));
EXPECT_NE(0u, mockList->parseArgs(createArg({"lshal", "--neat", "-d"})));
- EXPECT_THAT(output.str(), StrNe(""));
+ EXPECT_THAT(err.str(), HasSubstr("--neat should not be used with --debug."));
}
/// Fetch Test