Merge pull request #17537 from bfredl/neolua

refactor(tests): run unittests using main nvim binary - delete separate nvim-test build
This commit is contained in:
bfredl
2023-01-31 19:58:33 +01:00
committed by GitHub
18 changed files with 117 additions and 93 deletions

View File

@@ -26,7 +26,6 @@ BUILD_FLAGS="CMAKE_FLAGS=-DCI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_
case "$FLAVOR" in case "$FLAVOR" in
asan) asan)
BUILD_FLAGS="$BUILD_FLAGS -DPREFER_LUA=ON"
cat <<EOF >> "$GITHUB_ENV" cat <<EOF >> "$GITHUB_ENV"
CLANG_SANITIZER=ASAN_UBSAN 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 ASAN_OPTIONS=detect_leaks=1:check_initialization_order=1:log_path=$GITHUB_WORKSPACE/build/log/asan:intercept_tls_get_addr=0

View File

@@ -370,7 +370,7 @@ endif()
if(BUSTED_PRG) if(BUSTED_PRG)
get_target_property(TEST_INCLUDE_DIRS main_lib INTERFACE_INCLUDE_DIRECTORIES) 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(FUNCTIONALTEST_PREREQS nvim printenv-test printargs-test shell-test pwsh-test streams-test tty-test ${GENERATED_HELP_TAGS})
set(BENCHMARK_PREREQS nvim tty-test) set(BENCHMARK_PREREQS nvim tty-test)
@@ -380,6 +380,7 @@ if(BUSTED_PRG)
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DBUSTED_PRG=${BUSTED_PRG} -DBUSTED_PRG=${BUSTED_PRG}
-DLUA_PRG=${LUA_PRG} -DLUA_PRG=${LUA_PRG}
-DNVIM_PRG=$<TARGET_FILE:nvim>
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE} -DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test -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}") message(WARNING "disabling unit tests: no Luajit FFI in ${LUA_PRG}")
endif() endif()
if(LUA_HAS_FFI)
set(TEST_LIBNVIM_PATH $<TARGET_FILE:nvim-test>)
else()
set(TEST_LIBNVIM_PATH "")
endif()
configure_file( configure_file(
${CMAKE_SOURCE_DIR}/test/cmakeconfig/paths.lua.in ${CMAKE_SOURCE_DIR}/test/cmakeconfig/paths.lua.in
${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua.gen) ${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua.gen)

View File

@@ -16,8 +16,7 @@ build_make() {
} }
build_deps() { build_deps() {
if test "${FUNCTIONALTEST}" = "functionaltest-lua" \ if test "${FUNCTIONALTEST}" = "functionaltest-lua" ; then
|| test "${CLANG_SANITIZER}" = "ASAN_UBSAN" ; then
DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON" DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON"
fi fi
@@ -66,13 +65,6 @@ build_nvim() {
if ! top_make libnvim ; then if ! top_make libnvim ; then
exit 1 exit 1
fi fi
if test "${FUNCTIONALTEST}" != "functionaltest-lua"; then
echo "Building nvim-test."
if ! top_make nvim-test ; then
exit 1
fi
fi
fi fi
# Invoke nvim to trigger *San early. # Invoke nvim to trigger *San early.

View File

@@ -71,8 +71,16 @@ if(NOT DEFINED ENV{TEST_TIMEOUT} OR "$ENV{TEST_TIMEOUT}" STREQUAL "")
endif() endif()
set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua. 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( 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 --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua --lpath=${BUILD_DIR}/?.lua
--lpath=${WORKING_DIR}/runtime/lua/?.lua --lpath=${WORKING_DIR}/runtime/lua/?.lua

View File

@@ -239,6 +239,14 @@ argument.
Disables |shada| unless |-i| was given. Disables |shada| unless |-i| was given.
Disables swapfile (like |-n|). Disables swapfile (like |-n|).
*-ll*
-ll {script} [args]
Execute a lua script, similarly to |-l|, but the editor is not
initialized. This gives a lua enviroment similar to a worker
thread. See |lua-loop-threading|.
Unlike `-l` no prior arguments are allowed.
*-b* *-b*
-b Binary mode. File I/O will only recognize <NL> to separate -b Binary mode. File I/O will only recognize <NL> to separate
lines. The 'expandtab' option will be reset. The 'textwidth' lines. The 'expandtab' option will be reset. The 'textwidth'

View File

@@ -42,8 +42,11 @@ function vim._load_package(name)
return nil return nil
end end
-- Insert vim._load_package after the preloader at position 2 -- TODO(bfredl): dedicated state for this?
table.insert(package.loaders, 2, vim._load_package) if vim.api then
-- Insert vim._load_package after the preloader at position 2
table.insert(package.loaders, 2, vim._load_package)
end
-- builtin functions which always should be available -- builtin functions which always should be available
require('vim.shared') require('vim.shared')
@@ -78,6 +81,6 @@ function vim.empty_dict()
end end
-- only on main thread: functions for interacting with editor state -- only on main thread: functions for interacting with editor state
if not vim.is_thread() then if vim.api and not vim.is_thread() then
require('vim._editor') require('vim._editor')
end end

View File

@@ -52,7 +52,7 @@ if(PREFER_LUA)
find_package(Lua 5.1 EXACT REQUIRED) find_package(Lua 5.1 EXACT REQUIRED)
target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUA_INCLUDE_DIR}) target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LUA_INCLUDE_DIR})
target_link_libraries(main_lib INTERFACE ${LUA_LIBRARIES}) 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) find_package(LuaJit)
else() else()
find_package(LuaJit REQUIRED) find_package(LuaJit REQUIRED)
@@ -679,6 +679,14 @@ if(UNIX)
endif() endif()
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} target_sources(nvim PRIVATE ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS} ${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS}
${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS}) ${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS})
@@ -837,27 +845,6 @@ set_target_properties(
target_compile_definitions(libnvim PRIVATE MAKE_LIB) target_compile_definitions(libnvim PRIVATE MAKE_LIB)
target_link_libraries(libnvim PRIVATE main_lib PUBLIC libuv_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) if(CLANG_ASAN_UBSAN)
message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.") message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
if(CI_BUILD) if(CI_BUILD)

View File

@@ -64,6 +64,7 @@
#include "nvim/window.h" #include "nvim/window.h"
static int in_fast_callback = 0; static int in_fast_callback = 0;
static bool in_script = false;
// Initialized in nlua_init(). // Initialized in nlua_init().
static lua_State *global_lstate = NULL; static lua_State *global_lstate = NULL;
@@ -133,8 +134,13 @@ static void nlua_error(lua_State *const lstate, const char *const msg)
str = lua_tolstring(lstate, -1, &len); str = lua_tolstring(lstate, -1, &len);
} }
if (in_script) {
os_errmsg(str);
os_errmsg("\n");
} else {
msg_ext_set_kind("lua_error"); msg_ext_set_kind("lua_error");
semsg_multiline(msg, (int)len, str); semsg_multiline(msg, (int)len, str);
}
lua_pop(lstate, 1); lua_pop(lstate, 1);
} }
@@ -534,7 +540,7 @@ int nlua_get_global_ref_count(void)
return nlua_global_refs->ref_count; return nlua_global_refs->ref_count;
} }
static void nlua_common_vim_init(lua_State *lstate, bool is_thread) static void nlua_common_vim_init(lua_State *lstate, bool is_thread, bool is_standalone)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
nlua_ref_state_t *ref_state = nlua_new_ref_state(lstate, is_thread); nlua_ref_state_t *ref_state = nlua_new_ref_state(lstate, is_thread);
@@ -567,7 +573,9 @@ static void nlua_common_vim_init(lua_State *lstate, bool is_thread)
lua_setfield(lstate, -2, "_empty_dict_mt"); lua_setfield(lstate, -2, "_empty_dict_mt");
// vim.loop // vim.loop
if (is_thread) { if (is_standalone) {
// do nothing, use libluv like in a standalone interpreter
} else if (is_thread) {
luv_set_callback(lstate, nlua_luv_thread_cb_cfpcall); luv_set_callback(lstate, nlua_luv_thread_cb_cfpcall);
luv_set_thread(lstate, nlua_luv_thread_cfpcall); luv_set_thread(lstate, nlua_luv_thread_cfpcall);
luv_set_cthread(lstate, nlua_luv_thread_cfcpcall); luv_set_cthread(lstate, nlua_luv_thread_cfcpcall);
@@ -606,7 +614,7 @@ static int nlua_module_preloader(lua_State *lstate)
return 1; return 1;
} }
static bool nlua_init_packages(lua_State *lstate) static bool nlua_init_packages(lua_State *lstate, bool is_standalone)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
// put builtin packages in preload // put builtin packages in preload
@@ -618,7 +626,7 @@ static bool nlua_init_packages(lua_State *lstate)
lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure] lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure]
lua_setfield(lstate, -2, def.name); // [package, preload] lua_setfield(lstate, -2, def.name); // [package, preload]
if (nlua_disable_preload && strequal(def.name, "vim.inspect")) { if ((nlua_disable_preload && !is_standalone) && strequal(def.name, "vim.inspect")) {
break; break;
} }
} }
@@ -769,7 +777,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_pushcfunction(lstate, &nlua_ui_detach); lua_pushcfunction(lstate, &nlua_ui_detach);
lua_setfield(lstate, -2, "ui_detach"); lua_setfield(lstate, -2, "ui_detach");
nlua_common_vim_init(lstate, false); nlua_common_vim_init(lstate, false, false);
// patch require() (only for --startuptime) // patch require() (only for --startuptime)
if (time_fd != NULL) { if (time_fd != NULL) {
@@ -788,7 +796,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_setglobal(lstate, "vim"); lua_setglobal(lstate, "vim");
if (!nlua_init_packages(lstate)) { if (!nlua_init_packages(lstate, false)) {
return false; return false;
} }
@@ -813,6 +821,9 @@ void nlua_init(char **argv, int argc, int lua_arg0)
luaL_openlibs(lstate); luaL_openlibs(lstate);
if (!nlua_state_init(lstate)) { if (!nlua_state_init(lstate)) {
os_errmsg(_("E970: Failed to initialize builtin lua modules\n")); os_errmsg(_("E970: Failed to initialize builtin lua modules\n"));
#ifdef EXITFREE
nlua_common_free_all_mem(lstate);
#endif
os_exit(1); os_exit(1);
} }
@@ -823,10 +834,29 @@ void nlua_init(char **argv, int argc, int lua_arg0)
} }
static lua_State *nlua_thread_acquire_vm(void) static lua_State *nlua_thread_acquire_vm(void)
{
return nlua_init_state(true);
}
void nlua_run_script(char **argv, int argc, int lua_arg0)
FUNC_ATTR_NORETURN
{
in_script = true;
global_lstate = nlua_init_state(false);
luv_set_thread_cb(nlua_thread_acquire_vm, nlua_common_free_all_mem);
nlua_init_argv(global_lstate, argv, argc, lua_arg0);
bool lua_ok = nlua_exec_file(argv[lua_arg0 - 1]);
#ifdef EXITFREE
nlua_free_all_mem();
#endif
exit(lua_ok ? 0 : 1);
}
lua_State *nlua_init_state(bool thread)
{ {
// If it is called from the main thread, it will attempt to rebuild the cache. // If it is called from the main thread, it will attempt to rebuild the cache.
const uv_thread_t self = uv_thread_self(); const uv_thread_t self = uv_thread_self();
if (uv_thread_equal(&main_thread, &self)) { if (!in_script && uv_thread_equal(&main_thread, &self)) {
runtime_search_path_validate(); runtime_search_path_validate();
} }
@@ -835,9 +865,11 @@ static lua_State *nlua_thread_acquire_vm(void)
// Add in the lua standard libraries // Add in the lua standard libraries
luaL_openlibs(lstate); luaL_openlibs(lstate);
if (!in_script) {
// print // print
lua_pushcfunction(lstate, &nlua_print); lua_pushcfunction(lstate, &nlua_print);
lua_setglobal(lstate, "print"); lua_setglobal(lstate, "print");
}
lua_pushinteger(lstate, 0); lua_pushinteger(lstate, 0);
lua_setfield(lstate, LUA_REGISTRYINDEX, "nlua.refcount"); lua_setfield(lstate, LUA_REGISTRYINDEX, "nlua.refcount");
@@ -845,18 +877,20 @@ static lua_State *nlua_thread_acquire_vm(void)
// vim // vim
lua_newtable(lstate); lua_newtable(lstate);
nlua_common_vim_init(lstate, true); nlua_common_vim_init(lstate, thread, in_script);
nlua_state_add_stdlib(lstate, true); nlua_state_add_stdlib(lstate, true);
if (!in_script) {
lua_createtable(lstate, 0, 0); lua_createtable(lstate, 0, 0);
lua_pushcfunction(lstate, nlua_thr_api_nvim__get_runtime); lua_pushcfunction(lstate, nlua_thr_api_nvim__get_runtime);
lua_setfield(lstate, -2, "nvim__get_runtime"); lua_setfield(lstate, -2, "nvim__get_runtime");
lua_setfield(lstate, -2, "api"); lua_setfield(lstate, -2, "api");
}
lua_setglobal(lstate, "vim"); lua_setglobal(lstate, "vim");
nlua_init_packages(lstate); nlua_init_packages(lstate, in_script);
lua_getglobal(lstate, "package"); lua_getglobal(lstate, "package");
lua_getfield(lstate, -1, "loaded"); lua_getfield(lstate, -1, "loaded");

View File

@@ -239,6 +239,14 @@ int main(int argc, char **argv)
argv0 = argv[0]; argv0 = argv[0];
if (argc > 1 && STRICMP(argv[1], "-ll") == 0) {
if (argc == 2) {
print_mainerr(err_arg_missing, argv[1]);
exit(1);
}
nlua_run_script(argv, argc, 3);
}
char *fname = NULL; // file name from command line char *fname = NULL; // file name from command line
mparm_T params; // various parameters passed between mparm_T params; // various parameters passed between
// main() and other functions. // main() and other functions.
@@ -2110,6 +2118,12 @@ static int execute_env(char *env)
/// @param str string to append to the primary error message, or NULL /// @param str string to append to the primary error message, or NULL
static void mainerr(const char *errstr, const char *str) static void mainerr(const char *errstr, const char *str)
FUNC_ATTR_NORETURN FUNC_ATTR_NORETURN
{
print_mainerr(errstr, str);
os_exit(1);
}
static void print_mainerr(const char *errstr, const char *str)
{ {
char *prgname = path_tail(argv0); char *prgname = path_tail(argv0);
@@ -2126,8 +2140,6 @@ static void mainerr(const char *errstr, const char *str)
os_errmsg(_("\nMore info with \"")); os_errmsg(_("\nMore info with \""));
os_errmsg(prgname); os_errmsg(prgname);
os_errmsg(" -h\"\n"); os_errmsg(" -h\"\n");
os_exit(1);
} }
/// Prints version information for "nvim -v" or "nvim --version". /// Prints version information for "nvim -v" or "nvim --version".

View File

@@ -1182,7 +1182,7 @@ static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_rig
assert(x->ptr[i] != x->ptr[j]); assert(x->ptr[i] != x->ptr[j]);
} }
} }
} else { } else if (x->n > 0) {
*last = x->key[x->n - 1].pos; *last = x->key[x->n - 1].pos;
} }
return n_keys; return n_keys;

View File

@@ -117,14 +117,6 @@ static const struct kitty_key_map_entry {
static Map(KittyKey, cstr_t) kitty_key_map = MAP_INIT; 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 #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/input.c.generated.h" # include "tui/input.c.generated.h"
#endif #endif
@@ -584,7 +576,7 @@ static void set_bg(char *bgvalue)
// ignored in the calculations. // ignored in the calculations.
// //
// [1] https://en.wikipedia.org/wiki/Luma_%28video%29 // [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) { if (input->waiting_for_bg_response <= 0) {
return kNotApplicable; return kNotApplicable;
@@ -669,12 +661,6 @@ static HandleState handle_background_color(TermInput *input)
} }
return kComplete; 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) static void handle_raw_buffer(TermInput *input, bool force)
{ {

View File

@@ -40,18 +40,14 @@ typedef struct term_input {
TUIData *tui_data; TUIData *tui_data;
} TermInput; } TermInput;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/input.h.generated.h"
#endif
#ifdef UNIT_TESTING
typedef enum { typedef enum {
kIncomplete = -1, kIncomplete = -1,
kNotApplicable = 0, kNotApplicable = 0,
kComplete = 1, kComplete = 1,
} HandleState; } HandleState;
HandleState ut_handle_background_color(TermInput *input); #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/input.h.generated.h"
#endif #endif
#endif // NVIM_TUI_INPUT_H #endif // NVIM_TUI_INPUT_H

1
test/busted_runner.lua Normal file
View File

@@ -0,0 +1 @@
require 'busted.runner'({ standalone = false })

View File

@@ -6,7 +6,6 @@ for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do
end end
module.test_build_dir = "${CMAKE_BINARY_DIR}" module.test_build_dir = "${CMAKE_BINARY_DIR}"
module.test_libnvim_path = "${TEST_LIBNVIM_PATH}"
module.test_source_path = "${CMAKE_SOURCE_DIR}" module.test_source_path = "${CMAKE_SOURCE_DIR}"
module.test_lua_prg = "${LUA_PRG}" module.test_lua_prg = "${LUA_PRG}"
module.test_luajit_prg = "" module.test_luajit_prg = ""

View File

@@ -102,6 +102,13 @@ describe('startup', function()
end) end)
it('os.exit() sets Nvim exitcode', function() 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 -- nvim -l foo.lua -arg1 -- a b c
assert_l_out([[ assert_l_out([[
bufs: bufs:

View File

@@ -1677,7 +1677,7 @@ describe('typval.c', function()
eq(nil, lib.tv_dict_find(nil, 'test', -1)) eq(nil, lib.tv_dict_find(nil, 'test', -1))
eq(nil, lib.tv_dict_find(nil, nil, 0)) eq(nil, lib.tv_dict_find(nil, nil, 0))
end) end)
itp('works with NULL key', function() itp('works with empty key', function()
local lua_d = { local lua_d = {
['']=0, ['']=0,
t=1, t=1,
@@ -1692,7 +1692,6 @@ describe('typval.c', function()
alloc_log:check({}) alloc_log:check({})
local dis = dict_items(d) local dis = dict_items(d)
eq({0, '', dis['']}, {tv_dict_find(d, '', 0)}) eq({0, '', dis['']}, {tv_dict_find(d, '', 0)})
eq({0, '', dis['']}, {tv_dict_find(d, nil, 0)})
end) end)
itp('works with len properly', function() itp('works with len properly', function()
local lua_d = { local lua_d = {
@@ -1910,8 +1909,6 @@ describe('typval.c', function()
} }
local d = dict(lua_d) local d = dict(lua_d)
eq(lua_d, dct2tbl(d)) eq(lua_d, dct2tbl(d))
eq({{type='fref', fref='tr'}, true},
{tv_dict_get_callback(d, nil, 0)})
eq({{type='fref', fref='tr'}, true}, eq({{type='fref', fref='tr'}, true},
{tv_dict_get_callback(d, '', -1)}) {tv_dict_get_callback(d, '', -1)})
eq({{type='none'}, true}, eq({{type='none'}, true},

View File

@@ -75,7 +75,8 @@ local function child_cleanup_once(func, ...)
end end
end end
local libnvim = nil -- Unittests are run from debug nvim binary in lua interpreter mode.
local libnvim = ffi.C
local lib = setmetatable({}, { local lib = setmetatable({}, {
__index = only_separate(function(_, idx) __index = only_separate(function(_, idx)
@@ -87,8 +88,6 @@ local lib = setmetatable({}, {
}) })
local init = only_separate(function() local init = only_separate(function()
-- load neovim shared library
libnvim = ffi.load(Paths.test_libnvim_path)
for _, c in ipairs(child_calls_init) do for _, c in ipairs(child_calls_init) do
c.func(unpack(c.args)) c.func(unpack(c.args))
end end

View File

@@ -12,7 +12,7 @@ local multiqueue = cimport("./test/unit/fixtures/multiqueue.h")
local ui_client = cimport("./src/nvim/ui_client.h") local ui_client = cimport("./src/nvim/ui_client.h")
itp('handle_background_color', function() 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 term_input = ffi.new('TermInput', {})
local events = globals.main_loop.thread_events local events = globals.main_loop.thread_events
local kIncomplete = cinput.kIncomplete local kIncomplete = cinput.kIncomplete