From 1619dbb89f5759afa80ae521df812b20ac4c6fe8 Mon Sep 17 00:00:00 2001 From: Giovanni Marzot Date: Mon, 10 Aug 2026 18:11:18 -0400 Subject: [PATCH] test: discover gtest tests at ctest startup, not POST_BUILD CMake 4.4.0's generated discovery scripts omit TEST_TARGET, so every target's POST_BUILD discovery shares one JSON file (cmake_test_discovery_e3b0c44298.json, sha256 of the empty string). Ninja links test binaries in parallel and their discovery steps race on that file: one truncates it while another parses, producing the intermittent macOS failure ParseTestList.cmake:96: string sub-command JSON failed parsing json string ... Line 1, Column 1: Syntax error Fixed upstream in cmake 4.4.1, but Homebrew CI runners ship 4.4.0. PRE_TEST discovery runs serially at ctest startup, immune to the race on any cmake version. Measured cost: 0.8s to enumerate all 772 tests, cached thereafter (0.12s); build step drops its ~28 post-link discovery executions. --- test/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2494305a..da411c99 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,11 @@ find_package(GTest REQUIRED CONFIG) include(GoogleTest) +# Discover tests at ctest startup (serial) instead of POST_BUILD (parallel). +# Parallel POST_BUILD discovery races on a shared JSON file under cmake 4.4.0, +# intermittently failing macOS builds with "JSON failed parsing". +set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST) + add_library(moqx_test_utils STATIC TestUtils.cpp )