ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
Testing with Catch2 v3

ascii-chat uses Catch2 v3 for native unit, contract, integration, and benchmark tests on Windows, Linux, and macOS. The authoritative build and test targets are in tests/CMakeLists.txt and CMakePresets.json.

Building and selecting tests

Configure the test preset, build it, and let CTest schedule discovered cases. CTest is the parallel scheduler; Catch2 cases are not run in parallel inside one process.

cmake --preset tests
cmake --build --preset tests
ctest --preset all --output-on-failure --parallel 0
ctest --preset unit
ctest --preset integration
ctest --preset benchmarks

The benchmarks CTest group selects native timing sources in tests/benchmarks/. They use Catch2 BENCHMARK or BENCHMARK_ADVANCED, are tagged [benchmark], and run serially in CI.

Writing Catch2 tests

Native test files are C++ and use TEST_CASE with hierarchical tags.

TEST_CASE("parser/rejects_truncated_header", "[parser][negative]") {
SECTION("missing length") {
REQUIRE(parse_header(bytes, 2) == ERROR_BUFFER_UNDERFLOW);
}
}

Prefer SECTION for branches sharing setup, REQUIRE for fatal preconditions, CHECK for collecting failures, and Catch2 matchers for readable string/container assertions. Use INFO and CAPTURE for diagnostics. Catch2 generators replace Catch2 theories:

auto size = GENERATE(1u, 16u, 256u, 4096u);
CAPTURE(size);
REQUIRE(round_trip(size));

Use GENERATE_COPY for mutable captured state. Keep generated values deterministic and independent; never leave a declared data table unused. Use RAII helpers or TEST_CASE_METHOD for fixtures, not uncalled setup or teardown functions. Assertions stay on the Catch2 test thread: worker callbacks record a result and the owning test asserts it after joining.

Tags and groups

Tags identify subsystem, capability, and cost, such as [Crypto Module], [Network Module], [integration], [contract], [slow], [requires-network], and [benchmark]. Select them with Catch2 expressions such as unit_tests "[Crypto Module]~[slow]"; use CTest labels for CI groups.

Output, coverage, and CI

Catch2 discovery requests JUnit XML from every native Catch2 executable in build/Testing/xml/. CTest also writes its own JUnit result file. CI validates the Catch2 files, uploads them as artifacts, and passes the same files to Codecov. Coverage builds instrument production targets and Catch2 executables; the coverage workflow combines gcov/LLVM data before uploading it. XML is diagnostic evidence and does not replace CTest's pass/fail result.

Standalone and external-boundary tests

New native assertions must not be standalone C programs. Convert them to Catch2 and register them through CMake so they receive tags, discovery, JUnit output, CTest parallelization, and coverage. A small executable may remain only as an external-process fixture, PTY/console probe, or platform boundary that Catch2 cannot own; tests/standalone/README.md documents each exception. Python tests remain pytest tests and may launch subprocesses.

Troubleshooting

List tests with unit_tests --list-tests and inspect CTest with ctest -N. Run a focused case with a Catch2 expression and write XML with --reporter junit --out path.xml. Catch2 filters and XML directories are integrated with CTest discovery.