scripted-diff: [test] replace assert with Assert #36074

pull maflcko wants to merge 4 commits into bitcoin:master from maflcko:2608-test-assert changing 204 files +1878 −1726
  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 and a small linter to enforce it going forward.

    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)
    • #36091 (test: Add debug output to common tested types by rustaceanrob)
    • #36087 (util: Add and use AssertUnreachable by maflcko)
    • #36068 (fuzz: reuse one fuzzed wallet across inputs by brunoerg)
    • #36042 (build: Bump g++ minimum supported version to 13 by maflcko)
    • #36033 ([wip,nomerge,rfc] build: Require C++23 compiler by maflcko)
    • #36031 (wallet: Remove mapMasterKeys and enforce that only one encryption key can exist by achow101)
    • #36015 (txorphanage: bound orphan memory by storing transactions serialized by brunoerg)
    • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
    • #35975 (wallet: Fix CWalletTx malleated transaction metadata sync by achow101)
    • #35911 (Warn on and add missing [[noreturn]] by fanquake)
    • #35793 (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior)
    • #35752 (wallet: make encryption state updates atomic by l0rinc)
    • #35733 (sign: Remove FillableSigningProvider by achow101)
    • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)
    • #35716 (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101)
    • #35714 (validation: stop writes after flush failure by l0rinc)
    • #35713 (Remove boost as a unit test runner by rustaceanrob)
    • #35662 (script: prevent stale sighash caches across transactions by l0rinc)
    • #35570 (refactor: Change some validation.cpp methods to return BlockValidationState by optout21)
    • #35569 (Encapsulation for CTransaction by purpleKarrot)
    • #35557 (kernel, validation: Add btck_chainstate_manager_set_clock_time by ryanofsky)
    • #35511 (RFC: consensus: Make CAmount a class by hodlinator)
    • #35351 (net: Disallow invalid HeadersSyncState due to lagging clock by hodlinator)
    • #35170 (test: Better test coverage for legacy ParseHDKeypath() by optout21)
    • #35003 (validation: improve block data I/O error handling in P2P paths by furszy)
    • #34969 (fuzz: several improvements to scriptpubkeyman harness by brunoerg)
    • #34864 (coins: tighten cache entry state invariants by l0rinc)
    • #34861 (wallet: Add importdescriptors interface by polespinasa)
    • #34778 (logging: rewrite macros to enforce restrictions at compile-time, improve efficiency and usability by ryanofsky)
    • #34698 (wallet: handle MiniMiner bump fee calculation failures by shuv-amp)
    • #34681 (wallet: move rescan logic into ChainScanner and wallet/scan by Eunovo)
    • #34132 (coins,dbwrapper: remove error catcher, make point-read failures fatal by l0rinc)
    • #32729 (test,script: add sigop helpers (without consensus migration) by l0rinc)
    • #32554 (bench: replace embedded raw block with configurable block generator by l0rinc)
    • #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)
    • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
    • #27260 (Enhanced error messages for invalid network prefix during address parsing. by portlandhodl)
    • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic 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-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • // Dont check any values, just that each success result must fit into -> // Don't check any values, just that each successful result must fit into [“Dont” is misspelled; the intended meaning is clear but the apostrophe is missing]

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false) in src/bench/duplicate_inputs.cpp

    <sup>2026-08-26 11:29:19</sup>

  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. 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/test/'
       'src/bench/'
       'src/wallet/test/'
       'src/qt/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
         if [[ "$f" == *.cpp ]]; then
           line=5
         else
           line=8
         fi
         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-
    7140a3a35d
  11. refactor: [test] Sort includes
    This can be reproduced by checking out the previous commit and running:
    git show -U0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
    209333c1df
  12. scripted-diff: [test] replace assert with Assert
    -BEGIN VERIFY SCRIPT-
    
     sed -i --regexp-extended 's/\<assert\(/Assert(/g' $(git grep -l --extended-regexp '\<assert\(' -- \
       src/test/ \
       src/bench/ \
       src/wallet/test/ \
       src/qt/test/ \
       ":(exclude)src/bench/nanobench.h" \
     )
    
    -END VERIFY SCRIPT-
    16790da4ef
  13. test: lint C assert usage 3440553098
  14. maflcko force-pushed on Aug 26, 2026
  15. DrahtBot removed the label Needs rebase on Aug 26, 2026

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-08-26 19:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me