Skip to content

Commit 2880bb5

Browse files
committed
Merge bitcoin/bitcoin#27889: test: Kill BOOST_ASSERT and update the linter
28fff06 test: Make linter to look for `BOOST_ASSERT` macros (Hennadii Stepanov) 47fe551 test: Kill `BOOST_ASSERT` (Hennadii Stepanov) Pull request description: One of the goals of bitcoin/bitcoin#27783 was to get rid of the `BOOST_ASSERT` macros instead of including the `boost/assert.hpp` headers. See bitcoin/bitcoin#27783 (comment). It turns out that a couple of those macros sneaked into the codebase in bitcoin/bitcoin#27790. This PR makes the linter guard against new instances of the `BOOST_ASSERT` macros and replaces the current ones. ACKs for top commit: kevkevinpal: ACK [28fff06](bitcoin/bitcoin@28fff06) stickies-v: ACK 28fff06 TheCharlatan: ACK 28fff06 Tree-SHA512: 371f613592cf677afe0196d18c83943c6c8f1e998f57b4ff3ee58bfeff8636e4dac1357840d8611b4f7b197def94df10fe1a8ca3282b00b7b4eff4624552dda8
2 parents 0c84a0e + 28fff06 commit 2880bb5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/wallet/test/db_tests.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <boost/test/unit_test.hpp>
66

77
#include <test/util/setup_common.h>
8+
#include <util/check.h>
89
#include <util/fs.h>
910
#include <util/translation.h>
1011
#ifdef USE_BDB
@@ -141,12 +142,10 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
141142
{
142143
// Test each supported db
143144
for (const auto& database : TestDatabases(m_path_root)) {
144-
BOOST_ASSERT(database);
145-
146145
std::vector<std::string> prefixes = {"", "FIRST", "SECOND", "P\xfe\xff", "P\xff\x01", "\xff\xff"};
147146

148147
// Write elements to it
149-
std::unique_ptr<DatabaseBatch> handler = database->MakeBatch();
148+
std::unique_ptr<DatabaseBatch> handler = Assert(database)->MakeBatch();
150149
for (unsigned int i = 0; i < 10; i++) {
151150
for (const auto& prefix : prefixes) {
152151
BOOST_CHECK(handler->Write(std::make_pair(prefix, i), i));
@@ -162,7 +161,7 @@ BOOST_AUTO_TEST_CASE(db_cursor_prefix_range_test)
162161
DataStream value;
163162
for (int i = 0; i < 10; i++) {
164163
DatabaseCursor::Status status = cursor->Next(key, value);
165-
BOOST_ASSERT(status == DatabaseCursor::Status::MORE);
164+
BOOST_CHECK_EQUAL(status, DatabaseCursor::Status::MORE);
166165

167166
std::string key_back;
168167
unsigned int i_back;

test/lint/lint-assertions.py

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def main():
4545
":(exclude)src/rpc/server.cpp",
4646
], "CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.")
4747

48+
# The `BOOST_ASSERT` macro requires to `#include boost/assert.hpp`,
49+
# which is an unnecessary Boost dependency.
50+
exit_code |= git_grep([
51+
"-E",
52+
r"BOOST_ASSERT *\(.*\);",
53+
"--",
54+
"*.cpp",
55+
"*.h",
56+
], "BOOST_ASSERT must be replaced with Assert, BOOST_REQUIRE, or BOOST_CHECK.")
57+
4858
sys.exit(exit_code)
4959

5060

0 commit comments

Comments
 (0)