mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 20:59:11 +00:00
Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
87 lines
2.6 KiB
Lua
87 lines
2.6 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
local describe, it, before_each = t.describe, t.it, t.before_each
|
|
local eq, clear, call = t.eq, n.clear, n.call
|
|
local command = n.command
|
|
local matches = t.matches
|
|
local pcall_err = t.pcall_err
|
|
local is_os = t.is_os
|
|
local set_shell_powershell = n.set_shell_powershell
|
|
local eval = n.eval
|
|
|
|
local find_dummies = function(ext_pat)
|
|
local tmp_path = eval('$PATH')
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
|
matches('null' .. ext_pat, call('exepath', 'null'))
|
|
matches('true' .. ext_pat, call('exepath', 'true'))
|
|
matches('false' .. ext_pat, call('exepath', 'false'))
|
|
command("let $PATH = '" .. tmp_path .. "'")
|
|
end
|
|
|
|
describe('exepath()', function()
|
|
before_each(clear)
|
|
|
|
it('fails for invalid values', function()
|
|
for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do
|
|
eq(
|
|
'Vim(call):E1174: String required for argument 1',
|
|
pcall_err(command, 'call exepath(' .. input .. ')')
|
|
)
|
|
end
|
|
eq(
|
|
'Vim(call):E1175: Non-empty string required for argument 1',
|
|
pcall_err(command, 'call exepath("")')
|
|
)
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
|
for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do
|
|
eq(
|
|
'Vim(call):E1174: String required for argument 1',
|
|
pcall_err(command, 'call exepath(' .. input .. ')')
|
|
)
|
|
end
|
|
end)
|
|
|
|
if is_os('win') then
|
|
it('returns 1 for commands in $PATH (Windows)', function()
|
|
local exe = 'ping'
|
|
matches(exe .. '%.EXE$', call('exepath', exe))
|
|
end)
|
|
|
|
it('append extension if omitted', function()
|
|
local filename = 'cmd'
|
|
local pathext = '.exe'
|
|
clear({ env = { PATHEXT = pathext } })
|
|
eq(call('exepath', filename .. pathext), call('exepath', filename))
|
|
end)
|
|
|
|
it(
|
|
'returns file WITH extension if files both with and without extension exist in $PATH',
|
|
function()
|
|
local ext_pat = '%.CMD$'
|
|
find_dummies(ext_pat)
|
|
set_shell_powershell()
|
|
find_dummies(ext_pat)
|
|
end
|
|
)
|
|
else
|
|
it('returns 1 for commands in $PATH (not Windows)', function()
|
|
local exe = 'ls'
|
|
matches(exe .. '$', call('exepath', exe))
|
|
end)
|
|
|
|
it(
|
|
'returns file WITHOUT extension if files both with and without extension exist in $PATH',
|
|
function()
|
|
find_dummies('$')
|
|
end
|
|
)
|
|
end
|
|
|
|
it('respects shellslash #39524', function()
|
|
t.skip(not is_os('win'), "N/A: 'shellslash' only works on Windows")
|
|
local path = call('exepath', 'cmd.exe') ---@type string
|
|
t.ok(nil == path:find('/'))
|
|
end)
|
|
end)
|