Add craft test command modeled on cargo test#34
Open
DaanyaalSobani wants to merge 1 commit into
Open
Conversation
Discovers .c/.cpp files in a project's tests/ directory and treats each one as an independent test binary, matching cargo's integration test model (one binary per file). `craft test` builds via the same flow as `craft build`, runs each test binary, and reports per-binary pass/fail with an aggregate summary. Test targets are emitted in the generated CMakeLists.txt inside an `if(EXISTS tests)` block, so `craft build` also picks them up when tests are present. For library project types each test target is linked against the project library automatically; executable projects skip the link step. Options: craft test <name> filter tests by substring craft test --no-run build the test binaries but do not run them Implements the proposal in randerson112#33. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.
Implements the proposal in #33.
What
Adds a
craft testcommand that discovers.c/.cppfiles in a project'stests/directory and treats each one as an independent test binary — the cargo integration test model (one binary per file).craft test:craft build(test targets are emitted in the generatedCMakeLists.txtwhentests/exists, socraft buildalso picks them up).Example
Options
craft test <name>— substring filter (cargo-style)craft test --no-run— build test binaries without running themImplementation
include/test.h,src/test.chandle_build(), find each test binary across known multi-config layouts (build/,build/Debug/,build/Release/,build/MinSizeRel/,build/RelWithDebInfo/), report resultssrc/cmake.cwrite_tests()— emits anif(EXISTS tests/)block withfile(GLOB ... CONFIGURE_DEPENDS). Library project types auto-link against the project library; executable projects do notsrc/parser.c+include/parser.htestcommand +--no-runoptionsrc/dispatcher.ctesttohandle_testsrc/help.ccraft help test+ entry in main helpLibrary vs. executable projects
static-library,shared-library,header-only): test files are auto-linked against the project library — write tests in terms of the project's public headers.Trying it out
If you'd like to poke at this end-to-end without setting anything up yourself, I built a small public playground:
DaanyaalSobani/craft-playground — has a
math/static-library project with three passing tests and a repeatable bash harness atscripts/test_craft_test.shthat exercises six scenarios (22 checks total: all-passing, filter,--no-run, known-failing test, missingtests/, no-match filter). Points at this branch'scraft.exeby default; override via theCRAFTenv var.Scope
Deliberately matches cargo's integration test model only. Per-function
#[test]-style granularity (one file, many independently-reported tests) is called out as a future direction in #33 — happy to layer that on later via either a small bundled framework or a[test]section incraft.tomlif you'd prefer.Testing
Tested on Windows 11 / MSVC 19.42 / CMake 4.3.2 against the playground harness — 22/22 checks pass.