rocksdb: print status error message when (ASSERT|EXPECT)_OK fails

Summary: Modified rocksdb status assertions ASSERT_OK and EXPECT_OK to print error message from Status::ToString() when failed.

Test Plan: Modify a test to fail status assertions ASSERT_OK and EXPECT_OK and notice an error message that came from Status::ToString()

Reviewers: meyering, sdong, yhchiang, igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D35469
This commit is contained in:
Igor Sugak 2015-03-19 17:32:43 -07:00
parent 9405b5ef8f
commit 28bc6de989
2 changed files with 15 additions and 4 deletions

View File

@ -13,6 +13,15 @@
namespace rocksdb {
namespace test {
::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) {
if (s.ok()) {
return ::testing::AssertionSuccess();
} else {
return ::testing::AssertionFailure() << s_expr << std::endl
<< s.ToString();
}
}
std::string TmpDir(Env* env) {
std::string dir;
Status s = env->GetTestDirectory(&dir);

View File

@ -25,10 +25,12 @@ std::string TmpDir(Env* env = Env::Default());
// runs may be able to vary the seed.
int RandomSeed();
#define ASSERT_OK(s) ASSERT_TRUE(((s).ok()))
#define ASSERT_NOK(s) ASSERT_FALSE(((s).ok()))
#define EXPECT_OK(s) EXPECT_TRUE(((s).ok()))
#define EXPECT_NOK(s) EXPECT_FALSE(((s).ok()))
::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s);
#define ASSERT_OK(s) ASSERT_PRED_FORMAT1(rocksdb::test::AssertStatus, s)
#define ASSERT_NOK(s) ASSERT_FALSE((s).ok())
#define EXPECT_OK(s) EXPECT_PRED_FORMAT1(rocksdb::test::AssertStatus, s)
#define EXPECT_NOK(s) EXPECT_FALSE((s).ok())
} // namespace test
} // namespace rocksdb