Commit b15db0d8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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
parent eb0730c9
......@@ -22,5 +22,5 @@
#include <folly/portability/GTest.h>
TEST(Basic, compiles) {
EXPECT_TRUE(true);
SUCCEED();
}
......@@ -296,7 +296,7 @@ TEST_F(HHWheelTimerTest, Stress) {
timeout - 256);
timeouts[i].fn = [&, i, timeout]() {
LOG(INFO) << "FAIL:timer " << i << " still fired in " << timeout;
EXPECT_FALSE(true);
ADD_FAILURE();
};
} else {
t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(timeout));
......
......@@ -142,7 +142,7 @@ TEST(IOBuf, Cursor) {
c.write((uint8_t)40); // OK
try {
c.write((uint8_t)10); // Bad write, checked should except.
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (...) {
}
}
......
......@@ -147,7 +147,7 @@ TEST(Conv, Floating2Floating) {
EXPECT_TRUE(shouldWork == std::numeric_limits<float>::min() ||
shouldWork == 0.f);
} catch (...) {
EXPECT_TRUE(false);
ADD_FAILURE();
}
}
......@@ -601,7 +601,7 @@ TEST(Conv, StringPieceToDouble) {
// Test NaN conversion
try {
to<double>("not a number");
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (const std::range_error &) {
}
......@@ -638,7 +638,7 @@ TEST(Conv, EmptyStringToInt) {
try {
to<int>(pc);
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (const std::range_error &) {
}
}
......@@ -649,7 +649,7 @@ TEST(Conv, CorruptedStringToInt) {
try {
to<int64_t>(&pc);
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (const std::range_error &) {
}
}
......@@ -660,7 +660,7 @@ TEST(Conv, EmptyStringToDouble) {
try {
to<double>(pc);
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (const std::range_error &) {
}
}
......@@ -671,7 +671,7 @@ TEST(Conv, IntToDouble) {
/* This seems not work in ubuntu11.10, gcc 4.6.1
try {
auto f = to<float>(957837589847);
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (std::range_error& e) {
//LOG(INFO) << e.what();
}
......@@ -684,7 +684,7 @@ TEST(Conv, DoubleToInt) {
try {
auto i2 = to<int>(42.1);
LOG(ERROR) << "to<int> returned " << i2 << " instead of throwing";
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (std::range_error&) {
//LOG(INFO) << e.what();
}
......@@ -701,7 +701,7 @@ TEST(Conv, EnumToInt) {
LOG(ERROR) << "to<char> returned "
<< static_cast<unsigned int>(i2)
<< " instead of throwing";
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (std::range_error&) {
//LOG(INFO) << e.what();
}
......@@ -726,7 +726,7 @@ TEST(Conv, IntToEnum) {
LOG(ERROR) << "to<A> returned "
<< static_cast<unsigned int>(i2)
<< " instead of throwing";
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (std::range_error&) {
//LOG(INFO) << e.what();
}
......@@ -743,7 +743,7 @@ TEST(Conv, UnsignedEnum) {
try {
auto i = to<int32_t>(x);
LOG(ERROR) << "to<int32_t> returned " << i << " instead of throwing";
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (std::range_error&) {
}
}
......@@ -915,7 +915,7 @@ void testConvError(
std::string where = to<std::string>(__FILE__, "(", line, "): ");
try {
auto res = expr();
EXPECT_TRUE(false) << where << exprStr << " -> " << res;
ADD_FAILURE() << where << exprStr << " -> " << res;
} catch (const ConversionError& e) {
EXPECT_EQ(code, e.errorCode()) << where << exprStr;
std::string str(e.what());
......
......@@ -127,7 +127,7 @@ TEST(Enumerate, EmptyRange) {
std::vector<std::string> v;
for (auto it : folly::enumerate(v)) {
(void)it; // Silence warnings.
EXPECT_TRUE(false);
ADD_FAILURE();
}
}
......
......@@ -508,10 +508,10 @@ TEST(ExceptionWrapper, handle_std_exception) {
bool handled = false;
auto expect_runtime_error_yes_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::logic_error&) { EXPECT_TRUE(false); },
[](const std::logic_error&) { ADD_FAILURE(); },
[&](const std::runtime_error&) { handled = true; },
[](const std::exception&) { EXPECT_TRUE(false); },
[](...) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); },
[](...) { ADD_FAILURE(); });
};
expect_runtime_error_yes_catch_all(ew_eptr);
......@@ -526,9 +526,9 @@ TEST(ExceptionWrapper, handle_std_exception) {
auto expect_runtime_error_no_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::logic_error&) { EXPECT_TRUE(false); },
[](const std::logic_error&) { ADD_FAILURE(); },
[&](const std::runtime_error&) { handled = true; },
[](const std::exception&) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); });
};
expect_runtime_error_no_catch_all(ew_eptr);
......@@ -543,10 +543,10 @@ TEST(ExceptionWrapper, handle_std_exception) {
auto expect_runtime_error_catch_non_std = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::logic_error&) { EXPECT_TRUE(false); },
[](const std::logic_error&) { ADD_FAILURE(); },
[&](const std::runtime_error&) { handled = true; },
[](const std::exception&) { EXPECT_TRUE(false); },
[](const int&) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); },
[](const int&) { ADD_FAILURE(); });
};
expect_runtime_error_catch_non_std(ew_eptr);
......@@ -563,12 +563,12 @@ TEST(ExceptionWrapper, handle_std_exception) {
// outer handler:
auto expect_runtime_error_rethrow = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::logic_error&) { EXPECT_TRUE(false); },
[](const std::logic_error&) { ADD_FAILURE(); },
[&](const std::runtime_error& e) {
handled = true;
throw e;
},
[](const std::exception&) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); });
};
EXPECT_THROW(expect_runtime_error_rethrow(ew_eptr), std::runtime_error);
......@@ -589,8 +589,8 @@ TEST(ExceptionWrapper, handle_std_exception_unhandled) {
bool handled = false;
auto expect_runtime_error_yes_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::logic_error&) { EXPECT_TRUE(false); },
[](const std::runtime_error&) { EXPECT_TRUE(false); },
[](const std::logic_error&) { ADD_FAILURE(); },
[](const std::runtime_error&) { ADD_FAILURE(); },
[&](...) { handled = true; });
};
......@@ -610,7 +610,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_small) {
auto expect_int_yes_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::exception&) { EXPECT_TRUE(false); },
[](const std::exception&) { ADD_FAILURE(); },
[&](...) { handled = true; });
};
......@@ -626,7 +626,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_small) {
auto expect_int_no_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::exception&) { EXPECT_TRUE(false); },
[](const std::exception&) { ADD_FAILURE(); },
[&](const int&) { handled = true; });
};
......@@ -643,7 +643,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_small) {
auto expect_int_no_catch_all_2 = [&](const exception_wrapper& ew) {
ew.handle(
[&](const int&) { handled = true; },
[](const std::exception&) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); });
};
expect_int_no_catch_all_2(ew_eptr1);
......@@ -665,7 +665,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_big) {
auto expect_int_yes_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::exception&) { EXPECT_TRUE(false); },
[](const std::exception&) { ADD_FAILURE(); },
[&](...) { handled = true; });
};
......@@ -681,7 +681,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_big) {
auto expect_int_no_catch_all = [&](const exception_wrapper& ew) {
ew.handle(
[](const std::exception&) { EXPECT_TRUE(false); },
[](const std::exception&) { ADD_FAILURE(); },
[&](const BigNonStdError&) { handled = true; });
};
......@@ -698,7 +698,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_big) {
auto expect_int_no_catch_all_2 = [&](const exception_wrapper& ew) {
ew.handle(
[&](const BigNonStdError&) { handled = true; },
[](const std::exception&) { EXPECT_TRUE(false); });
[](const std::exception&) { ADD_FAILURE(); });
};
expect_int_no_catch_all_2(ew_eptr1);
......@@ -724,7 +724,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_rethrow_base_derived) {
handled = true;
throw e;
},
[](const BaseException&) { EXPECT_TRUE(false); }),
[](const BaseException&) { ADD_FAILURE(); }),
DerivedException);
EXPECT_TRUE(handled);
handled = false;
......@@ -734,7 +734,7 @@ TEST(ExceptionWrapper, handle_non_std_exception_rethrow_base_derived) {
handled = true;
throw e;
},
[](...) { EXPECT_TRUE(false); }),
[](...) { ADD_FAILURE(); }),
DerivedException);
EXPECT_TRUE(handled);
}
......
......@@ -676,7 +676,7 @@ TEST(Expected, Then) {
// Error case:
Expected<int, E> ex = Expected<std::unique_ptr<int>, E>{
unexpected, E::E1}.then([](std::unique_ptr<int> p) -> int {
EXPECT_TRUE(false);
ADD_FAILURE();
return *p;
});
EXPECT_FALSE(bool(ex));
......
......@@ -118,21 +118,21 @@ TEST(File, Truthy) {
if (temp) {
;
} else {
EXPECT_FALSE(true);
ADD_FAILURE();
}
if (File file = File::temporary()) {
;
} else {
EXPECT_FALSE(true);
ADD_FAILURE();
}
EXPECT_FALSE(bool(File()));
if (File()) {
EXPECT_TRUE(false);
ADD_FAILURE();
}
if (File notOpened = File()) {
EXPECT_TRUE(false);
ADD_FAILURE();
}
}
......
......@@ -227,7 +227,7 @@ TEST(LifoSem, shutdown_multi) {
threads.push_back(DSched::thread([&]{
try {
a.wait();
EXPECT_TRUE(false);
ADD_FAILURE();
} catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
......
......@@ -1009,7 +1009,7 @@ void createProtectedBuf(StringPiece& contents, char** buf) {
const size_t kSuccess = 0;
char* pageAlignedBuf = (char*)aligned_malloc(2 * kPageSize, kPageSize);
if (pageAlignedBuf == nullptr) {
ASSERT_FALSE(true);
FAIL();
}
// Protect the page after the first full page-aligned region of the
// malloc'ed buffer
......
......@@ -420,7 +420,7 @@ TEST(PrettyToDouble, Basic) {
try{
recoveredX = prettyToDouble(testString, formatType);
} catch (const std::range_error& ex) {
EXPECT_TRUE(false) << testCase.prettyString << " -> " << ex.what();
ADD_FAILURE() << testCase.prettyString << " -> " << ex.what();
}
double relativeError = fabs(x) < 1e-5 ? (x-recoveredX) :
(x - recoveredX) / x;
......@@ -438,7 +438,7 @@ TEST(PrettyToDouble, Basic) {
recoveredX = prettyToDouble(prettyPrint(x, formatType, addSpace),
formatType);
} catch (std::range_error&) {
EXPECT_TRUE(false);
ADD_FAILURE();
}
double relativeError = (x - recoveredX) / x;
EXPECT_NEAR(0, relativeError, 1e-3);
......
......@@ -530,7 +530,7 @@ TEST(ThreadLocal, Fork) {
EXPECT_TRUE(WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status));
} else {
EXPECT_TRUE(false) << "fork failed";
ADD_FAILURE() << "fork failed";
}
EXPECT_EQ(2, totalValue());
......@@ -573,7 +573,7 @@ TEST(ThreadLocal, Fork2) {
EXPECT_TRUE(WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status));
} else {
EXPECT_TRUE(false) << "fork failed";
ADD_FAILURE() << "fork failed";
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment