From b9ffa67789d75cdc9dfef59446d4f894b1f137f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Tue, 27 Oct 2026 13:53:00 +0800 Subject: [PATCH 1/3] Own fixture identity and assertion includes in the canonical test header --- include/zeroerr/unittest.h | 8 +++++--- zeroerr.hpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/zeroerr/unittest.h b/include/zeroerr/unittest.h index 742f54b6..9c8f2d85 100644 --- a/include/zeroerr/unittest.h +++ b/include/zeroerr/unittest.h @@ -10,6 +10,7 @@ #include "zeroerr/internal/config.h" +#include "zeroerr/assert.h" #include "zeroerr/internal/time.h" #include @@ -52,9 +53,10 @@ ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH {__VA_ARGS__})); \ inline void classname::funcname(ZEROERR_UNUSED(zeroerr::TestContext* _ZEROERR_TEST_CONTEXT)) -#define TEST_CASE_FIXTURE(fixture, ...) \ - ZEROERR_EXPAND(ZEROERR_CREATE_TEST_CLASS(fixture, ZEROERR_NAMEGEN(_zeroerr_class), \ - ZEROERR_NAMEGEN(_zeroerr_test_method), __VA_ARGS__)) +#define TEST_CASE_FIXTURE(fixture, ...) \ + ZEROERR_EXPAND(ZEROERR_CREATE_TEST_CLASS(fixture, ZEROERR_NAMEGEN(ZEROERR_CAT(fixture, _zeroerr_class)), \ + ZEROERR_NAMEGEN(ZEROERR_CAT(fixture, _zeroerr_test_method)), \ + __VA_ARGS__)) #define ZEROERR_HAVE_SAME_OUTPUT _ZEROERR_TEST_CONTEXT->save_output(); diff --git a/zeroerr.hpp b/zeroerr.hpp index 94c1d30c..c83060d3 100644 --- a/zeroerr.hpp +++ b/zeroerr.hpp @@ -3292,6 +3292,7 @@ ZEROERR_SUPPRESS_COMMON_WARNINGS_POP + #include #include @@ -3332,9 +3333,10 @@ ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH {__VA_ARGS__})); \ inline void classname::funcname(ZEROERR_UNUSED(zeroerr::TestContext* _ZEROERR_TEST_CONTEXT)) -#define TEST_CASE_FIXTURE(fixture, ...) \ - ZEROERR_EXPAND(ZEROERR_CREATE_TEST_CLASS(fixture, ZEROERR_NAMEGEN(_zeroerr_class), \ - ZEROERR_NAMEGEN(_zeroerr_test_method), __VA_ARGS__)) +#define TEST_CASE_FIXTURE(fixture, ...) \ + ZEROERR_EXPAND(ZEROERR_CREATE_TEST_CLASS(fixture, ZEROERR_NAMEGEN(ZEROERR_CAT(fixture, _zeroerr_class)), \ + ZEROERR_NAMEGEN(ZEROERR_CAT(fixture, _zeroerr_test_method)), \ + __VA_ARGS__)) #define ZEROERR_HAVE_SAME_OUTPUT _ZEROERR_TEST_CONTEXT->save_output(); From 418ea6921163f9929e7243d70135a75b06513e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Tue, 27 Oct 2026 13:57:47 +0800 Subject: [PATCH 2/3] Cover cross-translation-unit fixture identity with LTO --- test/CMakeLists.txt | 2 ++ test/native_fixture_identity/CMakeLists.txt | 13 +++++++++++++ test/native_fixture_identity/first.cpp | 3 +++ test/native_fixture_identity/main.cpp | 2 ++ test/native_fixture_identity/second.cpp | 3 +++ 5 files changed, 23 insertions(+) create mode 100644 test/native_fixture_identity/CMakeLists.txt create mode 100644 test/native_fixture_identity/first.cpp create mode 100644 test/native_fixture_identity/main.cpp create mode 100644 test/native_fixture_identity/second.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6e3307c0..63513a99 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -106,3 +106,5 @@ foreach(order IN ITEMS zeroerr_first stl_first) endif() add_test(NAME PrintCapabilities_${order} COMMAND print_capabilities_${order}) endforeach() + +add_subdirectory(native_fixture_identity) diff --git a/test/native_fixture_identity/CMakeLists.txt b/test/native_fixture_identity/CMakeLists.txt new file mode 100644 index 00000000..04665dba --- /dev/null +++ b/test/native_fixture_identity/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.21) +project(NativeFixtureIdentity LANGUAGES C CXX) +include(CTest) +include(CheckIPOSupported) +check_ipo_supported(RESULT _ipo_supported) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${_ipo_supported}) +if(NOT TARGET zeroerr) + add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../.." zeroerr EXCLUDE_FROM_ALL) +endif() +target_compile_definitions(zeroerr PRIVATE ZEROERR_NO_MAIN) +add_executable(fixture_identity main.cpp first.cpp second.cpp) +target_link_libraries(fixture_identity PRIVATE zeroerr) +add_test(NAME fixture_identity COMMAND fixture_identity --no-color) diff --git a/test/native_fixture_identity/first.cpp b/test/native_fixture_identity/first.cpp new file mode 100644 index 00000000..61d7ca50 --- /dev/null +++ b/test/native_fixture_identity/first.cpp @@ -0,0 +1,3 @@ +#include +struct FirstFixture { int value = 17; }; +TEST_CASE_FIXTURE(FirstFixture, "native.fixture.first") { REQUIRE(value == 17); } diff --git a/test/native_fixture_identity/main.cpp b/test/native_fixture_identity/main.cpp new file mode 100644 index 00000000..bace1a57 --- /dev/null +++ b/test/native_fixture_identity/main.cpp @@ -0,0 +1,2 @@ +#include +int main(int argc, char** argv) { return zeroerr::UnitTest().parseArgs(argc, const_cast(argv)).run(); } diff --git a/test/native_fixture_identity/second.cpp b/test/native_fixture_identity/second.cpp new file mode 100644 index 00000000..45ed9ced --- /dev/null +++ b/test/native_fixture_identity/second.cpp @@ -0,0 +1,3 @@ +#include +struct SecondFixture { char padding[128] = {}; int value = 91; }; +TEST_CASE_FIXTURE(SecondFixture, "native.fixture.second") { REQUIRE(value == 91); } From 13cd2a97bc7f46644d87d38028b9ed36457060a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Tue, 27 Oct 2026 14:01:03 +0800 Subject: [PATCH 3/3] Preserve the parent suite's test main when embedding the fixture regression --- test/native_fixture_identity/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/native_fixture_identity/CMakeLists.txt b/test/native_fixture_identity/CMakeLists.txt index 04665dba..a5ea7c99 100644 --- a/test/native_fixture_identity/CMakeLists.txt +++ b/test/native_fixture_identity/CMakeLists.txt @@ -4,10 +4,12 @@ include(CTest) include(CheckIPOSupported) check_ipo_supported(RESULT _ipo_supported) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${_ipo_supported}) +set(_fixture_sources first.cpp second.cpp) if(NOT TARGET zeroerr) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../.." zeroerr EXCLUDE_FROM_ALL) + target_compile_definitions(zeroerr PRIVATE ZEROERR_NO_MAIN) + list(APPEND _fixture_sources main.cpp) endif() -target_compile_definitions(zeroerr PRIVATE ZEROERR_NO_MAIN) -add_executable(fixture_identity main.cpp first.cpp second.cpp) +add_executable(fixture_identity ${_fixture_sources}) target_link_libraries(fixture_identity PRIVATE zeroerr) add_test(NAME fixture_identity COMMAND fixture_identity --no-color)