From 47fe551e52d8b3f607d55ad20073c0436590e081 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 14 Jun 2023 15:07:36 +0100 Subject: [PATCH 1/2] test: Kill `BOOST_ASSERT` --- src/wallet/test/db_tests.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp index 4cda35ed8d0..e0b4a1e74c3 100644 --- a/src/wallet/test/db_tests.cpp +++ b/src/wallet/test/db_tests.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #ifdef USE_BDB @@ -141,12 +142,10 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test) { // Test each supported db for (const auto& database : TestDatabases(m_path_root)) { - BOOST_ASSERT(database); - std::vector prefixes = {"", "FIRST", "SECOND", "P\xfe\xff", "P\xff\x01", "\xff\xff"}; // Write elements to it - std::unique_ptr handler = database->MakeBatch(); + std::unique_ptr handler = Assert(database)->MakeBatch(); for (unsigned int i = 0; i < 10; i++) { for (const auto& prefix : prefixes) { BOOST_CHECK(handler->Write(std::make_pair(prefix, i), i)); @@ -162,7 +161,7 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test) DataStream value; for (int i = 0; i < 10; i++) { DatabaseCursor::Status status = cursor->Next(key, value); - BOOST_ASSERT(status == DatabaseCursor::Status::MORE); + BOOST_CHECK_EQUAL(status, DatabaseCursor::Status::MORE); std::string key_back; unsigned int i_back; From 28fff06afe98177c14a932abf95b380bb51c6653 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 14 Jun 2023 16:26:11 +0100 Subject: [PATCH 2/2] test: Make linter to look for `BOOST_ASSERT` macros The `BOOST_ASSERT` macro requires to `#include boost/assert.hpp`. --- test/lint/lint-assertions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/lint/lint-assertions.py b/test/lint/lint-assertions.py index e7eecebce59..6da59b0d48d 100755 --- a/test/lint/lint-assertions.py +++ b/test/lint/lint-assertions.py @@ -45,6 +45,16 @@ def main(): ":(exclude)src/rpc/server.cpp", ], "CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.") + # The `BOOST_ASSERT` macro requires to `#include boost/assert.hpp`, + # which is an unnecessary Boost dependency. + exit_code |= git_grep([ + "-E", + r"BOOST_ASSERT *\(.*\);", + "--", + "*.cpp", + "*.h", + ], "BOOST_ASSERT must be replaced with Assert, BOOST_REQUIRE, or BOOST_CHECK.") + sys.exit(exit_code)