Repository navigation
CMake: an executable built from test sources holds C and C++ tests - #524
Merged
lefticus merged 6 commits intoDec 2, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #524 +/- ##
==========================================
+ Coverage 99.44% 99.46% +0.01%
==========================================
Files 374 378 +4
Lines 27339 27991 +652
Branches 3440 3563 +123
==========================================
+ Hits 27188 27840 +652
Misses 151 151 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leftibot
force-pushed
the
cmake-test-executables
branch
2 times, most recently
from
December 1, 2026 19:49
b7cc106 to
9913f8c
Compare
…make check tests
Autotools projects (jq, tmux, curl, libzmq) had no C build system, so their
warning flags and `make check` tests were missed, and every make command CI
ran was unknown ("the makefile: none is found where make runs"): configure
writes the makefile, so it is not in the checkout.
- configure.ac is evaluated without running m4 or the shell
(build_systems/autotools/configure_syntax.py, configure.py): macro calls
and shell statements, `if`/`case` branches, AS_IF, AS_CASE, AC_ARG_ENABLE,
AC_ARG_WITH, the flag macros (AX_CHECK_COMPILE_FLAG, AX_APPEND_COMPILE_FLAGS,
AX_APPEND_FLAG, gl_WARN_ADD) where the compiler accepts the flag, macros
the file defines, AC_SUBST and AM_CONDITIONAL. `test "x$GCC" = xyes` is
the GCC-like compilers; any other test is a requirement as written.
tmux's LTO probe, which sets -Werror for one compile check and restores
CFLAGS, leaves no -Werror.
- Each Makefile.am is read with the configure.ac above it (automake.py):
AM_CFLAGS, AM_CXXFLAGS, AM_CPPFLAGS and each built target's own flags,
through Automake conditionals, with configure's substitutions expanded.
- Autotools (Makefile.am) is a build system of C and C++; `make check`,
`distcheck` or `recheck` where a Makefile.am is (or in a build tree
outside the checkout) runs the tests TESTS and check_PROGRAMS name.
- Where no makefile is in the checkout but a Makefile.am is, make reads the
Makefile.am's rules, and Automake's own targets (policy/automake.toml) are
known, not unknown.
Part of cpp-best-practices#470
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…ctices#470) Brackets around a shell test (an m4 quote, stripped), several assignments on a line, a case pattern on a line of its own, AS_IF and AS_CASE without their last branch, AC_SUBST with a value, unquoted arguments holding parentheses, a body-less AC_DEFUN, a stray else or fi, an assignment no build reaches, a configure.ac past the bound on conditions, and a Makefile.am variable set only where it is not used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
) Like configure.ac's most_defined_calls, how deep a Makefile.am reference is followed is a limit, not a constant in the code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…ystem (cpp-best-practices#470) The maintainer asked that the message read the same for every build system: "warnings are not treated as errors in CI configuration or the build files", rather than listing CMake files, presets and meson.build (leaving out configure.ac), or fpm's flags for Fortran. The hints, which say how in each build system, are unchanged, as is CMake's own presets finding. test_warnings_as_errors' SEARCHED and the bare_c, bare_cpp, bare_fortran and buildable snapshots change to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
leftibot
force-pushed
the
cmake-test-executables
branch
from
December 1, 2026 22:22
9913f8c to
ac3ccb5
Compare
…pp-best-practices#470) Conditions are kept for the whole process, so a second reading of the same configure.ac builds no new nodes and never reaches the lowered bound. mutmut runs the suite more than once in one process, so the test failed in its clean run on cpp-best-practices#532 and cpp-best-practices#533. Each reading now gets names of its own, and the test reads twice to hold that in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
pybind11 defines its C++ tests only as executables of tests/ that custom targets run (`add_custom_target(cpptest COMMAND $<TARGET_FILE:test_with_catch>)`), and CI builds the targets; luanti builds its unit tests into the engine and CI runs `./bin/luanti --run-unittests`. CMake's add_executable and target_sources are now read: an executable with a source in a test directory, or named as a test (`test_ban.cpp`), is a test executable, unless CTest's tests already run it. A run of one, by a custom target's command or by CI naming the built file, runs its tests; one built with the product's sources too runs them only when an option asks for them (policy/tests.toml). Part of cpp-best-practices#482. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
leftibot
force-pushed
the
cmake-test-executables
branch
from
December 2, 2026 01:51
ac3ccb5 to
f2b3ae7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #522 — merge after it; until then this diff includes its commits. (#522 is stacked on #517 → #515 → #512.)
Part of #482: the pybind11 and luanti rows.
What changes
pybind11 defines its C++ tests only as executables in
tests/. Custom targets run them (add_custom_target(cpptest COMMAND "$<TARGET_FILE:test_with_catch>"), andcheck, which depends ontest_pure_cpp), and CI builds those targets. luanti builds its unit tests into the engine, and CI runs./bin/luanti --run-unittests. Before this PR, neither was a C/C++ test definition, so tests-run said "no tests found".The CMake reader now reads
add_executableandtarget_sources. A test executable is an executable with at least one test source: a source in a test directory, or a source whose name says it is a test (test.cpp,test_ban.cpp,parser_test.cc,ParserTests.cpp). It is recorded as aSetting(toolCMake, keytest executable) with whether every source is a test source. Two cases are skipped:add_test's command or a*_discover_teststarget) once CTest is enabled, because it is already CTest's definition;There is a new test runner, a test executable (
build_systems/cmake/ctest.py), for the CMake languages. It counts as a run in two cases:$<TARGET_FILE:name>or as the bare target name (CMake replaces that with the built file);./bin/luanti,bin\Release\luanti.exe), not a bare program name found on the PATH.An executable built only from test sources counts whatever arguments it gets. One built together with the product's sources counts only when an option asks for its tests. Its definitions count for every unit when they are in a unit of tests (pybind11's
tests/is a CMake project of its own).New policy table
policy/tests.toml([test_executables] option_words = ["test"]), added toTABLESinpolicy_tables.py, with a table test.Corpus, before → after (score, tests-run)
tests/executables are test executables, and CI doesn't run them)cJSON, CLI11, expected, Catch2, cmake_template, doctest, fmt, spdlog, llama.cpp and abseil: unchanged.
Existing tests and snapshots changed
tests/checks/test_tests_run.py: the "no tests found" and "no CI configuration runs …" wordings now list the new runner (NO_C_TESTS, newNOT_RUN_C).bare_c,bare_cpp,bare_fortran,buildable,registry,well_configured_c,well_configured_cpp,well_configured_fortran(.jsononly; their executables are CTest's, so no facts change).For the maintainer
tests/programs are mostly interactive test programs. They now count as tests that CI doesn't run (WARN), where before there were none (FAIL). The rule is the test role's: a source in a test directory is a test source.--run-unittests) applies only to executables built with product sources too.Coverage
codecov/patch was 98.86%. All of the missed lines were #522's, and they are fixed there. This PR's own lines were already covered. Patch coverage locally: 64/64 for this PR's own diff, 803/803 for the stack against main.
🤖 Generated with Claude Code
https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt