Unit tests with doctest #5

Closed
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:48 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

Every later issue says "tests first where it fits". That needs a test executable on both build systems before the first engine change.

Decided

  • doctest, one header, downloaded and pinned (same version and SHA-256 in CMake and in a DownloadDoctest target of UnitTests.vcxproj).
  • One executable, UnitTests, with one .cpp per area. It needs no window and no GPU. CTest runs it.
  • The engine's global systems keep their state between test cases: a test doesn't rely on particular ids or on empty systems, and removes what it creates.
  • Tests use CHECK, not the engine's assert (off in Release).
  • Benchmarks are test cases named benchmark: ... and marked doctest::skip(). No commas in test names (-tc splits on them).
  • Test data goes in UnitTests/Data/ (PRIMAL_TEST_DATA_DIR).

Read first

  • CLAUDE, "Automated tests" (the fork's working notes).
  • UnflavoredMeson/Primal#21 (the original ticket and what it covered).

Steps

  • 1. Add the doctest download to both build systems.
  • 2. Create UnitTests/ with Main.cpp and a first test file for utl::vector (Engine/Utilities/Vector.h). Write a test for erase() that you expect to pass, then one for a case you're not sure about.
  • 3. Add tests for Id.h and IOStream.h (blob reader/writer round trips).
  • 4. Register the executable with CTest and run it both ways.

Done when

  • x64/Debug/UnitTests and ctest --test-dir build/linux-debug pass on Linux; UnitTests.exe passes on Windows.
  • A deliberately broken assertion fails the run with a non-zero exit code.

Claude can help with

  • Suggesting edge cases for a test you've started (empty containers, the last element, ids at their limits).
  • Setting up the MSBuild download target.

Learn

  • Why tests of global engine systems must clean up after themselves.
  • doctest's SUBCASE and how it reruns the enclosing test case.
## Why Every later issue says "tests first where it fits". That needs a test executable on both build systems before the first engine change. ## Decided - doctest, one header, downloaded and pinned (same version and SHA-256 in CMake and in a `DownloadDoctest` target of `UnitTests.vcxproj`). - One executable, `UnitTests`, with one `.cpp` per area. It needs no window and no GPU. CTest runs it. - The engine's global systems keep their state between test cases: a test doesn't rely on particular ids or on empty systems, and removes what it creates. - Tests use `CHECK`, not the engine's `assert` (off in Release). - Benchmarks are test cases named `benchmark: ...` and marked `doctest::skip()`. No commas in test names (`-tc` splits on them). - Test data goes in `UnitTests/Data/` (`PRIMAL_TEST_DATA_DIR`). ## Read first - [CLAUDE](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/CLAUDE), "Automated tests" (the fork's working notes). - `UnflavoredMeson/Primal#21` (the original ticket and what it covered). ## Steps - [x] 1. Add the doctest download to both build systems. - [x] 2. Create `UnitTests/` with `Main.cpp` and a first test file for `utl::vector` (`Engine/Utilities/Vector.h`). Write a test for `erase()` that you expect to pass, then one for a case you're not sure about. - [x] 3. Add tests for `Id.h` and `IOStream.h` (blob reader/writer round trips). - [x] 4. Register the executable with CTest and run it both ways. ## Done when - [x] `x64/Debug/UnitTests` and `ctest --test-dir build/linux-debug` pass on Linux; `UnitTests.exe` passes on Windows. - [x] A deliberately broken assertion fails the run with a non-zero exit code. ## Claude can help with - Suggesting edge cases for a test you've started (empty containers, the last element, ids at their limits). - Setting up the MSBuild download target. ## Learn - Why tests of global engine systems must clean up after themselves. - doctest's `SUBCASE` and how it reruns the enclosing test case.
Sign in to join this conversation.
No assignees
No project
No milestone
Blocks
#6 Logging through primal::log
UnflavoredMeson/Primal_Plus_Plus
#7 CI on Forgejo Actions for Linux and Windows
UnflavoredMeson/Primal_Plus_Plus
#11 The engine as one shared library
UnflavoredMeson/Primal_Plus_Plus
#14 utl::free_list with stable storage
UnflavoredMeson/Primal_Plus_Plus
#21 Reflection generator PrimalReflectGen
UnflavoredMeson/Primal_Plus_Plus
Depends on
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
UnflavoredMeson/Primal_Plus_Plus#5
No description provided.