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

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2608-test-assert changing 57 files +151 −110
  1. maflcko commented at 9:44 AM on November 12, 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, other code can be done later, if there is need to.

    (Currently a draft, because it waits on other stuff)

  2. 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 to use util/check.h.
    
    -BEGIN VERIFY SCRIPT-
    
     # Files to edit.
     paths=(
       'src/bench/'
       'src/ipc/test/'
       'src/qt/test/'
       'src/test/'
       'src/wallet/test/'
       ':(exclude)src/bench/nanobench.h'
     )
    
     for f in $(git grep -l --extended-regexp '\<(a|A)ssert\(' -- "${paths[@]}"); do
    
       # Add the util/check.h include when needed.
       if ! git 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
    
       # Remove leftover cassert includes.
       sed --in-place '/^#include <cassert>$/d' "$f"
    
     done
    
    -END VERIFY SCRIPT-
    113fa13d90
  3. scripted-diff: [test] Sort includes
    -BEGIN VERIFY SCRIPT-
     git show -U0 HEAD~0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
    -END VERIFY SCRIPT-
    71f48a6e93
  4. DrahtBot renamed this:
    scripted-diff: [test] Add util/check.h includes for assertions
    scripted-diff: [test] Add util/check.h includes for assertions
    on Nov 12, 2026
  5. DrahtBot added the label Refactoring on Nov 12, 2026
  6. maflcko marked this as a draft on Nov 12, 2026
  7. DrahtBot commented at 9:44 AM on November 12, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--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/945 <sub><img src="https://drahtbot.space/ack_count/bitcoin-core/gui/945.svg"></sub> (Fix sign message address book filtering by Bushstar)
    • #36844 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36844.svg"></sub> (iwyu: Fix warnings in some modules in src/ and treat them as errors by hebasto)
    • #36832 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36832.svg"></sub> (test: speed up wallet unit test by ViniciusCestarii)
    • #36808 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
    • #36737 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36737.svg"></sub> (qa: check more socket API invariants for each platform we support by darosior)
    • #36548 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36548.svg"></sub> (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
    • #36520 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36520.svg"></sub> (interfaces: Avoid node crashes from invalid Chain IPC calls by ryanofsky)
    • #36506 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36506.svg"></sub> (p2p: plug "tier 1" 1p1c liveness holes by instagibbs)
    • #36386 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36386.svg"></sub> (compressor: oversized script decoding can leave a spendable script by l0rinc)
    • #36280 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36280.svg"></sub> (validation: throw when a compressed script can't be decompressed by furszy)
    • #36167 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable -Wunused by fanquake)
    • #36040 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36040.svg"></sub> (Wallet: Don't backdate locktime rbf by Bicaru20)
    • #36000 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36000.svg"></sub> (validation: prefetch blocks while connecting by l0rinc)
    • #35731 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35731.svg"></sub> (Indexes: Harden the flush-error notification invariant by arejula27)
    • #35713 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob)
    • #35302 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo)
    • #35003 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35003.svg"></sub> (validation: improve block data I/O error handling in P2P paths by furszy)

    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-->

Contributors

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

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