scripted-diff: [test] Add util/check.h includes for assertions #36074

pull maflcko wants to merge 3 commits into bitcoin:master from maflcko:2608-test-assert changing 155 files +341 −225
  1. maflcko commented at 9:30 AM on August 25, 2026: member

    In test code, assert is used. This is perfectly fine, but sometimes confusion arises, when it is unclear whether NDEBUG can disable the assertions, or whether to use assert or Assert.

    Avoid that confusion in test code with a scripted replacement to add the util/check.h include. The changes here will also make it easier to run IWYU.

    Scope: This change is only about test code (bench, fuzz, unit), other code can be done later, if there is need to.

  2. DrahtBot renamed this:
    scripted-diff: [test] replace assert with Assert
    scripted-diff: [test] replace assert with Assert
    on Aug 25, 2026
  3. DrahtBot added the label Refactoring on Aug 25, 2026
  4. DrahtBot commented at 9:30 AM on August 25, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36074.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #bitcoin-core/gui/954 (Add dialog to select change output when bumping fee by pablomartin4btc)
    • #bitcoin-core/gui/945 (qt: Fix sign message address book filtering by Bushstar)
    • #36159 (http: Improve HTTPRemoteClient::MaybeDisconnect() by hodlinator)
    • #36135 (fuzz: test HTTPRequest state machine in http_request by frankomosh)
    • #36130 (test: add tests in transaction_tests.cpp covering live mutants by ViniciusCestarii)
    • #36091 (test: Add debug output to common tested types by rustaceanrob)
    • #36070 (wallet: Add deriveHDKey interface by PraneethGunas)
    • #36068 (fuzz: reuse one fuzzed wallet across inputs by brunoerg)
    • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
    • #35916 (fuzz: improve ipc fuzz coverage by enirox001)
    • #35887 (ipc: use std::optional for checkSpawned(), add tests and rename arg -ipcfd to -ipcchild by ViniciusCestarii)
    • #35752 (wallet: make encryption state updates atomic by l0rinc)
    • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)
    • #35714 (validation: stop writes after flush failure by l0rinc)
    • #35713 (Remove boost as a unit test runner by rustaceanrob)
    • #35646 (RFC: Separate out runtime errors from BlockValidationState using util::Expected by yuvicc)
    • #35511 (RFC: consensus: Make CAmount a class by hodlinator)
    • #35377 (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101)
    • #35003 (validation: improve block data I/O error handling in P2P paths by furszy)
    • #34861 (wallet: Add importdescriptors interface by polespinasa)
    • #34778 (logging: rewrite macros to enforce restrictions at compile-time, improve efficiency and usability by ryanofsky)
    • #34681 (wallet: move rescan logic into ChainScanner and wallet/scan by Eunovo)
    • #32387 (ipc: add windows support by ryanofsky)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
    • #29278 (Wallet: Add maxfeerate wallet startup option by ismaelsadeeq)
    • #29256 (log, refactor: Allow log macros to accept context arguments by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. DrahtBot added the label CI failed on Aug 25, 2026
  6. DrahtBot commented at 10:52 AM on August 25, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task i686, no IPC: https://github.com/bitcoin/bitcoin/actions/runs/32832295932/job/97753466551</sub> <sub>LLM reason (✨ experimental): CI failed due to a C++ build error treated as fatal (-Werror=return-type) in bench/sign_transaction.cpp where an Assert(false) lambda triggers “control reaches end of non-void function.”</sub>

    <details><summary>Hints</summary>

    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.

    </details>

  7. maflcko marked this as a draft on Aug 25, 2026
  8. maflcko commented at 12:15 PM on August 25, 2026: member

    Hmm, I guess Assert(0/false) being a function trips GCC into thinking it can return? Though, the optimized codegen is unaffected on GCC. Funnily clang doesn't warn, but pessimises codegen: https://godbolt.org/z/h79K1scWK

    I guess that means we could add an explicit #define AssertUnreachable() assertion_fail(std::source_location::current(), "Unreachable code")

  9. DrahtBot added the label Needs rebase on Aug 26, 2026
  10. maflcko force-pushed on Aug 26, 2026
  11. DrahtBot removed the label Needs rebase on Aug 26, 2026
  12. in src/test/fuzz/mini_miner.cpp:122 in 3440553098
     124 | -        assert(!mini_miner.IsReadyToCalculate());
     125 | +        Assert(total_bumpfee.has_value());
     126 | +        Assert(!mini_miner.IsReadyToCalculate());
     127 |      }
     128 |      // Overlapping ancestry across multiple outpoints can only reduce the total bump fee.
     129 |      assert (sum_fees >= *total_bumpfee);
    


    jeanpablojp commented at 7:36 PM on August 26, 2026:

    This one doesn't match \<assert\( because of the space, and it's the only one left in the swept paths. lint_c_assert uses the same regex, so it doesn't catch it either. I added assert (1); to a covered file and the linter still passes. How about \<assert\s*\(?


    maflcko commented at 2:47 PM on August 29, 2026:

    Thx, but I've dropped the third and forth commit for now, because:


    l0rinc commented at 3:06 PM on August 29, 2026:

    This is why I only migrated the problematic usages with side effects - but I'm glad you're taking a stab at it systemically, even if just for tests for now

  13. in test/lint/test_runner/src/lint_cpp.rs:164 in 3440553098
     159 | +            "--",
     160 | +            // Limit to test-only code for now:
     161 | +            "src/test/",
     162 | +            "src/bench/",
     163 | +            "src/wallet/test/",
     164 | +            "src/qt/test/",
    


    jeanpablojp commented at 7:36 PM on August 26, 2026:

    src/ipc/test/ is left out here, and src/ipc/test/fuzz/ipc.cpp has six assert(. lint-tests.py already counts that directory as part of the test suite. Is this intentional?


    jeanpablojp commented at 5:02 PM on August 29, 2026:

    The comma in 'src/ipc/test/', ends up inside the element, so it still matches nothing.


    maflcko commented at 6:55 AM on September 1, 2026:

    The comma in 'src/ipc/test/', ends up inside the element, so it still matches nothing.

    Whoops, fixed. Thx

  14. maflcko renamed this:
    scripted-diff: [test] replace assert with Assert
    scripted-diff: [test] Add util/check.h includes for assertions
    on Aug 29, 2026
  15. DrahtBot renamed this:
    scripted-diff: [test] Add util/check.h includes for assertions
    scripted-diff: [test] Add util/check.h includes for assertions
    on Aug 29, 2026
  16. maflcko force-pushed on Aug 29, 2026
  17. DrahtBot removed the label CI failed on Aug 29, 2026
  18. maflcko force-pushed on Aug 31, 2026
  19. DrahtBot added the label Needs rebase on Aug 31, 2026
  20. maflcko force-pushed on Sep 1, 2026
  21. scripted-diff: [test] Add util/check.h includes for assertions
    The project has a compile error when compiled without assertions in
    util/check.h. Thus, util/check.h should be included for all assertions.
    
    So do that with a scripted-diff for Assert and assert, and remove the
    cassert include, which is exported from util/check.h.
    
    -BEGIN VERIFY SCRIPT-
    
     # Select all test .cpp and .h files
     paths=(
       'src/bench/'
       'src/ipc/test/'
       'src/qt/test/'
       'src/test/'
       'src/wallet/test/'
       ':(exclude)src/bench/nanobench.h'
     )
    
     # Add the util/check.h includes
     for f in $(git grep -l --extended-regexp "\<(a|A)ssert\(" -- "${paths[@]}"); do
       if ! grep --quiet "util/check.h" "$f"; then
         line=$(grep --line-number --max-count=1 '^#include' "$f" | cut --delimiter=: --fields=1)
         sed --in-place "${line}i#include <util/check.h>" "$f"
       fi
     done
    
     # Remove cassert includes
     for f in $(git grep -l '<cassert>' -- "${paths[@]}"); do
       sed --in-place '/^#include <cassert>$/d' "$f"
     done
    
    -END VERIFY SCRIPT-
    33afe004af
  22. lint: Allow clang-format to be used in scripted-diff
    Also, remove the unused pushd/popd. No command in this file requires a
    special PWD.
    4edc1a3e86
  23. scripted-diff: [test] Sort includes
    -BEGIN VERIFY SCRIPT-
    git show -U0 HEAD~1 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
    -END VERIFY SCRIPT-
    bd900dc6bb
  24. maflcko force-pushed on Sep 1, 2026
  25. DrahtBot added the label CI failed on Sep 1, 2026
  26. DrahtBot removed the label Needs rebase on Sep 1, 2026
  27. DrahtBot removed the label CI failed on Sep 1, 2026
  28. DrahtBot added the label Needs rebase on Sep 5, 2026
  29. DrahtBot commented at 1:21 PM on September 5, 2026: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-09-09 07:56 UTC