Skip to content

test: GoogleTest harness — CMake, presets, support helpers, runner #43

Closed

Description

@homer6

Part of #41. The test harness the area suites build on. Do this first.

  • tests/CMakeLists.txt (top-level CMakeLists.txt at the repo root that adds tests/), C++26, GoogleTest v1.18.0 via FetchContent pinned to the tag, gtest_discover_tests.
  • CMakePresets.json with configure/build/test/workflow presets: gcc-15 (Homebrew g++-15), clang-22 (Homebrew /opt/homebrew/opt/llvm/bin/clang++, -stdlib=libc++), and a documented Docker recipe for GCC 16 (gcc:16 image) for C++26 tests.
  • Layout mirrors docs/examples/: tests/<area>/<page>_test.cpp; one CMake target per area (examples_containers_tests, …) so areas build independently, plus an all aggregate. A helper tests/support/ for capturing std::cout/std::print output into a string and a CPPDOCS_REQUIRE(__cpp_lib_x)-style skip macro (GTEST_SKIP with a reason).
  • tools/run_tests.sh [preset] runs the workflow preset; CLAUDE.md and README get a "Running the tests" section (local only; no CI).
  • One worked example per area folder (e.g. tests/containers/vector_test.cpp with 3–5 tests) so the area sub-issues have a pattern to copy.

Acceptance: cmake --workflow --preset gcc-15 and --preset clang-22 configure, build and pass; the Docker GCC 16 recipe runs; skips print their reason.

Activity

  1. self-assigned this
    on Oct 31, 2026
  2. homer6 commented on Oct 31, 2026

    @homer6
    OwnerAuthor

    Delivered in #52.

    What changed

    • CMakeLists.txt (root) and tests/CMakeLists.txt:
      • C++26, GoogleTest v1.18.0 from FetchContent pinned to the tag, and gtest_discover_tests.
      • One executable per area, examples_<area>_tests, built from the *_test.cpp files that exist, plus the examples_tests aggregate.
    • CMakePresets.json: configure, build, test and workflow presets for:
      • gcc-15 (g++-15).
      • clang-22 (Homebrew clang++ with -stdlib=libc++, linked against Homebrew's libc++ and libunwind with rpaths).
      • gcc-16 (run inside the gcc:16 Docker image).
    • tests/support/:
      • capture.hpp captures std::cout, printf and std::print in order. It redirects fd 1 and forwards cout's buffer into stdout.
      • feature.hpp provides CPPDOCS_REQUIRE / CPPDOCS_REQUIRE_VERSION, which skip with the missing macro and the version found.
      • Self-tests for both.
    • tools/run_tests.sh [preset] [ctest args]:
      • Runs the workflow preset and lists each skipped test with its reason.
      • For gcc-16 it runs inside Docker after apt-get install cmake ninja-build.
    • README.md and CLAUDE.md: "Running the tests" sections. .gitignore: build/ and out/.
    • 30 worked example files, one per docs/examples/ area folder and language/ subfolder, each with 2–5 tests on one page's claims.
    • Page fixes:
      • vector.md: std::bitset is C++98, not C++20.
      • futures.md: a broken promise throws std::future_error / future_errc::broken_promise.
      • comparison.md: a defaulted <=> does declare ==.
      • coroutines.md: take(10) resumes the generator an 11th time.

    Why

    • These cover every item in test: GoogleTest harness — CMake, presets, support helpers, runner #43: the CMake project, the presets, the per-area targets with an aggregate, the support helpers, the runner, the docs, and the worked examples.
    • Verified by running each workflow, with 127 tests per run:
      • cmake --workflow --preset gcc-15: 100% passed (GCC 15.2).
      • cmake --workflow --preset clang-22: 100% passed (Clang 22.1.8 with libc++).
      • tools/run_tests.sh gcc-16: 100% passed (Docker GCC 16.2, CMake 3.31.6).
    • Skips print their reason. Examples: needs __cpp_lib_generator (not defined by this toolchain), and needs __cpp_lib_optional >= 202506L (this toolchain has 202110L).
    • The snippet checker baseline is still clean after the page fixes.

    Still open

  3. homer6 commented on Oct 31, 2026

    @homer6
    OwnerAuthor

    Merged in #52 (3b3f168) on the owner's review.

    What changed

    Why

    • Approved by the owner after review and re-review.

    Still open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions