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/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..a5ea7c99 --- /dev/null +++ b/test/native_fixture_identity/CMakeLists.txt @@ -0,0 +1,15 @@ +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}) +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() +add_executable(fixture_identity ${_fixture_sources}) +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); } 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();