From 496eca22b37b243aba2efe8383e591ef57d27df9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 18 Feb 2026 15:56:50 +0800 Subject: [PATCH] test: support running functionaltests in parallel by directory (#37918) Define a CMake target for every subdirectory of test/functional that contains functional tests, and a functionaltest_parallel target that depends on all those targets, allowing multiple test runners to run in parallel. On CI, use at most 2 parallel test runners, as using more may increase system load and make tests unstable. --- .github/workflows/test.yml | 25 ++++++--- .github/workflows/test_windows.yml | 10 +++- cmake/RunTests.cmake | 46 ++++++++++++---- test/CMakeLists.txt | 47 +++++++++++++---- test/busted/outputHandlers/nvim.lua | 24 +++++++-- test/functional/api/vim_spec.lua | 28 +++++----- test/functional/ex_cmds/trust_spec.lua | 51 +++++++++--------- test/functional/legacy/normal_spec.lua | 2 +- test/functional/lua/option_and_var_spec.lua | 7 +-- test/functional/lua/secure_spec.lua | 52 ++++++++++--------- test/functional/plugin/spellfile_spec.lua | 4 +- test/functional/ui/messages_spec.lua | 2 +- test/functional/vimscript/executable_spec.lua | 10 +++- 13 files changed, 206 insertions(+), 102 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65ac93f60b..9a9b7e3b23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -163,16 +163,29 @@ jobs: cmake --preset ci -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX ${{ matrix.build.flags }} cmake --build build + - if: ${{ matrix.test == 'unittest' }} + name: unittest + timeout-minutes: 20 + run: cmake --build build --target unittest + + - if: ${{ matrix.test == 'functionaltest' }} + name: functionaltest + timeout-minutes: 20 + env: + # With parallel tests, use shorter timeout for a single group. + TEST_TIMEOUT: 600 + run: | + set +e + cmake --build build --target functionaltest_parallel -j 2 -- -k 0 + exit_code="$?" + cmake --build build --target functionaltest_summary + exit "$exit_code" + - if: ${{ matrix.test == 'oldtest' }} - name: ${{ matrix.test }} + name: oldtest timeout-minutes: 20 run: make -C test/old/testdir NVIM_PRG=$(realpath build)/bin/nvim - - if: ${{ matrix.test != 'oldtest' }} - name: ${{ matrix.test }} - timeout-minutes: 20 - run: cmake --build build --target ${{ matrix.test }} - - name: Install run: | cmake --install build diff --git a/.github/workflows/test_windows.yml b/.github/workflows/test_windows.yml index dd72329bb8..1606940f2e 100644 --- a/.github/workflows/test_windows.yml +++ b/.github/workflows/test_windows.yml @@ -54,7 +54,15 @@ jobs: - if: ${{ matrix.test == 'functional' }} name: functionaltest timeout-minutes: ${{ inputs.functionaltest_timeout }} - run: cmake --build build --target functionaltest + env: + # With parallel tests, use shorter timeout for a single group. + TEST_TIMEOUT: 600 + run: | + $ErrorActionPreference = 'Continue' + cmake --build build --target functionaltest_parallel -j 2 -- -k 0 + $exitCode = $LASTEXITCODE + cmake --build build --target functionaltest_summary + exit $exitCode - if: ${{ matrix.test == 'old' }} uses: msys2/setup-msys2@v2 diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index e1b8bb8e9a..48876c07c8 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -1,11 +1,21 @@ +if(DEFINED TEST_PARALLEL_GROUP) + if(DEFINED ENV{TEST_FILE}) + message(FATAL_ERROR "$TEST_FILE should not be used with parallel tests") + endif() + set(TEST_SUFFIX "_${TEST_PARALLEL_GROUP}") + string(REGEX REPLACE "[^A-Za-z0-9_]" "_" TEST_SUFFIX ${TEST_SUFFIX}) +else() + set(TEST_SUFFIX "") +endif() + set(ENV{NVIM_TEST} "1") # Set LC_ALL to meet expectations of some locale-sensitive tests. set(ENV{LC_ALL} "en_US.UTF-8") set(ENV{VIMRUNTIME} ${WORKING_DIR}/runtime) -set(ENV{NVIM_RPLUGIN_MANIFEST} ${BUILD_DIR}/Xtest_rplugin_manifest) -set(ENV{XDG_CONFIG_HOME} ${BUILD_DIR}/Xtest_xdg/config) -set(ENV{XDG_DATA_HOME} ${BUILD_DIR}/Xtest_xdg/share) -set(ENV{XDG_STATE_HOME} ${BUILD_DIR}/Xtest_xdg/state) +set(ENV{NVIM_RPLUGIN_MANIFEST} ${BUILD_DIR}/Xtest_rplugin_manifest${TEST_SUFFIX}) +set(ENV{XDG_CONFIG_HOME} ${BUILD_DIR}/Xtest_xdg${TEST_SUFFIX}/config) +set(ENV{XDG_DATA_HOME} ${BUILD_DIR}/Xtest_xdg${TEST_SUFFIX}/share) +set(ENV{XDG_STATE_HOME} ${BUILD_DIR}/Xtest_xdg${TEST_SUFFIX}/state) unset(ENV{XDG_DATA_DIRS}) unset(ENV{NVIM}) # Clear $NVIM in case tests are running from Nvim. #11009 unset(ENV{TMUX}) # Nvim TUI shouldn't think it's running in tmux. #34173 @@ -19,6 +29,7 @@ set(ENV{CIRRUS_CI} ${CIRRUS_CI}) if(NOT DEFINED ENV{NVIM_LOG_FILE}) set(ENV{NVIM_LOG_FILE} ${BUILD_DIR}/.nvimlog) endif() +set(ENV{NVIM_LOG_FILE} "$ENV{NVIM_LOG_FILE}${TEST_SUFFIX}") if(NVIM_PRG) set(ENV{NVIM_PRG} "${NVIM_PRG}") @@ -26,10 +37,16 @@ endif() if(DEFINED ENV{TEST_FILE}) set(TEST_PATH "$ENV{TEST_FILE}") +elseif(DEFINED TEST_PARALLEL_GROUP) + set(TEST_PATH "${TEST_DIR}/${TEST_TYPE}/${TEST_PARALLEL_GROUP}") else() set(TEST_PATH "${TEST_DIR}/${TEST_TYPE}") endif() +if(NOT DEFINED TEST_SUMMARY_FILE) + set(TEST_SUMMARY_FILE "-") +endif() + # Force $TEST_PATH to workdir-relative path ("test/…"). if(IS_ABSOLUTE ${TEST_PATH}) file(RELATIVE_PATH TEST_PATH "${WORKING_DIR}" "${TEST_PATH}") @@ -50,7 +67,7 @@ if(DEFINED ENV{TEST_FILTER_OUT} AND NOT "$ENV{TEST_FILTER_OUT}" STREQUAL "") endif() # TMPDIR: for testutil.tmpname() and Nvim tempname(). -set(ENV{TMPDIR} "${BUILD_DIR}/Xtest_tmpdir") +set(ENV{TMPDIR} "${BUILD_DIR}/Xtest_tmpdir${TEST_SUFFIX}") execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory $ENV{TMPDIR}) # HISTFILE: do not write into user's ~/.bash_history @@ -71,6 +88,7 @@ execute_process( # Note: because of "-ll" (low-level interpreter mode), some modules like # _core/editor.lua are not loaded. COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/lua_runner.lua ${DEPS_INSTALL_DIR}/share/lua/5.1/ busted -v -o test.busted.outputHandlers.nvim + -Xoutput "{\"test_path\": \"${TEST_PATH}\", \"summary_file\": \"${TEST_SUMMARY_FILE}\"}" --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua --lpath=${BUILD_DIR}/?.lua --lpath=${WORKING_DIR}/src/?.lua @@ -83,8 +101,16 @@ execute_process( RESULT_VARIABLE res ${EXTRA_ARGS}) -file(GLOB RM_FILES ${BUILD_DIR}/Xtest_*) -file(REMOVE_RECURSE ${RM_FILES}) +file(REMOVE_RECURSE $ENV{TMPDIR}) + +macro(PRINT_NVIM_LOG) + file(READ $ENV{NVIM_LOG_FILE} out) + if(${TEST_SUMMARY_FILE} STREQUAL "-") + message(STATUS "$NVIM_LOG_FILE: $ENV{NVIM_LOG_FILE}\n${out}") + else() + file(APPEND ${TEST_SUMMARY_FILE} "$NVIM_LOG_FILE: $ENV{NVIM_LOG_FILE}\n${out}") + endif() +endmacro() if(res) message(STATUS "Tests exited non-zero: ${res}") @@ -92,8 +118,7 @@ if(res) # Dump the logfile on CI (if not displayed and moved already). if(CI_BUILD) if(EXISTS $ENV{NVIM_LOG_FILE} AND NOT EXISTS $ENV{NVIM_LOG_FILE}.displayed) - file(READ $ENV{NVIM_LOG_FILE} out) - message(STATUS "$NVIM_LOG_FILE: $ENV{NVIM_LOG_FILE}\n${out}") + PRINT_NVIM_LOG() endif() endif() @@ -103,8 +128,7 @@ endif() if(CI_BUILD) file(SIZE $ENV{NVIM_LOG_FILE} FILE_SIZE) if(NOT ${FILE_SIZE} MATCHES "^0$") - file(READ $ENV{NVIM_LOG_FILE} out) - message(STATUS "$NVIM_LOG_FILE: $ENV{NVIM_LOG_FILE}\n${out}") + PRINT_NVIM_LOG() message(FATAL_ERROR "$NVIM_LOG_FILE is not empty") endif() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1141e6aded..3ed2c6d22c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,13 +2,14 @@ add_subdirectory(functional/fixtures) # compile test programs get_directory_property(TEST_INCLUDE_DIRS DIRECTORY ${PROJECT_SOURCE_DIR}/src/nvim DEFINITION TEST_INCLUDE_DIRS) +set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(TEST_OPTIONS -D BUILD_DIR=${CMAKE_BINARY_DIR} -D CIRRUS_CI=$ENV{CIRRUS_CI} -D CI_BUILD=${CI_BUILD} -D DEPS_INSTALL_DIR=${DEPS_INSTALL_DIR} -D NVIM_PRG=$ - -D TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -D TEST_DIR=${TEST_DIR} -D WORKING_DIR=${PROJECT_SOURCE_DIR}) check_lua_module(${LUA_PRG} "ffi" LUA_HAS_FFI) @@ -28,6 +29,15 @@ configure_file( ${CMAKE_SOURCE_DIR}/test/cmakeconfig/paths.lua.in ${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua) +add_custom_target(benchmark + COMMAND ${CMAKE_COMMAND} + -D TEST_TYPE=benchmark + ${TEST_OPTIONS} + -P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake + DEPENDS tty-test + USES_TERMINAL) +add_dependencies(benchmark lua_dev_deps nvim) + add_custom_target(functionaltest COMMAND ${CMAKE_COMMAND} -D TEST_TYPE=functional @@ -37,11 +47,30 @@ add_custom_target(functionaltest USES_TERMINAL) add_dependencies(functionaltest lua_dev_deps nvim) -add_custom_target(benchmark - COMMAND ${CMAKE_COMMAND} - -D TEST_TYPE=benchmark - ${TEST_OPTIONS} - -P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake - DEPENDS tty-test - USES_TERMINAL) -add_dependencies(benchmark lua_dev_deps nvim) +# Create multiple targets for groups of functional tests to enable parallel testing. +set(group_targets "") +set(summary_files "") +file(GLOB_RECURSE test_files RELATIVE "${TEST_DIR}/functional" "${TEST_DIR}/functional/*_spec*") +foreach(test_file ${test_files}) + # Get test group: "test/functional/foo/bar_spec.lua" => "foo". + string(REGEX REPLACE "/.*" "" test_group ${test_file}) + set(group_target "functionaltest_${test_group}") + string(REGEX REPLACE "[^A-Za-z0-9_]" "_" group_target ${group_target}) + list(FIND group_targets ${group_target} group_idx) + if(${group_idx} EQUAL -1) + # Create new target for test group. + set(summary_file "${CMAKE_BINARY_DIR}/${group_target}.summary") + add_custom_target(${group_target} + COMMAND ${CMAKE_COMMAND} + -D TEST_TYPE=functional -D TEST_PARALLEL_GROUP=${test_group} -D TEST_SUMMARY_FILE=${summary_file} + ${TEST_OPTIONS} + -P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake + DEPENDS printenv-test printargs-test shell-test pwsh-test streams-test tty-test) + add_dependencies(${group_target} lua_dev_deps nvim) + list(APPEND group_targets ${group_target}) + list(APPEND summary_files ${summary_file}) + endif() +endforeach() + +add_custom_target(functionaltest_parallel DEPENDS ${group_targets}) +add_custom_target(functionaltest_summary COMMAND ${CMAKE_COMMAND} -E cat ${summary_files} USES_TERMINAL) diff --git a/test/busted/outputHandlers/nvim.lua b/test/busted/outputHandlers/nvim.lua index f4a3bcdad3..532449965c 100644 --- a/test/busted/outputHandlers/nvim.lua +++ b/test/busted/outputHandlers/nvim.lua @@ -25,6 +25,8 @@ end return function(options) local busted = require 'busted' local handler = require 'busted.outputHandlers.base'() + local args = options.arguments + args = vim.json.decode(#args > 0 and table.concat(args, ',') or '{}') local c = { succ = function(s) @@ -254,13 +256,25 @@ return function(options) local elapsedTime_ms = getElapsedTime(suite) local tests = (testCount == 1 and 'test' or 'tests') local files = (fileCount == 1 and 'file' or 'files') - io.write(globalTeardown) - io.write(suiteEndString:format(testCount, tests, fileCount, files, elapsedTime_ms)) - io.write(getSummaryString()) - if failureCount > 0 or errorCount > 0 then - io.write(t_global.read_nvim_log(nil, true)) + if type(args.test_path) == 'string' then + files = files .. ' of ' .. args.test_path end + local sf = type(args.summary_file) == 'string' + and args.summary_file ~= '-' + and io.open(args.summary_file, 'w') + or io.stdout + io.write(globalTeardown) io.flush() + sf:write('\n') + sf:write(suiteEndString:format(testCount, tests, fileCount, files, elapsedTime_ms)) + sf:write(getSummaryString()) + if failureCount > 0 or errorCount > 0 then + sf:write(t_global.read_nvim_log(nil, true)) + end + sf:flush() + if sf ~= io.stdout then + sf:close() + end return nil, true end diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7bf8295878..74af76bdd2 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -734,23 +734,24 @@ describe('API', function() describe('nvim_set_current_dir', function() local start_dir + local test_dir = 'Xtest_set_current_dir' before_each(function() - fn.mkdir('Xtestdir') + fn.mkdir(test_dir) start_dir = fn.getcwd() end) after_each(function() - n.rmdir('Xtestdir') + n.rmdir(test_dir) end) it('works', function() - api.nvim_set_current_dir('Xtestdir') - eq(start_dir .. n.get_pathsep() .. 'Xtestdir', fn.getcwd()) + api.nvim_set_current_dir(test_dir) + eq(start_dir .. n.get_pathsep() .. test_dir, fn.getcwd()) end) it('sets previous directory', function() - api.nvim_set_current_dir('Xtestdir') + api.nvim_set_current_dir(test_dir) command('cd -') eq(start_dir, fn.getcwd()) end) @@ -1670,8 +1671,9 @@ describe('API', function() -- Check if autoload works properly local pathsep = n.get_pathsep() - local xconfig = 'Xhome' .. pathsep .. 'Xconfig' - local xdata = 'Xhome' .. pathsep .. 'Xdata' + local xhome = 'Xhome_api' + local xconfig = xhome .. pathsep .. 'Xconfig' + local xdata = xhome .. pathsep .. 'Xdata' local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) local autoload_file = table.concat({ autoload_folder, 'testload.vim' }, pathsep) mkdir_p(autoload_folder) @@ -1679,7 +1681,7 @@ describe('API', function() clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } } eq(2, api.nvim_get_var('testload#value')) - rmdir('Xhome') + rmdir(xhome) end) it('nvim_get_vvar, nvim_set_vvar', function() @@ -2966,16 +2968,18 @@ describe('API', function() end) describe('nvim_list_runtime_paths', function() + local test_dir = 'Xtest_list_runtime_paths' + setup(function() local pathsep = n.get_pathsep() - mkdir_p('Xtest' .. pathsep .. 'a') - mkdir_p('Xtest' .. pathsep .. 'b') + mkdir_p(test_dir .. pathsep .. 'a') + mkdir_p(test_dir .. pathsep .. 'b') end) teardown(function() - rmdir 'Xtest' + rmdir(test_dir) end) before_each(function() - api.nvim_set_current_dir 'Xtest' + api.nvim_set_current_dir(test_dir) end) it('returns nothing with empty &runtimepath', function() diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index f33f237c4c..5b6210bd3c 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -11,57 +11,63 @@ local is_os = t.is_os local fn = n.fn describe(':trust', function() - local xstate = 'Xstate' + local xstate = 'Xstate_ex_trust' + local test_file = 'Xtest_functional_ex_cmds_trust' before_each(function() n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - t.write_file('test_file', 'test') + t.write_file(test_file, 'test') clear { env = { XDG_STATE_HOME = xstate } } end) after_each(function() - os.remove('test_file') + os.remove(test_file) n.rmdir(xstate) end) + --- @param s string + local function fmt(s) + return s:format(test_file) + end + it('is not executed when inside false condition', function() - command('edit test_file') + command(fmt('edit %s')) eq('', exec_capture('if 0 | trust | endif')) eq(nil, vim.uv.fs_stat(fn.stdpath('state') .. pathsep .. 'trust')) end) it('trust then deny then remove a file using current buffer', function() local cwd = fn.getcwd() - local hash = fn.sha256(t.read_file('test_file')) + local hash = fn.sha256(assert(t.read_file(test_file))) - command('edit test_file') - matches('^Allowed in trust database%: ".*test_file"$', exec_capture('trust')) + command(fmt('edit %s')) + matches(fmt('^Allowed in trust database%%: ".*%s"$'), exec_capture('trust')) local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') - eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) + eq(string.format('%s %s', hash, cwd .. pathsep .. test_file), vim.trim(trust)) - matches('^Denied in trust database%: ".*test_file"$', exec_capture('trust ++deny')) + matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture('trust ++deny')) trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') - eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust)) - matches('^Removed from trust database%: ".*test_file"$', exec_capture('trust ++remove')) + matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture('trust ++remove')) trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() local cwd = fn.getcwd() - local hash = fn.sha256(t.read_file('test_file')) + local hash = fn.sha256(assert(t.read_file(test_file))) - command('edit test_file') - matches('^Denied in trust database%: ".*test_file"$', exec_capture('trust ++deny')) + command(fmt('edit %s')) + matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture('trust ++deny')) local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') - eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust)) - matches('^Allowed in trust database%: ".*test_file"$', exec_capture('trust')) + matches(fmt('^Allowed in trust database%%: ".*%s"$'), exec_capture('trust')) trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') - eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) + eq(string.format('%s %s', hash, cwd .. pathsep .. test_file), vim.trim(trust)) - matches('^Removed from trust database%: ".*test_file"$', exec_capture('trust ++remove')) + matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture('trust ++remove')) trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) @@ -69,14 +75,11 @@ describe(':trust', function() it('deny then remove a file using file path', function() local cwd = fn.getcwd() - matches('^Denied in trust database%: ".*test_file"$', exec_capture('trust ++deny test_file')) + matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture(fmt('trust ++deny %s'))) local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') - eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) + eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust)) - matches( - '^Removed from trust database%: ".*test_file"$', - exec_capture('trust ++remove test_file') - ) + matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture(fmt('trust ++remove %s'))) trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) diff --git a/test/functional/legacy/normal_spec.lua b/test/functional/legacy/normal_spec.lua index cc542da71c..576910f9bb 100644 --- a/test/functional/legacy/normal_spec.lua +++ b/test/functional/legacy/normal_spec.lua @@ -143,7 +143,7 @@ describe('normal', function() fn.mkdir(locale_dir, 'p') fn.filecopy(build_dir .. '/src/nvim/po/tr.mo', locale_dir .. '/nvim.mo') finally(function() - n.rmdir(build_dir .. '/share') + n.rmdir(vim.fs.dirname(locale_dir)) end) clear({ env = { LANG = 'tr_TR.UTF-8' } }) diff --git a/test/functional/lua/option_and_var_spec.lua b/test/functional/lua/option_and_var_spec.lua index 4953100622..eac74a5cc5 100644 --- a/test/functional/lua/option_and_var_spec.lua +++ b/test/functional/lua/option_and_var_spec.lua @@ -128,8 +128,9 @@ describe('lua stdlib', function() -- Check if autoload works properly local pathsep = n.get_pathsep() - local xconfig = 'Xhome' .. pathsep .. 'Xconfig' - local xdata = 'Xhome' .. pathsep .. 'Xdata' + local xhome = 'Xhome_lua' + local xconfig = xhome .. pathsep .. 'Xconfig' + local xdata = xhome .. pathsep .. 'Xdata' local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) local autoload_file = table.concat({ autoload_folder, 'testload.vim' }, pathsep) mkdir_p(autoload_folder) @@ -138,7 +139,7 @@ describe('lua stdlib', function() clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } } eq(2, exec_lua("return vim.g['testload#value']")) - rmdir('Xhome') + rmdir(xhome) end) it('vim.b', function() diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index 728ae14e0e..69a66c6ce3 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -19,7 +19,7 @@ local read_file = t.read_file describe('vim.secure', function() describe('read()', function() - local xstate = 'Xstate' + local xstate = 'Xstate_lua_secure' local screen ---@type test.functional.ui.screen before_each(function() @@ -272,7 +272,9 @@ describe('vim.secure', function() end) describe('trust()', function() - local xstate = 'Xstate' + local xstate = 'Xstate_lua_secure' + local test_file = 'Xtest_functional_lua_secure' + local test_dir = 'Xtest_functional_lua_secure_dir' setup(function() clear { env = { XDG_STATE_HOME = xstate } } @@ -280,20 +282,20 @@ describe('vim.secure', function() before_each(function() n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - t.write_file('test_file', 'test') - t.mkdir('test_dir') + t.write_file(test_file, 'test') + t.mkdir(test_dir) end) after_each(function() - os.remove('test_file') - n.rmdir('test_dir') + os.remove(test_file) + n.rmdir(test_dir) n.rmdir(xstate) end) it('returns error when passing both path and bufnr', function() matches( '"path" and "bufnr" are mutually exclusive', - pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]]) + pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path=...})]], test_file) ) end) @@ -306,10 +308,10 @@ describe('vim.secure', function() it('trust then deny then remove a file using bufnr', function() local cwd = fn.getcwd() - local hash = fn.sha256(assert(read_file('test_file'))) - local full_path = cwd .. pathsep .. 'test_file' + local hash = fn.sha256(assert(read_file(test_file))) + local full_path = cwd .. pathsep .. test_file - command('edit test_file') + command('edit ' .. test_file) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq(string.format('%s %s', hash, full_path), vim.trim(trust)) @@ -325,10 +327,10 @@ describe('vim.secure', function() it('deny then trust then remove a file using bufnr', function() local cwd = fn.getcwd() - local hash = fn.sha256(assert(read_file('test_file'))) - local full_path = cwd .. pathsep .. 'test_file' + local hash = fn.sha256(assert(read_file(test_file))) + local full_path = cwd .. pathsep .. test_file - command('edit test_file') + command('edit ' .. test_file) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq(string.format('! %s', full_path), vim.trim(trust)) @@ -344,24 +346,24 @@ describe('vim.secure', function() it('trust using bufnr then deny then remove a file using path', function() local cwd = fn.getcwd() - local hash = fn.sha256(assert(read_file('test_file'))) - local full_path = cwd .. pathsep .. 'test_file' + local hash = fn.sha256(assert(read_file(test_file))) + local full_path = cwd .. pathsep .. test_file - command('edit test_file') + command('edit ' .. test_file) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq(string.format('%s %s', hash, full_path), vim.trim(trust)) eq( { true, full_path }, - exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) + exec_lua([[return {vim.secure.trust({action='deny', path=...})}]], test_file) ) trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq(string.format('! %s', full_path), vim.trim(trust)) eq( { true, full_path }, - exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) + exec_lua([[return {vim.secure.trust({action='remove', path=...})}]], test_file) ) trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq('', vim.trim(trust)) @@ -369,13 +371,13 @@ describe('vim.secure', function() it('deny then trust then remove a file using bufnr', function() local cwd = fn.getcwd() - local hash = fn.sha256(assert(read_file('test_file'))) - local full_path = cwd .. pathsep .. 'test_file' + local hash = fn.sha256(assert(read_file(test_file))) + local full_path = cwd .. pathsep .. test_file - command('edit test_file') + command('edit ' .. test_file) eq( { true, full_path }, - exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) + exec_lua([[return {vim.secure.trust({action='deny', path=...})}]], test_file) ) local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq(string.format('! %s', full_path), vim.trim(trust)) @@ -386,7 +388,7 @@ describe('vim.secure', function() eq( { true, full_path }, - exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) + exec_lua([[return {vim.secure.trust({action='remove', path=...})}]], test_file) ) trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) eq('', vim.trim(trust)) @@ -402,8 +404,8 @@ describe('vim.secure', function() it('trust then deny then remove a directory using bufnr', function() local cwd = fn.getcwd() - local full_path = cwd .. pathsep .. 'test_dir' - command('edit test_dir') + local full_path = cwd .. pathsep .. test_dir + command('edit ' .. test_dir) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) local trust = assert(read_file(stdpath('state') .. pathsep .. 'trust')) diff --git a/test/functional/plugin/spellfile_spec.lua b/test/functional/plugin/spellfile_spec.lua index 262b63a0b7..38ffb6e6c0 100644 --- a/test/functional/plugin/spellfile_spec.lua +++ b/test/functional/plugin/spellfile_spec.lua @@ -6,8 +6,8 @@ local neq = t.neq local exec_lua = n.exec_lua describe('nvim.spellfile', function() - local data_root = 'Xtest_data' - local rtp_dir = 'Xtest_rtp' + local data_root = 'Xtest_data_spellfile' + local rtp_dir = 'Xtest_rtp_spellfile' before_each(function() n.clear() diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 539d1ad1e0..c9a4f2c715 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -2447,7 +2447,7 @@ describe('ui/msg_puts_printf', function() fn.mkdir(locale_dir, 'p') fn.filecopy(build_dir .. '/src/nvim/po/ja.mo', locale_dir .. '/nvim.mo') finally(function() - n.rmdir(build_dir .. '/share') + n.rmdir(vim.fs.dirname(locale_dir)) end) cmd = cmd .. '"' .. nvim_prog .. '" -u NONE -i NONE -Es -V1' diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index a66f9cdb8a..05d249ca32 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -33,9 +33,15 @@ describe('executable()', function() end) it('stdpath respects shellslash', function() - eq([[build\Xtest_xdg\share\nvim-data]], call('fnamemodify', call('stdpath', 'data'), ':.')) + t.matches( + [[build\Xtest_xdg[%w_]*\share\nvim%-data]], + call('fnamemodify', call('stdpath', 'data'), ':.') + ) command('set shellslash') - eq('build/Xtest_xdg/share/nvim-data', call('fnamemodify', call('stdpath', 'data'), ':.')) + t.matches( + 'build/Xtest_xdg[%w_]*/share/nvim%-data', + call('fnamemodify', call('stdpath', 'data'), ':.') + ) end) end