commit 2d4b028d02c1255c1f21a8f1c50851626e867761
parent c81af9428c08d21d6e7ddc7ce7ac1761e9a20b9e
Author: bfredl <bjorn.linse@gmail.com>
Date: Thu, 22 May 2025 11:22:29 +0200
fix(tests): use correct include path for unittest
Copy whatever was made to work for generated headers:
(1) we need to consider all cmake targets not just main_lib
(2) we need to add the sysroot for macOS
Diffstat:
6 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/build.zig b/build.zig
@@ -408,6 +408,7 @@ pub fn test_config(b: *std.Build, gen_dir: LazyPath) ![]u8 {
\\local M = {{}}
\\
\\M.include_paths = {{}}
+ \\M.apple_sysroot = ""
\\M.translations_enabled = "$ENABLE_TRANSLATIONS" == "ON"
\\M.is_asan = "$ENABLE_ASAN_UBSAN" == "ON"
\\M.is_zig_build = true
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
@@ -481,11 +481,13 @@ foreach(target ${targets})
message(STATUS "${target} props '${prop}'")
foreach(gen_include ${prop})
list(APPEND gen_cflags "-I${gen_include}")
+ list(APPEND TEST_INCLUDE_DIRS "${gen_include}")
endforeach()
endif()
endforeach()
list(REMOVE_DUPLICATES gen_cflags)
+list(REMOVE_DUPLICATES TEST_INCLUDE_DIRS)
if(APPLE AND CMAKE_OSX_SYSROOT)
list(APPEND gen_cflags "-isysroot" "${CMAKE_OSX_SYSROOT}")
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
@@ -1,6 +1,6 @@
add_subdirectory(functional/fixtures) # compile test programs
-get_target_property(TEST_INCLUDE_DIRS main_lib INTERFACE_INCLUDE_DIRECTORIES)
+get_directory_property(TEST_INCLUDE_DIRS DIRECTORY ${PROJECT_SOURCE_DIR}/src/nvim DEFINITION TEST_INCLUDE_DIRS)
set(TEST_OPTIONS
-D BUILD_DIR=${CMAKE_BINARY_DIR}
diff --git a/test/cmakeconfig/paths.lua.in b/test/cmakeconfig/paths.lua.in
@@ -4,6 +4,7 @@ M.include_paths = {}
for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do
table.insert(M.include_paths, p)
end
+M.apple_sysroot = "${CMAKE_OSX_SYSROOT}"
M.translations_enabled = "${ENABLE_TRANSLATIONS}" == "ON"
M.is_asan = "${ENABLE_ASAN_UBSAN}" == "ON"
diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua
@@ -146,13 +146,20 @@ end
--- @param ... string
function Gcc:add_to_include_path(...)
+ local ef = self.preprocessor_extra_flags
for i = 1, select('#', ...) do
local path = select(i, ...)
- local ef = self.preprocessor_extra_flags
ef[#ef + 1] = '-I' .. path
end
end
+function Gcc:add_apple_sysroot(sysroot)
+ local ef = self.preprocessor_extra_flags
+
+ table.insert(ef, '-isysroot')
+ table.insert(ef, sysroot)
+end
+
-- returns a list of the headers files upon which this file relies
--- @param hdr string
--- @return string[]?
@@ -278,4 +285,9 @@ function M.add_to_include_path(...)
return cc:add_to_include_path(...)
end
+--- @param ... string
+function M.add_apple_sysroot(...)
+ return cc:add_apple_sysroot(...)
+end
+
return M
diff --git a/test/unit/testutil.lua b/test/unit/testutil.lua
@@ -19,6 +19,11 @@ for _, p in ipairs(paths.include_paths) do
Preprocess.add_to_include_path(p)
end
+-- add some nonstandard header locations
+if paths.apple_sysroot ~= '' then
+ Preprocess.add_apple_sysroot(paths.apple_sysroot)
+end
+
local child_pid = nil --- @type integer?
--- @generic F: function
--- @param func F