From fd090b0d95995e11022f1b6621c3e86e9d3d583f Mon Sep 17 00:00:00 2001 From: Nana Sakisaka <1901813+saki7@users.noreply.github.com> Date: Sun, 4 Oct 2026 08:48:42 +0900 Subject: [PATCH] Enable PCH for tests --- test/CMakeLists.txt | 7 +++++ test/pch.cpp | 0 test/pch.hpp | 39 ++++++++++++++++++++++++++++ test/unicode/string/utf8_invalid.cpp | 12 ++++++--- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 test/pch.cpp create mode 100644 test/pch.hpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4163f4..1eda386 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -159,9 +159,16 @@ if(MSVC) target_sources(_iris_internal_test_base INTERFACE "${CMAKE_CURRENT_LIST_DIR}/cpp.hint") endif() +# Must be an executable so that its compile flags (e.g. -fPIE) match the tests +add_executable(_iris_internal_test_pch ${CMAKE_CURRENT_LIST_DIR}/pch.cpp) +target_link_libraries(_iris_internal_test_pch PRIVATE Iris::Iris iris_cxx_test Catch2::Catch2WithMain _iris_internal_test_base) +target_precompile_headers(_iris_internal_test_pch PRIVATE ${CMAKE_CURRENT_LIST_DIR}/pch.hpp) +set_target_properties(_iris_internal_test_pch PROPERTIES CXX_EXTENSIONS OFF FOLDER "test") + function(iris_define_internal_test test_name) iris_define_test(iris_${test_name} ${ARGN}) target_link_libraries(iris_${test_name}_test PRIVATE _iris_internal_test_base) + target_precompile_headers(iris_${test_name}_test REUSE_FROM _iris_internal_test_pch) target_sources(iris_${test_name}_test PRIVATE FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_FUNCTION_LIST_DIR} FILES ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/iris_test.hpp) set_target_properties(iris_${test_name}_test PROPERTIES FOLDER "test/iris") endfunction() diff --git a/test/pch.cpp b/test/pch.cpp new file mode 100644 index 0000000..e69de29 diff --git a/test/pch.hpp b/test/pch.hpp new file mode 100644 index 0000000..9d1682f --- /dev/null +++ b/test/pch.hpp @@ -0,0 +1,39 @@ +#ifndef IRIS_ZZ_TEST_PCH_HPP +#define IRIS_ZZ_TEST_PCH_HPP + +// SPDX-License-Identifier: MIT + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#endif diff --git a/test/unicode/string/utf8_invalid.cpp b/test/unicode/string/utf8_invalid.cpp index b7f46b7..e740e6d 100644 --- a/test/unicode/string/utf8_invalid.cpp +++ b/test/unicode/string/utf8_invalid.cpp @@ -1,6 +1,3 @@ -// TODO: we need secure "getenv" in iris library -#define _CRT_SECURE_NO_WARNINGS 1 - #include "iris_test.hpp" #include @@ -29,11 +26,18 @@ TEST_CASE("utf8_invalid") namespace unicode = iris::unicode; using iris::throwf; +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4996) +#endif std::filesystem::path const IRIS_ROOT = [] { - char const* IRIS_ROOT_str = std::getenv("IRIS_ROOT"); + char const* IRIS_ROOT_str = std::getenv("IRIS_ROOT"); // NOLINT(concurrency-mt-unsafe) if (!IRIS_ROOT_str) throwf("IRIS_ROOT is not defined"); return std::filesystem::path(IRIS_ROOT_str); }(); +#ifdef _MSC_VER +# pragma warning(pop) +#endif auto const test_file_path = IRIS_ROOT / "test" / "unicode" / "string" / "test_data" / "utf8_invalid.txt"; std::ifstream fs8(test_file_path);