2019-01-17 22:11:40 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2024-01-02 18:09:18 -07:00
|
|
|
local eq, clear, call = helpers.eq, helpers.clear, helpers.call
|
2020-12-08 18:19:08 -07:00
|
|
|
local command = helpers.command
|
|
|
|
local exc_exec = helpers.exc_exec
|
2020-12-11 20:59:43 -07:00
|
|
|
local matches = helpers.matches
|
2022-11-21 17:13:30 -07:00
|
|
|
local is_os = helpers.is_os
|
2023-01-26 04:06:29 -07:00
|
|
|
local set_shell_powershell = helpers.set_shell_powershell
|
|
|
|
local eval = helpers.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'))
|
2024-01-02 18:09:18 -07:00
|
|
|
command("let $PATH = '" .. tmp_path .. "'")
|
2023-01-26 04:06:29 -07:00
|
|
|
end
|
2019-01-17 22:11:40 -07:00
|
|
|
|
2020-12-08 18:19:08 -07:00
|
|
|
describe('exepath()', function()
|
|
|
|
before_each(clear)
|
2019-01-17 22:11:40 -07:00
|
|
|
|
2020-12-08 18:19:08 -07:00
|
|
|
it('fails for invalid values', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do
|
|
|
|
eq(
|
|
|
|
'Vim(call):E1174: String required for argument 1',
|
|
|
|
exc_exec('call exepath(' .. input .. ')')
|
|
|
|
)
|
2020-12-08 18:19:08 -07:00
|
|
|
end
|
2022-10-26 22:04:08 -07:00
|
|
|
eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")'))
|
2020-12-08 18:19:08 -07:00
|
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
2024-01-02 18:09:18 -07:00
|
|
|
for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do
|
|
|
|
eq(
|
|
|
|
'Vim(call):E1174: String required for argument 1',
|
|
|
|
exc_exec('call exepath(' .. input .. ')')
|
|
|
|
)
|
2020-12-08 18:19:08 -07:00
|
|
|
end
|
2019-01-17 22:11:40 -07:00
|
|
|
end)
|
2020-12-08 18:19:08 -07:00
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2023-01-26 04:06:29 -07:00
|
|
|
it('returns 1 for commands in $PATH (Windows)', function()
|
|
|
|
local exe = 'ping'
|
|
|
|
matches(exe .. '%.EXE$', call('exepath', exe))
|
|
|
|
end)
|
|
|
|
|
2020-12-08 18:19:08 -07:00
|
|
|
it('append extension if omitted', function()
|
|
|
|
local filename = 'cmd'
|
|
|
|
local pathext = '.exe'
|
2024-01-02 18:09:18 -07:00
|
|
|
clear({ env = { PATHEXT = pathext } })
|
|
|
|
eq(call('exepath', filename .. pathext), call('exepath', filename))
|
2020-12-08 18:19:08 -07:00
|
|
|
end)
|
2023-01-26 04:06:29 -07:00
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
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
|
|
|
|
)
|
2023-01-26 04:06:29 -07:00
|
|
|
else
|
|
|
|
it('returns 1 for commands in $PATH (not Windows)', function()
|
|
|
|
local exe = 'ls'
|
|
|
|
matches(exe .. '$', call('exepath', exe))
|
|
|
|
end)
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
it(
|
|
|
|
'returns file WITHOUT extension if files both with and without extension exist in $PATH',
|
|
|
|
function()
|
|
|
|
find_dummies('$')
|
|
|
|
end
|
|
|
|
)
|
2020-12-08 18:19:08 -07:00
|
|
|
end
|
2019-01-17 22:11:40 -07:00
|
|
|
end)
|