Repository navigation
Remove boost as a unit test runner - #35587
rustaceanrob wants to merge 19 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35587. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. LLM Linter (✨ experimental)Possible typos and grammar issues:
Possible places where named args for integral literals may be used (e.g.
2026-07-13 09:40:05 |
|
Strong Concept ACK
Boost may have multiple problems on its own, but the problems that you list are specific to Boost.Test. You should not conflate the two.
Iterators or Ranges?
Boost.Test allows arbitrary deep nesting of test suites. When integrating Boost.Test into CTest, this causes headaches for little benefit. I hope we can follow-up on this and restrict the test hierarchy to exactly one test suite (no more and no less) using something along the
In my opinion, concurrency does not belong in a testing framework. Many testing frameworks have a test driver built-in. But separating test framework and test driver into two orthogonal components allows much more powerful composition. I would even go so far and claim that a test framework should not provide a way to run more than one test; neither concurrently, nor sequentially. What a test framework needs to be able to provide, is a way to launch a single test and a way to tell the test driver about the list of tests that are available. The test driver can then orchestrate tests from different testing frameworks from potentially different programming languages and invoke tests individually, sequentially, concurrently, or even distributed across multiple hosts. This kind of integration is exactly the reason why I implemented discover_tests, which will be available in CMake 4.4. 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! |
Boost.Test is not a dependency of |
Correct me if I'm wrong but it appears the config here still builds
That approach used STL containers. An actual replacement would need to use something like this: https://www.mail-archive.com/[email protected]/msg33920.html |
Yes, but what does that have to with my comment? I just said that it's a dependency of
I would read this very clearly as boost (including Boost.Test) is a dependency of
The pull was rejected on conceptual basis, not approach, so I don't think this matters. |
Sure, PR description updated.
I find this less obvious then the comment implies. A repository going stale is far more likely than some backdoor or high severity CVE, so "a lot more interesting" feels subjective. |
A lot. @rustaceanrob correctly points out that even though |
Precisely. It's also worth remembering the |
|
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:
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:
|
Makes the output size of each hash known at compile time for other TU. When using expression decomposition, like in `BOOST_TEST` or the framework introduced later, expressions are captured as `const T&` function arguments whose values must be known at compile time.
Makes the size of the pool known at compile time for other TU. When using expression decomposition, like in `BOOST_TEST` or the framework introduced later, expressions are captured as `const T&` function arguments whose values must be known at compile time.
Needed to use `==` operator in tests.
This is being brought in transitively by boost
libboost_unit_test_framework is prebuilt without MSan/UBSan, so these uninitialized reads were not flagged. The test framework introduced in later commits is compiled with the sanitizers.
There is only a single case of this macro and the if conditional that triggers it may simply be used in a `BOOST_REQUIRE`
In the case of `descriptor_tests.cpp`, the info is only used to get the diagonsics of `BOOST_CHECK_EQUAL` along with the human readable form of the descriptor. This is irrelevant if the test framework implements expression decomposition, which will print the string representation on failure (e.g. `BOOST_TEST`). Removing `BOOST_TEST_INFO_SCOPE` requires a few duplications, but these are very little cost compared to a port of this macro, which does not appear very useful.
This is only used in a single test and would be a low-motivation add to porting the test framework. A lambda is sufficient to enforce the check.
9d28114 to
4793cb1
Compare
gcc12 warns with uninitialized when boost is not used for this test. This side-steps the warning.
`EraseTx` already returns a `bool`, so these implicit casts within the comparisons are not necessary.
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. 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://fekir.info/post/decomposing-an-expression/
The `||` is not usable with `BOOST_TEST` and other modern test frameworks like Catch2. This is due to operator precedence used in such macros. Here is an additional opinion from Catch2: > There is no simple rewrite rule for ||, but I generally believe that if you have || in your test expression, you should rethink your tests. ref: https://catch2-temp.readthedocs.io/en/latest/assertions.html#other-limitations ref: https://fekir.info/post/decomposing-an-expression/
-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 's|BOOST_TEST_MODULE Bitcoin Kernel Test Suite|BITCOIN_TEST_MAIN|; 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| --catch_system_error=no||' src/test/CMakeLists.txt -END VERIFY SCRIPT-
4793cb1 to
421271d
Compare
|
Closing and reopening to remove the github UI items |
is this a UI bug or was this reopened @sedited |
|
Oh, I completely misunderstood what you wanted to do here. Closing. |

tl;dr: Make an equivalent test runner to boost with simpler macros and tighter coupling to bitcoin-specific code.
Motivation
There are a number of problems with using dependencies in general. Bugs must either be promptly upstreamed or patched, projects may be abandoned, and they are not tailored to a particular use case. This PR removes boost for writing and running unit tests. In the case of Boost.Test, there are a number of issues which are listed below.
My problems with Boost.Test
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 forexpr1andexpr2BOOST_CHECK_EQUAL(expr1, expr2): failures show the expression and values, but requires developers rememberCHECK_EQUALand does not use usual operandsBOOST_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 forexpr1andexpr2To 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, andBOOST_CHECK_EQUALis unintuitive)Example boost outputs
New outputs
No repository context
Many types implement
ToString, but boost has no way of meaningfully using these representations (will change w/ futurestd::format). With a repository-specific test runner we can use these today. See example above.Not extensible
With the test runner in this repository we can add things such as #35139, implement string representations for more types, and implement ideas from #8670.
Other issues
More issues with boost are raised in #34666, #8670. This PR does not resolve all of them, but one it does address immediately is banning comparisons of integers with different signs, previously allowed by boost. Using a test runner within the source also makes IWYU easier to work with.
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. This includescatch_system_errorswhich is always no. Thelog_levelshave been reduced to 5 levels.Changes in writing tests
CHECKto compare two values with any==,!=,>, etcCHECK(a == b, "my message")to append a messageREQUIRE, same asCHECK, but will fail the test immediatelyCHECK_EQUAL_RANGES(it1, it2)to compare two rangesTEST_CASE(name)to add a testFIXTURE_TEST_CASE(name, Fixture)to add a test with a fixtureTEST_SUITE_BEGIN/ENDto declare a suite, optionally with fixture for each test in the suiteMigration
Boost.Testis removed in this PR, but the macros are aliased byBOOST_*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.Commits
The addition of the framework:
Migration script (majority of the file changes):
Low usage count macro removals:
BOOST_FAILBOOST_TEST_INFO_*BOOST_CHECK_CLOSERequired for expression decomposition:
&&conditions in macros||expressions in macros&expressions in macrosTo pass CI
Build and config