Skip to content

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

Draft
maflcko wants to merge 2 commits into
bitcoin:masterfrom
maflcko:2608-test-assert
Draft

maflcko wants to merge 2 commits into
bitcoin:masterfrom
maflcko:2608-test-assert

Conversation

@maflcko

@maflcko maflcko commented Nov 22, 2026

Copy link
Copy Markdown
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)

MarcoFalke added 2 commits November 22, 2026 14:03
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-
-BEGIN VERIFY SCRIPT-
 git show -U0 HEAD~0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
-END VERIFY SCRIPT-
@DrahtBot DrahtBot changed the title scripted-diff: [test] Add util/check.h includes for assertions scripted-diff: [test] Add util/check.h includes for assertions Nov 22, 2026
@maflcko
maflcko marked this pull request as draft November 22, 2026 13:12
@DrahtBot

DrahtBot commented Nov 22, 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.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37094 (validation: validate assumeutxo snapshots with a single chainstate by fjahr)
  • #36971 (blockstorage: fix partial-mask assertions and genesis availability checks by l0rinc)
  • #36844 (iwyu: Fix warnings in more modules in src/ and treat them as errors by hebasto)
  • #36832 (test: speed up wallet unit test by ViniciusCestarii)
  • #36831 (test: split test_IsStandard into independent test cases by yuvicc)
  • #36737 (qa: check more socket API invariants for each platform we support by darosior)
  • #36603 (Improve loadtxoutset performance by ajtowns)
  • #36548 (net: serve MSG_BLOCK by stripping witnesses in place by l0rinc)
  • #36520 (interfaces: Avoid node crashes from invalid Chain IPC calls by ryanofsky)
  • #36506 (p2p: plug "tier 1" 1p1c liveness holes by instagibbs)
  • #36386 (compressor: reject oversized scripts during deserialization by l0rinc)
  • #36280 (validation: throw when a compressed script can't be decompressed by furszy)
  • #36167 (build: Enable -Wunused by fanquake)
  • #36000 (validation: prefetch blocks while connecting by l0rinc)
  • #35731 (Indexes: Harden the flush-error notification invariant by arejula27)
  • #35713 (Remove boost as a unit test runner by rustaceanrob)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #35003 (validation: improve block data I/O error handling in P2P paths by furszy)
  • #32387 (ipc: add windows support by ryanofsky)
  • #27260 (Enhanced error messages for invalid network prefix during address parsing. by portlandhodl)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants