CodeMod: Prefer ADD_FAILURE() over EXPECT_TRUE(false), et cetera

Summary:
CodeMod: Prefer `ADD_FAILURE()` over `EXPECT_TRUE(false)`, et cetera.

The tautologically-conditioned and tautologically-contradicted boolean expectations/assertions have better alternatives: unconditional passes and failures.

Reviewed By: Orvid

Differential Revision:
D5432398

Tags: codemod, codemod-opensource

fbshipit-source-id: d16b447e8696a6feaa94b41199f5052226ef6914
main
Yedidya Feldblum 8 years ago committed by Facebook Github Bot
parent 4a2e4891fe
commit f1a056e005
  1. 4
      db/corruption_test.cc
  2. 4
      db/db_block_cache_test.cc
  3. 16
      db/write_batch_test.cc
  4. 2
      table/mock_table.cc
  5. 2
      util/thread_local_test.cc
  6. 2
      utilities/backupable/backupable_db_test.cc
  7. 2
      utilities/checkpoint/checkpoint_test.cc
  8. 2
      utilities/lua/rocks_lua_test.cc
  9. 4
      utilities/persistent_cache/persistent_cache_test.cc
  10. 6
      utilities/transactions/transaction_test.cc
  11. 12
      utilities/ttl/ttl_test.cc

@ -152,7 +152,7 @@ class CorruptionTest : public testing::Test {
struct stat sbuf; struct stat sbuf;
if (stat(fname.c_str(), &sbuf) != 0) { if (stat(fname.c_str(), &sbuf) != 0) {
const char* msg = strerror(errno); const char* msg = strerror(errno);
ASSERT_TRUE(false) << fname << ": " << msg; FAIL() << fname << ": " << msg;
} }
if (offset < 0) { if (offset < 0) {
@ -213,7 +213,7 @@ class CorruptionTest : public testing::Test {
return; return;
} }
} }
ASSERT_TRUE(false) << "no file found at level"; FAIL() << "no file found at level";
} }

@ -497,7 +497,7 @@ TEST_F(DBBlockCacheTest, CompressedCache) {
options.compression = kNoCompression; options.compression = kNoCompression;
break; break;
default: default:
ASSERT_TRUE(false); FAIL();
} }
CreateAndReopenWithCF({"pikachu"}, options); CreateAndReopenWithCF({"pikachu"}, options);
// default column family doesn't have block cache // default column family doesn't have block cache
@ -560,7 +560,7 @@ TEST_F(DBBlockCacheTest, CompressedCache) {
ASSERT_EQ(TestGetTickerCount(options, BLOCK_CACHE_COMPRESSED_HIT), 0); ASSERT_EQ(TestGetTickerCount(options, BLOCK_CACHE_COMPRESSED_HIT), 0);
break; break;
default: default:
ASSERT_TRUE(false); FAIL();
} }
options.create_if_missing = true; options.create_if_missing = true;

@ -451,20 +451,20 @@ TEST_F(WriteBatchTest, DISABLED_ManyUpdates) {
} }
virtual Status DeleteCF(uint32_t column_family_id, virtual Status DeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status SingleDeleteCF(uint32_t column_family_id, virtual Status SingleDeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status MergeCF(uint32_t column_family_id, const Slice& key, virtual Status MergeCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual void LogData(const Slice& blob) override { EXPECT_TRUE(false); } virtual void LogData(const Slice& blob) override { ADD_FAILURE(); }
virtual bool Continue() override { return num_seen < kNumUpdates; } virtual bool Continue() override { return num_seen < kNumUpdates; }
} handler; } handler;
@ -502,20 +502,20 @@ TEST_F(WriteBatchTest, DISABLED_LargeKeyValue) {
} }
virtual Status DeleteCF(uint32_t column_family_id, virtual Status DeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status SingleDeleteCF(uint32_t column_family_id, virtual Status SingleDeleteCF(uint32_t column_family_id,
const Slice& key) override { const Slice& key) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual Status MergeCF(uint32_t column_family_id, const Slice& key, virtual Status MergeCF(uint32_t column_family_id, const Slice& key,
const Slice& value) override { const Slice& value) override {
EXPECT_TRUE(false); ADD_FAILURE();
return Status::OK(); return Status::OK();
} }
virtual void LogData(const Slice& blob) override { EXPECT_TRUE(false); } virtual void LogData(const Slice& blob) override { ADD_FAILURE(); }
virtual bool Continue() override { return num_seen < 2; } virtual bool Continue() override { return num_seen < 2; }
} handler; } handler;

@ -137,7 +137,7 @@ void MockTableFactory::AssertLatestFile(
ParseInternalKey(Slice(key), &ikey); ParseInternalKey(Slice(key), &ikey);
std::cout << ikey.DebugString(false) << " -> " << value << std::endl; std::cout << ikey.DebugString(false) << " -> " << value << std::endl;
} }
ASSERT_TRUE(false); FAIL();
} }
} }

@ -569,7 +569,7 @@ TEST_F(ThreadLocalTest, DISABLED_MainThreadDiesFirst) {
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
} catch (const std::system_error& ex) { } catch (const std::system_error& ex) {
std::cerr << "Start thread: " << ex.code() << std::endl; std::cerr << "Start thread: " << ex.code() << std::endl;
ASSERT_TRUE(false); FAIL();
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
} }

@ -101,7 +101,7 @@ class DummyDB : public StackableDB {
virtual uint64_t LogNumber() const override { virtual uint64_t LogNumber() const override {
// what business do you have calling this method? // what business do you have calling this method?
EXPECT_TRUE(false); ADD_FAILURE();
return 0; return 0;
} }

@ -372,7 +372,7 @@ TEST_F(CheckpointTest, CheckpointCFNoFlush) {
rocksdb::SyncPoint::GetInstance()->SetCallBack( rocksdb::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCallFlush:start", [&](void* arg) { "DBImpl::BackgroundCallFlush:start", [&](void* arg) {
// Flush should never trigger. // Flush should never trigger.
ASSERT_TRUE(false); FAIL();
}); });
rocksdb::SyncPoint::GetInstance()->EnableProcessing(); rocksdb::SyncPoint::GetInstance()->EnableProcessing();
Checkpoint* checkpoint; Checkpoint* checkpoint;

@ -26,7 +26,7 @@ class StopOnErrorLogger : public Logger {
virtual void Logv(const char* format, va_list ap) override { virtual void Logv(const char* format, va_list ap) override {
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
ASSERT_TRUE(false); FAIL();
} }
}; };

@ -372,7 +372,7 @@ void PersistentCacheDBTest::RunTest(
options.table_factory.reset(NewBlockBasedTableFactory(table_options)); options.table_factory.reset(NewBlockBasedTableFactory(table_options));
break; break;
default: default:
ASSERT_TRUE(false); FAIL();
} }
std::vector<std::string> values; std::vector<std::string> values;
@ -425,7 +425,7 @@ void PersistentCacheDBTest::RunTest(
ASSERT_EQ(compressed_block_miss, 0); ASSERT_EQ(compressed_block_miss, 0);
break; break;
default: default:
ASSERT_TRUE(false); FAIL();
} }
options.create_if_missing = true; options.create_if_missing = true;

@ -242,7 +242,7 @@ TEST_P(TransactionTest, WaitingTxn) {
// Column family is 1 or 0 (cfa). // Column family is 1 or 0 (cfa).
if (cf_iterator->first != 1 && cf_iterator->first != 0) { if (cf_iterator->first != 1 && cf_iterator->first != 0) {
ASSERT_FALSE(true); FAIL();
} }
// The locked key is "foo" and is locked by txn1 // The locked key is "foo" and is locked by txn1
ASSERT_EQ(cf_iterator->second.key, "foo"); ASSERT_EQ(cf_iterator->second.key, "foo");
@ -253,7 +253,7 @@ TEST_P(TransactionTest, WaitingTxn) {
// Column family is 0 (default) or 1. // Column family is 0 (default) or 1.
if (cf_iterator->first != 1 && cf_iterator->first != 0) { if (cf_iterator->first != 1 && cf_iterator->first != 0) {
ASSERT_FALSE(true); FAIL();
} }
// The locked key is "foo" and is locked by txn1 // The locked key is "foo" and is locked by txn1
ASSERT_EQ(cf_iterator->second.key, "foo"); ASSERT_EQ(cf_iterator->second.key, "foo");
@ -1080,7 +1080,7 @@ TEST_P(TransactionTest, DISABLED_TwoPhaseMultiThreadTest) {
env->SleepForMicroseconds(10); env->SleepForMicroseconds(10);
} }
} else { } else {
ASSERT_TRUE(false); FAIL();
} }
}); });

@ -131,7 +131,7 @@ class TtlTest : public testing::Test {
batch.Delete(kv_it_->first); batch.Delete(kv_it_->first);
break; break;
default: default:
ASSERT_TRUE(false); FAIL();
} }
} }
db_ttl_->Write(wopts, &batch); db_ttl_->Write(wopts, &batch);
@ -184,12 +184,12 @@ class TtlTest : public testing::Test {
if (ret == false || value_found == false) { if (ret == false || value_found == false) {
fprintf(stderr, "KeyMayExist could not find key=%s in the database but" fprintf(stderr, "KeyMayExist could not find key=%s in the database but"
" should have\n", kv.first.c_str()); " should have\n", kv.first.c_str());
ASSERT_TRUE(false); FAIL();
} else if (val.compare(kv.second) != 0) { } else if (val.compare(kv.second) != 0) {
fprintf(stderr, " value for key=%s present in database is %s but" fprintf(stderr, " value for key=%s present in database is %s but"
" should be %s\n", kv.first.c_str(), val.c_str(), " should be %s\n", kv.first.c_str(), val.c_str(),
kv.second.c_str()); kv.second.c_str());
ASSERT_TRUE(false); FAIL();
} }
} }
} }
@ -239,18 +239,18 @@ class TtlTest : public testing::Test {
} else { } else {
fprintf(stderr, "is present in db but was expected to be absent\n"); fprintf(stderr, "is present in db but was expected to be absent\n");
} }
ASSERT_TRUE(false); FAIL();
} else if (s.ok()) { } else if (s.ok()) {
if (test_compaction_change && v.compare(kNewValue_) != 0) { if (test_compaction_change && v.compare(kNewValue_) != 0) {
fprintf(stderr, " value for key=%s present in database is %s but " fprintf(stderr, " value for key=%s present in database is %s but "
" should be %s\n", kv_it_->first.c_str(), v.c_str(), " should be %s\n", kv_it_->first.c_str(), v.c_str(),
kNewValue_.c_str()); kNewValue_.c_str());
ASSERT_TRUE(false); FAIL();
} else if (!test_compaction_change && v.compare(kv_it_->second) !=0) { } else if (!test_compaction_change && v.compare(kv_it_->second) !=0) {
fprintf(stderr, " value for key=%s present in database is %s but " fprintf(stderr, " value for key=%s present in database is %s but "
" should be %s\n", kv_it_->first.c_str(), v.c_str(), " should be %s\n", kv_it_->first.c_str(), v.c_str(),
kv_it_->second.c_str()); kv_it_->second.c_str());
ASSERT_TRUE(false); FAIL();
} }
} }
} }

Loading…
Cancel
Save