aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.github/workflows/env.sh1
-rw-r--r--CMakeLists.txt8
-rw-r--r--ci/common/build.sh10
-rw-r--r--cmake/RunTests.cmake10
-rwxr-xr-xsrc/nvim/CMakeLists.txt31
-rw-r--r--src/nvim/tui/input.c16
-rw-r--r--src/nvim/tui/input.h8
-rw-r--r--test/busted_runner.lua1
-rw-r--r--test/cmakeconfig/paths.lua.in1
-rw-r--r--test/functional/core/startup_spec.lua7
-rw-r--r--test/unit/helpers.lua5
-rw-r--r--test/unit/tui_spec.lua2
12 files changed, 35 insertions, 65 deletions
diff --git a/.github/workflows/env.sh b/.github/workflows/env.sh
index 2c3fbf9ef2..42a355da44 100755
--- a/.github/workflows/env.sh
+++ b/.github/workflows/env.sh
@@ -26,7 +26,6 @@ BUILD_FLAGS="CMAKE_FLAGS=-DCI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_
case "$FLAVOR" in
asan)
- BUILD_FLAGS="$BUILD_FLAGS -DPREFER_LUA=ON"
cat <<EOF >> "$GITHUB_ENV"
CLANG_SANITIZER=ASAN_UBSAN
ASAN_OPTIONS=detect_leaks=1:check_initialization_order=1:log_path=$GITHUB_WORKSPACE/build/log/asan:intercept_tls_get_addr=0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 095750328a..5ca1e2caa7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -370,7 +370,7 @@ endif()
if(BUSTED_PRG)
get_target_property(TEST_INCLUDE_DIRS main_lib INTERFACE_INCLUDE_DIRECTORIES)
- set(UNITTEST_PREREQS nvim-test)
+ set(UNITTEST_PREREQS nvim)
set(FUNCTIONALTEST_PREREQS nvim printenv-test printargs-test shell-test pwsh-test streams-test tty-test ${GENERATED_HELP_TAGS})
set(BENCHMARK_PREREQS nvim tty-test)
@@ -380,6 +380,7 @@ if(BUSTED_PRG)
COMMAND ${CMAKE_COMMAND}
-DBUSTED_PRG=${BUSTED_PRG}
-DLUA_PRG=${LUA_PRG}
+ -DNVIM_PRG=$<TARGET_FILE:nvim>
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
@@ -394,11 +395,6 @@ if(BUSTED_PRG)
message(WARNING "disabling unit tests: no Luajit FFI in ${LUA_PRG}")
endif()
- if(LUA_HAS_FFI)
- set(TEST_LIBNVIM_PATH $<TARGET_FILE:nvim-test>)
- else()
- set(TEST_LIBNVIM_PATH "")
- endif()
configure_file(
${CMAKE_SOURCE_DIR}/test/cmakeconfig/paths.lua.in
${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua.gen)
diff --git a/ci/common/build.sh b/ci/common/build.sh
index e30d0337b5..95972aab13 100644
--- a/ci/common/build.sh
+++ b/ci/common/build.sh
@@ -16,8 +16,7 @@ build_make() {
}
build_deps() {
- if test "${FUNCTIONALTEST}" = "functionaltest-lua" \
- || test "${CLANG_SANITIZER}" = "ASAN_UBSAN" ; then
+ if test "${FUNCTIONALTEST}" = "functionaltest-lua" ; then
DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON"
fi
@@ -66,13 +65,6 @@ build_nvim() {
if ! top_make libnvim ; then
exit 1
fi
-
- if test "${FUNCTIONALTEST}" != "functionaltest-lua"; then
- echo "Building nvim-test."
- if ! top_make nvim-test ; then
- exit 1
- fi
- fi
fi
# Invoke nvim to trigger *San early.
diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake
index c3ac5f208e..d724f43a5f 100644
--- a/cmake/RunTests.cmake
+++ b/cmake/RunTests.cmake
@@ -71,8 +71,16 @@ if(NOT DEFINED ENV{TEST_TIMEOUT} OR "$ENV{TEST_TIMEOUT}" STREQUAL "")
endif()
set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua.
+
+# TODO: eventually always use NVIM_PRG as the runner
+if("${TEST_TYPE}" STREQUAL "unit")
+ set(RUNNER_PRG ${NVIM_PRG} -ll ${WORKING_DIR}/test/busted_runner.lua)
+else()
+ set(RUNNER_PRG ${BUSTED_PRG})
+endif()
+
execute_process(
- COMMAND ${BUSTED_PRG} -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
+ COMMAND ${RUNNER_PRG} -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua
--lpath=${WORKING_DIR}/runtime/lua/?.lua
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 77ed0490d8..7b56af59da 100755
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -52,7 +52,7 @@ if(PREFER_LUA)
find_package(Lua 5.1 EXACT REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUA_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LUA_LIBRARIES})
- # Passive (not REQUIRED): if LUAJIT_FOUND is not set, nvim-test is skipped.
+ # Passive (not REQUIRED): if LUAJIT_FOUND is not set, fixtures for unittests is skipped.
find_package(LuaJit)
else()
find_package(LuaJit REQUIRED)
@@ -679,6 +679,14 @@ if(UNIX)
endif()
endif()
+if(NOT LUAJIT_FOUND)
+ message(STATUS "luajit not found, skipping unit tests")
+elseif(CMAKE_BUILD_TYPE MATCHES Debug)
+ glob_wrapper(UNIT_TEST_FIXTURES ${PROJECT_SOURCE_DIR}/test/unit/fixtures/*.c)
+ list(APPEND NVIM_SOURCES ${UNIT_TEST_FIXTURES})
+ target_compile_definitions(main_lib INTERFACE UNIT_TESTING)
+endif()
+
target_sources(nvim PRIVATE ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS}
${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS})
@@ -837,27 +845,6 @@ set_target_properties(
target_compile_definitions(libnvim PRIVATE MAKE_LIB)
target_link_libraries(libnvim PRIVATE main_lib PUBLIC libuv_lib)
-if(NOT LUAJIT_FOUND)
- message(STATUS "luajit not found, skipping nvim-test (unit tests) target")
-else()
- glob_wrapper(UNIT_TEST_FIXTURES ${PROJECT_SOURCE_DIR}/test/unit/fixtures/*.c)
- add_library(
- nvim-test
- MODULE
- EXCLUDE_FROM_ALL
- ${NVIM_SOURCES} ${NVIM_GENERATED_SOURCES}
- ${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
- ${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS}
- ${UNIT_TEST_FIXTURES}
- )
- target_link_libraries(nvim-test PRIVATE ${LUAJIT_LIBRARIES} main_lib PUBLIC libuv_lib)
- if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
- target_link_libraries(nvim-test PRIVATE "-framework CoreServices")
- endif()
- target_include_directories(nvim-test PRIVATE ${LUAJIT_INCLUDE_DIRS})
- target_compile_definitions(nvim-test PRIVATE UNIT_TESTING)
-endif()
-
if(CLANG_ASAN_UBSAN)
message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
if(CI_BUILD)
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 2cb39ab26b..733aa25f03 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -117,14 +117,6 @@ static const struct kitty_key_map_entry {
static Map(KittyKey, cstr_t) kitty_key_map = MAP_INIT;
-#ifndef UNIT_TESTING
-typedef enum {
- kIncomplete = -1,
- kNotApplicable = 0,
- kComplete = 1,
-} HandleState;
-#endif
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/input.c.generated.h"
#endif
@@ -584,7 +576,7 @@ static void set_bg(char *bgvalue)
// ignored in the calculations.
//
// [1] https://en.wikipedia.org/wiki/Luma_%28video%29
-static HandleState handle_background_color(TermInput *input)
+HandleState handle_background_color(TermInput *input)
{
if (input->waiting_for_bg_response <= 0) {
return kNotApplicable;
@@ -669,12 +661,6 @@ static HandleState handle_background_color(TermInput *input)
}
return kComplete;
}
-#ifdef UNIT_TESTING
-HandleState ut_handle_background_color(TermInput *input)
-{
- return handle_background_color(input);
-}
-#endif
static void handle_raw_buffer(TermInput *input, bool force)
{
diff --git a/src/nvim/tui/input.h b/src/nvim/tui/input.h
index 5df108b107..d33cea6383 100644
--- a/src/nvim/tui/input.h
+++ b/src/nvim/tui/input.h
@@ -40,18 +40,14 @@ typedef struct term_input {
TUIData *tui_data;
} TermInput;
-#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "tui/input.h.generated.h"
-#endif
-
-#ifdef UNIT_TESTING
typedef enum {
kIncomplete = -1,
kNotApplicable = 0,
kComplete = 1,
} HandleState;
-HandleState ut_handle_background_color(TermInput *input);
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "tui/input.h.generated.h"
#endif
#endif // NVIM_TUI_INPUT_H
diff --git a/test/busted_runner.lua b/test/busted_runner.lua
new file mode 100644
index 0000000000..b195ce3cc5
--- /dev/null
+++ b/test/busted_runner.lua
@@ -0,0 +1 @@
+require 'busted.runner'({ standalone = false })
diff --git a/test/cmakeconfig/paths.lua.in b/test/cmakeconfig/paths.lua.in
index 6be238d838..a35dbe8901 100644
--- a/test/cmakeconfig/paths.lua.in
+++ b/test/cmakeconfig/paths.lua.in
@@ -6,7 +6,6 @@ for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do
end
module.test_build_dir = "${CMAKE_BINARY_DIR}"
-module.test_libnvim_path = "${TEST_LIBNVIM_PATH}"
module.test_source_path = "${CMAKE_SOURCE_DIR}"
module.test_lua_prg = "${LUA_PRG}"
module.test_luajit_prg = ""
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index 1be5de6488..e9b47a0251 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -102,6 +102,13 @@ describe('startup', function()
end)
it('os.exit() sets Nvim exitcode', function()
+ -- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it
+ exec_lua [[
+ local asan_options = os.getenv 'ASAN_OPTIONS'
+ if asan_options ~= nil and asan_options ~= '' then
+ vim.loop.os_setenv('ASAN_OPTIONS', asan_options..':detect_leaks=0')
+ end
+ ]]
-- nvim -l foo.lua -arg1 -- a b c
assert_l_out([[
bufs:
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index 14d8eda357..686af3b461 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -75,7 +75,8 @@ local function child_cleanup_once(func, ...)
end
end
-local libnvim = nil
+-- Unittests are run from debug nvim binary in lua interpreter mode.
+local libnvim = ffi.C
local lib = setmetatable({}, {
__index = only_separate(function(_, idx)
@@ -87,8 +88,6 @@ local lib = setmetatable({}, {
})
local init = only_separate(function()
- -- load neovim shared library
- libnvim = ffi.load(Paths.test_libnvim_path)
for _, c in ipairs(child_calls_init) do
c.func(unpack(c.args))
end
diff --git a/test/unit/tui_spec.lua b/test/unit/tui_spec.lua
index 25b70a17c2..192e35a485 100644
--- a/test/unit/tui_spec.lua
+++ b/test/unit/tui_spec.lua
@@ -12,7 +12,7 @@ local multiqueue = cimport("./test/unit/fixtures/multiqueue.h")
local ui_client = cimport("./src/nvim/ui_client.h")
itp('handle_background_color', function()
- local handle_background_color = cinput.ut_handle_background_color
+ local handle_background_color = cinput.handle_background_color
local term_input = ffi.new('TermInput', {})
local events = globals.main_loop.thread_events
local kIncomplete = cinput.kIncomplete