Skip to content

Remove boost as a unit test runner - #35713

Open
rustaceanrob wants to merge 7 commits into
bitcoin:masterfrom
rustaceanrob:remove-boost-test
Open

rustaceanrob wants to merge 7 commits into
bitcoin:masterfrom
rustaceanrob:remove-boost-test

Conversation

@rustaceanrob

@rustaceanrob rustaceanrob commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Continued from #35587. tl;dr: Make an equivalent test runner to boost with simpler macros and tighter coupling to bitcoin-specific code.

Motivation

Replacing Boost.Test as a runner helps us simplify depends and guix as well as use IWYU and clang-tidy within the tests more effectively. It is my opinion that we can also improve the developer experience when writing tests. The repo currently uses a very small subset of Boost.Test, which offers a relatively simple replacement.

Macros

Rant on macros

When using boost, there are 3 ways of writing the same thing, each with different outcomes

  • BOOST_CHECK(expr1 == expr2): failures show the expression, but no values for expr1 and expr2
  • BOOST_CHECK_EQUAL(expr1, expr2): failures show the expression and values, but requires developers remember CHECK_EQUAL and does not use usual operands
  • BOOST_TEST(expr1 == expr2): failures show the expression and values, and developers may use familiar operands (==, !=)

All three are preserved to maintain backwards compatibility - presumably, but this results in all 3 being used throughout the repository. As a bonus there is a 4th way, with added context

  • BOOST_CHECK_MESSAGE(expr1 == expr2, "the context"): failures show the expression and message, but no values for expr1 and expr2

To make debugging and review easier, all of these should be unified to a single macro. Test sites use operands, print helpful messages - values are always included, and do not vary in approach (deciding between BOOST_TEST, CHECK, and BOOST_CHECK_EQUAL is unintuitive)

Example boost outputs
BOOST_AUTO_TEST_CASE(mustfail)
{
    auto a{1};
    auto b{2};
    BOOST_CHECK(a == b);
    BOOST_CHECK_EQUAL(a, b);
    BOOST_TEST(a == b);
    COutPoint outpoint_1{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 0};
    COutPoint outpoint_2{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 1};
    BOOST_CHECK(outpoint_1 == outpoint_2);
    // Doesn't even compile
    // BOOST_TEST(outpoint_1 == outpoint_2);
    // BOOST_CHECK_EQUAL(outpoint_1, outpoint_2);
}
Running 1 test case...
test/argsman_tests.cpp(31): error: in "argsman_tests/mustfail": check a == b has failed
test/argsman_tests.cpp(32): error: in "argsman_tests/mustfail": check a == b has failed [1 != 2]
test/argsman_tests.cpp(33): error: in "argsman_tests/mustfail": check a == b has failed [1 != 2]
test/argsman_tests.cpp(36): error: in "argsman_tests/mustfail": check outpoint_1 == outpoint_2 has failed
New outputs
TEST_CASE(mustfail)
{
    auto a{1};
    auto b{2};
    CHECK(a == b);
    COutPoint outpoint_1{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 0};
    COutPoint outpoint_2{Txid{"0000000000000000000000000000000000000000000000000000000000000100"}, 1};
    CHECK(outpoint_1 == outpoint_2);
}
Running 1 test cases...
[FAIL]: test/argsman_tests.cpp:30: CHECK(a == b)
1 == 2

[FAIL]: test/argsman_tests.cpp:33: CHECK(outpoint_1 == outpoint_2)
COutPoint(0000000000, 0) == COutPoint(0000000000, 1)

[FAIL] mustfail (2/2 checks failed)

No repository context

A custom framework allows for complete control of debug output, console output, CLI arguments, etc. #35587 (comment)

Other issues

Issues are mentioned in #34666, #8670, #36045.

High level changes

For those running tests, not a tremendous amount has changed in this PR. For instance, the doc page remains valid. Changes to the runner options include anything that is not help, run_test, log_level, list_content or used in CI.

For an explanation of all the internal details, I have written a detailed personal blog

Changes in writing tests

Macro shims are added so developers may continue using the usual BOOST_* macros. Future changes to writing tests would include:

  • CHECK to compare two values with any ==, !=, >, etc
  • CHECK(a == b, "my message") to append a message
  • CHECK_NO_DISPLAY to compare two values without a debug output of said values (expression is printed)
  • REQUIRE, same as CHECK, but will fail the test immediately
  • TEST_CASE(name) to add a test
  • FIXTURE_TEST_CASE(name, Fixture) to add a test with a fixture
  • TEST_SUITE_BEGIN/END to declare a suite, optionally with fixture for each test in the suite

Migration

Boost.Test is removed in this PR, but the macros are aliased by BOOST_* counterparts so there are no merge conflicts. The idea would be to migrate test files to the new macros when there are no/low number of conflicts on that file.

@DrahtBot

DrahtBot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK josibake, jeanpablojp, sedited, ismaelsadeeq

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37016 (rpc: fail scanblocks instead of silently skipping missing filters by shivansh023023)
  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #36629 (Add output script index and corresponding script history RPC by andrewtoth)
  • #36434 (http: support unix sockets by pinheadmz)
  • #36033 ([wip,nomerge,rfc] build: Require C++23 compiler by maflcko)
  • #35855 (guix: update time-machine by fanquake)
  • #35662 (script: prevent partial reinitialization of sighash data by l0rinc)
  • #35195 (coins: cache UTXO outpoint hash codes by l0rinc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@josibake

josibake commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Moving over my original ACK from the previous PR: #35587 (comment)


Strong Concept ACK!

Love to see it. While I broadly agree with the author's reasons stated in the PR, the ones I'll highlight specifically are:

  • No repository context
  • Not extensible

Having our own simple, in house test framework gives us the ability to customise it for exactly our needs. I believe we should do everything in our power to make testing an easy, intuitive, and feature rich experience as this helps to remove barriers to people writing and interpreting tests.

In particular, as a longer term project I am looking at ways to improve concurrency in our testing to help speed up CI. As @purpleKarrot points out:

The Boost.Test framework is notoriously bad at this. When selecting a single test, it spams out information about all tests that are not selected. While it can provide information about what tests are available, that output is optimized for human readability and very hard to parse by a test driver. We can definitely do better with a custom test framework!

Comment thread src/test/util/framework.h Resolved
Comment thread src/test/dbwrapper_tests.cpp Resolved
Comment thread src/test/util/framework.h Resolved
@rustaceanrob

Copy link
Copy Markdown
Member Author

Draft while I work on #35713 (comment)

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/40514159688/job/122223576644
LLM reason (✨ experimental): CI failed because clang-tidy flagged out += "]"; in test/util/framework.cpp:127; use the single-character overload (out += ']').

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@sedited

sedited commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@stringintech

Copy link
Copy Markdown
Member

@rustaceanrob was interested in seeing how the changes would affect compatibility with common IDEs. So I took a quick look at CLion, which is what I primarily use, to see how it would be affected by the changes.

For individual tests to be detected by the IDE and appear as runnable directly from the test file, the macros have to expand into code from a framework supported by the IDE (Boost.Test being one of them). This is why, for example, the following play buttons would disappear after the changes introduced by this PR:

image

However, since CTest is still supported by the IDE, we're still able to use the features CLion provides for it, including adding run configurations and running test suites directly from the CMake files:

image

@ismaelsadeeq

Copy link
Copy Markdown
Member

Concept ACK

@rustaceanrob

rustaceanrob commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

ea7d900 addressed Ralph, simplified the argument parsing a bit, and dropped an unneeded depends patch

edit: Ralphs current comments I am going to put off as low priority or obvious misuse.

rustaceanrob and others added 7 commits December 3, 2026 22:31
This commit introduces a new test runner as well as the associated
macros. The runner takes inspiration from boost, catch2, and doctest.
Notably, expressions are "decomposed" by taking each value and recording
a debug string in the case of an invalid expression. It does so by
overriding an operator (<=) before other comparison operations are
evaluated. Each test initializes a `TestContext` that manages the test
state and scoped logs.

The `TestContext` requires thread awareness to manage scoped logs in
potentially many threads. `REQUIRE` thrown on child threads is also
invalid because the exception cannot propagate to the main thread.

With respect to the comparison checks in `CapturedExpression`, C style
strings and integers have special handling. C style stirngs are compared
by the value of the string, not the memory address, which is the same
behavior as boost. Integers with mixed signs are compared using
`std::cmp_*`, which is a deliberate deviation from boost. This removes
potential underflows or overflows similar to bitcoin#35689. All other types are
compared by the comparison operator.

Compatiblity with boost is maintained for environment variables and CLI
arguments that are used in CI and docs.

`new_main.cpp` is defined here so reviewers can easily look at the file, but
it is renamed to `main.cpp` in the following commit.

ref: https://fekir.info/post/decomposing-an-expression/
This migrates the test runner, boost header imports, and linter.
`include <memory>` line is to fix an IWYU.

-BEGIN VERIFY SCRIPT-
mv src/test/new_main.cpp src/test/main.cpp
git grep -l '<boost/test/unit_test.hpp>' | xargs sed -i 's|<boost/test/unit_test.hpp>|<test/util/framework.h>|'
sed -i '/SIGSTKSZ/d; /BOOST_TEST_DISABLE_ALT_STACK/d; /BOOST_TEST_MODULE/d; s|<boost/test/included/unit_test.hpp>|<test/util/framework.h>|' src/test/kernel/test_kernel.cpp
sed -i 's|boost::unit_test::framework::master_test_suite().argv\[0\]|framework::executable_path()|' src/test/system_tests.cpp
sed -i '/boost\/test\/\(included\/\)\?unit_test.hpp/d' test/lint/lint-includes.py
sed -i 's|#include <test/util/framework.h>|&\n\n#include <memory>|' src/test/result_tests.cpp
sed -i '/^    Boost::headers$/d' src/test/kernel/CMakeLists.txt
-END VERIFY SCRIPT-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants