Skip to content

Commit 77bf05d

Browse files
committed
Remove remaining BOOST references
1 parent 7a582b6 commit 77bf05d

10 files changed

Lines changed: 70 additions & 38 deletions

File tree

doc/developer-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ code.
4949
naming style](#internal-interface-naming-style) for an exception to this
5050
convention.
5151

52-
- Test suite naming convention: The Boost test suite in file
52+
- Test suite naming convention: The test suite in file
5353
`src/test/foo_tests.cpp` should be named `foo_tests`. Test suite names
5454
must be unique.
5555

src/test/README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Unit tests
22

3-
The sources in this directory are unit test cases. Boost includes a
4-
unit testing framework, and since Bitcoin Core already uses Boost, it makes
5-
sense to simply use this framework rather than require developers to
6-
configure some other framework (we want as few impediments to creating
7-
unit tests as possible).
3+
The sources in this directory are unit test cases. Tests use a small
4+
header-only framework declared in `src/test/util/framework.hpp`, which
5+
provides registration macros (`TEST_CASE`, `FIXTURE_TEST_CASE`,
6+
`TEST_SUITE_BEGIN`/`TEST_SUITE_END`) and assertion macros (`CHECK`,
7+
`REQUIRE`, `CHECK_THROWS`, `CHECK_THROWS_AS`, `CHECK_EXCEPTION`,
8+
`CHECK_EQUAL_RANGES`, `TEST_MESSAGE`, `WARN_MESSAGE`).
89

910
The build system is set up to compile an executable called `test_bitcoin`
1011
that runs all of the unit tests. The main source file for the test library is found in
@@ -22,27 +23,26 @@ and tests weren't explicitly disabled.
2223
The unit tests can be run with `ctest --test-dir build`, which includes unit
2324
tests from subtrees.
2425

25-
Run `build/bin/test_bitcoin --list_content` for the full list of tests.
26+
Run `build/bin/test_bitcoin --list` for the full list of tests.
2627

2728
To run the unit tests manually, launch `build/bin/test_bitcoin`. To recompile
2829
after a test file was modified, run `cmake --build build` and then run the test again. If you
2930
modify a non-test file, use `cmake --build build --target test_bitcoin` to recompile only what's needed
3031
to run the unit tests.
3132

32-
To add more unit tests, add `BOOST_AUTO_TEST_CASE` functions to the existing
33-
.cpp files in the `test/` directory or add new .cpp files that
34-
implement new `BOOST_AUTO_TEST_SUITE` sections.
33+
To add more unit tests, add `TEST_CASE` (or `FIXTURE_TEST_CASE`) functions to
34+
the existing .cpp files in the `test/` directory, or add new .cpp files that
35+
declare a new suite with `TEST_SUITE_BEGIN("<name>")`.
3536

3637
### Running individual tests
3738

38-
The `test_bitcoin` runner accepts command line arguments from the Boost
39-
framework. To see the list of arguments that may be passed, run:
39+
To see the list of arguments that may be passed, run:
4040

4141
```
4242
build/bin/test_bitcoin --help
4343
```
4444

45-
For example, to run only the tests in the `getarg_tests` file, with full logging:
45+
For example, to run only the tests in the `getarg_tests` suite, with full logging:
4646

4747
```bash
4848
build/bin/test_bitcoin --log_level=all --run_test=getarg_tests
@@ -54,13 +54,14 @@ or
5454
build/bin/test_bitcoin -l all -t getarg_tests
5555
```
5656

57-
or to run only the doubledash test in `getarg_tests`
57+
or to run only the `doubledash` test in `getarg_tests`
5858

5959
```bash
60-
build/bin/test_bitcoin --run_test=getarg_tests/doubledash
60+
build/bin/test_bitcoin --run_test=getarg_tests::doubledash
6161
```
6262

6363
The `--log_level=` (or `-l`) argument controls the verbosity of the test output.
64+
Accepted values: `none`, `error` (default), `info`, `all`.
6465

6566
The `test_bitcoin` runner also accepts some of the command line arguments accepted by
6667
`bitcoind`. Use `--` to separate these sets of arguments:
@@ -126,8 +127,10 @@ additionally use the `--output-on-failure` option to display logs of the failed
126127
on failure. For running individual tests verbosely, refer to the section
127128
[above](#running-individual-tests).
128129

129-
To write to logs from unit tests you need to use specific message methods
130-
provided by Boost. The simplest is `BOOST_TEST_MESSAGE`.
130+
To write a diagnostic message from a unit test, use `TEST_MESSAGE(...)`
131+
(emitted at log level `info` or higher). `WARN_MESSAGE(cond, msg)` emits
132+
a warning when `cond` is false without failing the test — use `CHECK` /
133+
`REQUIRE` to fail.
131134

132135
For debugging you can launch the `test_bitcoin` executable with `gdb` or `lldb` and
133136
start debugging, just like you would with any other program:
@@ -146,13 +149,9 @@ Another tool that can be used to resolve segmentation faults is
146149
[valgrind](https://valgrind.org/).
147150

148151
If for whatever reason you want to produce a core dump file for this fault, you can do
149-
that as well. By default, the boost test runner will intercept system errors and not
150-
produce a core file. To bypass this, add `--catch_system_errors=no` to the
151-
`test_bitcoin` arguments and ensure that your ulimits are set properly (e.g. `ulimit -c
152-
unlimited`).
153-
154-
Running the tests and hitting a segmentation fault should now produce a file called `core`
155-
(on Linux platforms, the file name will likely depend on the contents of
152+
that as well. Ensure that your ulimits are set properly (e.g. `ulimit -c unlimited`),
153+
then running the tests and hitting a segmentation fault should produce a file called
154+
`core` (on Linux platforms, the file name will likely depend on the contents of
156155
`/proc/sys/kernel/core_pattern`).
157156

158157
You can then explore the core dump using

src/test/btcsignals_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ FIXTURE_TEST_CASE(thread_safety, BasicTestingSetup)
160160
sig0();
161161
}
162162
// Because these calls are purposely happening on both threads at the
163-
// same time, these must be asserts rather than BOOST_CHECKs to prevent
164-
// a race inside of BOOST_CHECK itself (writing to the log).
163+
// same time, these must be asserts rather than CHECKs to prevent
164+
// a race inside of CHECK itself (writing to the log).
165165
assert(!sig0.empty());
166166
assert(conn0.connected());
167167
});

src/test/cuckoocache_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* 3. Results should be treated as a regression test, i.e., did the behavior
2626
* change significantly from what was expected. This can be OK, depending on
2727
* the nature of the change, but requires updating the tests to reflect the new
28-
* expected behavior. For example improving the hit rate may cause some tests
29-
* using BOOST_CHECK_CLOSE to fail.
28+
* expected behavior. For example improving the hit rate may cause some
29+
* tolerance-based checks to fail.
3030
*
3131
*/
3232
TEST_SUITE_BEGIN(cuckoocache_tests);

src/test/descriptor_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,8 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
283283
CHECK(parse_priv->IsRange() == ((flags & RANGE) != 0));
284284

285285
// Check that the highest key expression index matches the number of keys in the descriptor
286-
/* BOOST_TEST_INFO("Pub desc: " + pub) */;
287286
uint32_t key_exprs = parse_pub->GetMaxKeyExpr();
288287
CHECK(key_exprs + 1 == parse_pub->GetKeyCount());
289-
/* BOOST_TEST_INFO("Priv desc: " + prv) */;
290288
CHECK(key_exprs == parse_priv->GetMaxKeyExpr());
291289
CHECK(key_exprs + 1 == parse_priv->GetKeyCount());
292290

src/test/logging_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,12 @@ void TestLogFromLocation(Location location, const std::string& message,
395395
BCLog::LogRateLimiter::Status status, bool suppressions_active,
396396
std::source_location source = std::source_location::current())
397397
{
398-
/* BOOST_TEST_INFO_SCOPE("TestLogFromLocation called from " << source.file_name() << ":" << source.line()) */;
399398
using Status = BCLog::LogRateLimiter::Status;
400399
if (!suppressions_active) assert(status == Status::UNSUPPRESSED); // developer error
401400

402401
std::ofstream ofs(LogInstance().m_file_path.std_path(), std::ios::out | std::ios::trunc); // clear debug log
403402
LogFromLocation(location, message);
404403
auto log_lines{ReadDebugLogLines()};
405-
/* BOOST_TEST_INFO_SCOPE(log_lines.size() << " log_lines read: \n" << util::Join(log_lines, "\n")) */;
406404

407405
if (status == Status::STILL_SUPPRESSED) {
408406
CHECK(log_lines.size() == 0U);

src/test/util/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <string>
1212

1313
/**
14-
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
14+
* Predicate to check the specific validation error.
1515
* Use as
1616
* CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));
1717
*/
@@ -26,7 +26,7 @@ class HasReason
2626
const std::string m_reason;
2727
};
2828

29-
// Make types usable in BOOST_CHECK_* @{
29+
// Make types usable in CHECK / REQUIRE @{
3030
namespace std {
3131
template <typename Clock, typename Duration>
3232
inline std::ostream& operator<<(std::ostream& os, const std::chrono::time_point<Clock, Duration>& tp)

src/test/versionbits_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
373373
}
374374

375375
if (nTimeout != Consensus::BIP9Deployment::NO_TIMEOUT) {
376-
// can reach any nTimeout other than NO_TIMEOUT due to earlier BOOST_REQUIRE
376+
// can reach any nTimeout other than NO_TIMEOUT due to earlier REQUIRE
377377

378378
nTime = nTimeout;
379379

test/lint/test_runner/src/lint_cpp.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn lint_boost_assert() -> LintResult {
195195
.success();
196196
if found {
197197
Err(r#"
198-
BOOST_ASSERT must be replaced with Assert, BOOST_REQUIRE, or BOOST_CHECK to avoid an unnecessary
198+
BOOST_ASSERT must be replaced with Assert, REQUIRE, or CHECK to avoid an unnecessary
199199
include of the boost/assert.hpp dependency.
200200
"#
201201
.trim()
@@ -204,3 +204,35 @@ include of the boost/assert.hpp dependency.
204204
Ok(())
205205
}
206206
}
207+
208+
pub fn lint_boost_test() -> LintResult {
209+
let found = git()
210+
.args([
211+
"grep",
212+
"--line-number",
213+
"--extended-regexp",
214+
r"BOOST_(AUTO_TEST_|FIXTURE_TEST_|GLOBAL_FIXTURE|DATA_TEST_|CHECK|REQUIRE|TEST|WARN)",
215+
"--",
216+
"*.cpp",
217+
"*.h",
218+
// src/univalue is a subtree (not tracked in get_subtrees()); its tests use Boost.Test independently.
219+
":(exclude)src/univalue",
220+
])
221+
.args(get_pathspecs_default_excludes())
222+
.status()
223+
.expect("command error")
224+
.success();
225+
if found {
226+
Err(r#"
227+
Boost.Test macros (BOOST_CHECK*, BOOST_REQUIRE*, BOOST_AUTO_TEST_*, BOOST_FIXTURE_TEST_*,
228+
BOOST_TEST*, BOOST_WARN*, BOOST_GLOBAL_FIXTURE, BOOST_DATA_TEST_*) are no longer used.
229+
Replace with the equivalents from src/test/util/framework.hpp (CHECK, REQUIRE, TEST_CASE,
230+
FIXTURE_TEST_CASE, TEST_SUITE_BEGIN, CHECK_THROWS, CHECK_THROWS_AS, CHECK_EXCEPTION,
231+
TEST_MESSAGE, WARN_MESSAGE, etc.).
232+
"#
233+
.trim()
234+
.to_string())
235+
} else {
236+
Ok(())
237+
}
238+
}

test/lint/test_runner/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::fs;
1414
use std::process::{Command, ExitCode};
1515

1616
use lint_cpp::{
17-
lint_boost_assert, lint_includes_build_config, lint_remove_all, lint_rpc_assert,
18-
lint_std_filesystem,
17+
lint_boost_assert, lint_boost_test, lint_includes_build_config, lint_remove_all,
18+
lint_rpc_assert, lint_std_filesystem,
1919
};
2020
use lint_docs::{lint_doc_args, lint_doc_release_note_snippets, lint_markdown};
2121
use lint_py::lint_py_lint;
@@ -73,6 +73,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
7373
name: "boost_assert",
7474
lint_fn: lint_boost_assert
7575
},
76+
&Linter {
77+
description: "Check that Boost.Test macros are not used (use src/test/util/framework.hpp)",
78+
name: "boost_test",
79+
lint_fn: lint_boost_test
80+
},
7681
&Linter {
7782
description: "Check that release note snippets are in the right folder",
7883
name: "doc_release_note_snippets",

0 commit comments

Comments
 (0)