Skip to content

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

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

scripted-diff: [test] replace assert with Assert#36074
maflcko wants to merge 4 commits into
bitcoin:masterfrom
maflcko:2608-test-assert

Conversation

@maflcko

@maflcko maflcko commented Aug 25, 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 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.

@DrahtBot DrahtBot changed the title scripted-diff: [test] replace assert with Assert scripted-diff: [test] replace assert with Assert Aug 25, 2026
@DrahtBot

DrahtBot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

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

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:

  • #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)
  • #35646 (RFC: Separate out runtime errors from BlockValidationState using util::Expected by yuvicc)
  • #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)
  • #35377 (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101)
  • #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)

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:

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

2026-08-26 11:29:19

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task i686, no IPC: https://github.com/bitcoin/bitcoin/actions/runs/32832295932/job/97753466551
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.”

Hints

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.

@maflcko
maflcko marked this pull request as draft August 25, 2026 12:08
@maflcko

maflcko commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

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

MarcoFalke added 4 commits August 26, 2026 13:27
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-
This can be reproduced by checking out the previous commit and running:
git show -U0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
-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-
Assert(!mini_miner.IsReadyToCalculate());
}
// Overlapping ancestry across multiple outpoints can only reduce the total bump fee.
assert (sum_fees >= *total_bumpfee);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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*\(?

Comment on lines +161 to +164
"src/test/",
"src/bench/",
"src/wallet/test/",
"src/qt/test/",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This was referenced Aug 27, 2026
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.

3 participants