mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 21:52:53 +02:00
test: Unroll && conditions in macros
Using `&&` in `BOOST_CHECK` is problematic as failures will not indicate which condition failed. By unrolling these checks, the user knows exactly which expression is the failing case. As an example, here is a line that would be particularly hard to debug if it failed: ``` src/test/net_tests.cpp BOOST_CHECK((*ret)[1] && (*ret)[1]->m_type == "headers" && std::ranges::equal((*ret)[1]->m_recv, MakeByteSpan(msg_data_2))); ``` If any one of these conditions fail, the whole expression fails, with no values printed or indication as to which condition failed. This is also required when using test macros that support value decomposition, which requires `&&` and `||` are `delete`. Examples include `BOOST_TEST`, doctest, Catch2, etc. ref: https://catch2-temp.readthedocs.io/en/latest/assertions.html#other-limitations ref: https://fekir.info/post/decomposing-an-expression/
This commit is contained in:
@@ -295,7 +295,8 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
|
||||
BOOST_REQUIRE(nStartTime < nTimeout);
|
||||
BOOST_REQUIRE(nStartTime >= 0);
|
||||
BOOST_REQUIRE(nTimeout <= std::numeric_limits<uint32_t>::max() || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT);
|
||||
BOOST_REQUIRE(0 <= bit && bit < 32);
|
||||
BOOST_REQUIRE(0 <= bit);
|
||||
BOOST_REQUIRE(bit < 32);
|
||||
// Make sure that no deployment tries to set an invalid bit.
|
||||
BOOST_REQUIRE(((1 << bit) & VERSIONBITS_TOP_MASK) == 0);
|
||||
BOOST_REQUIRE(min_activation_height >= 0);
|
||||
@@ -459,7 +460,8 @@ BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
|
||||
const uint32_t dep_mask{uint32_t{1} << dep_info.bit};
|
||||
BOOST_CHECK(!(chain_all_vbits & dep_mask));
|
||||
chain_all_vbits |= dep_mask;
|
||||
BOOST_CHECK(0 <= dep_info.bit && dep_info.bit < VERSIONBITS_MAX_NUM_BITS);
|
||||
BOOST_CHECK(0 <= dep_info.bit);
|
||||
BOOST_CHECK(dep_info.bit < VERSIONBITS_MAX_NUM_BITS);
|
||||
if (chain_type != ChainType::REGTEST) {
|
||||
if (dep == Consensus::DEPLOYMENT_TESTDUMMY) {
|
||||
BOOST_CHECK_EQUAL(dep_info.nStartTime, Consensus::BIP9Deployment::NEVER_ACTIVE);
|
||||
|
||||
Reference in New Issue
Block a user