2019-01-17 22:11:40 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local eq, clear, call, iswin =
|
|
|
|
helpers.eq, helpers.clear, helpers.call, helpers.iswin
|
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
|
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-11 20:59:43 -07:00
|
|
|
it('returns 1 for commands in $PATH', function()
|
|
|
|
local exe = iswin() and 'ping' or 'ls'
|
|
|
|
local ext_pat = iswin() and '%.EXE$' or '$'
|
|
|
|
matches(exe .. ext_pat, call('exepath', exe))
|
|
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
|
|
|
ext_pat = iswin() and '%.CMD$' or '$'
|
|
|
|
matches('null' .. ext_pat, call('exepath', 'null'))
|
|
|
|
matches('true' .. ext_pat, call('exepath', 'true'))
|
|
|
|
matches('false' .. ext_pat, call('exepath', 'false'))
|
|
|
|
end)
|
|
|
|
|
2020-12-08 18:19:08 -07:00
|
|
|
it('fails for invalid values', function()
|
2021-10-28 19:13:40 -07:00
|
|
|
for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
|
2022-09-11 23:03:32 -07:00
|
|
|
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")')
|
|
|
|
for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do
|
2022-09-11 23:03:32 -07:00
|
|
|
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
|
|
|
|
|
|
|
if iswin() then
|
|
|
|
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)
|
|
|
|
end
|
2019-01-17 22:11:40 -07:00
|
|
|
end)
|