2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local eq, clear, call, write_file, command = t.eq, n.clear, n.call, t.write_file, n.command
|
|
|
|
local exc_exec = n.exc_exec
|
|
|
|
local eval = n.eval
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
2016-09-01 14:50:26 -07:00
|
|
|
|
|
|
|
describe('executable()', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('returns 1 for commands in $PATH', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
local exe = is_os('win') and 'ping' or 'ls'
|
2016-09-01 14:50:26 -07:00
|
|
|
eq(1, call('executable', exe))
|
2020-12-11 20:59:43 -07:00
|
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
|
|
|
eq(1, call('executable', 'null'))
|
|
|
|
eq(1, call('executable', 'true'))
|
|
|
|
eq(1, call('executable', 'false'))
|
2016-09-01 14:50:26 -07:00
|
|
|
end)
|
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2022-07-17 17:00:08 -07:00
|
|
|
it('exepath respects shellslash', function()
|
|
|
|
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
|
|
|
|
eq(
|
|
|
|
[[test\functional\fixtures\bin\null.CMD]],
|
|
|
|
call('fnamemodify', call('exepath', 'null'), ':.')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-07-17 17:00:08 -07:00
|
|
|
command('set shellslash')
|
|
|
|
eq(
|
|
|
|
'test/functional/fixtures/bin/null.CMD',
|
|
|
|
call('fnamemodify', call('exepath', 'null'), ':.')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-07-17 17:00:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('stdpath respects shellslash', function()
|
|
|
|
eq([[build\Xtest_xdg\share\nvim-data]], call('fnamemodify', call('stdpath', 'data'), ':.'))
|
|
|
|
command('set shellslash')
|
|
|
|
eq('build/Xtest_xdg/share/nvim-data', call('fnamemodify', call('stdpath', 'data'), ':.'))
|
|
|
|
end)
|
|
|
|
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 executable(' .. input .. ')')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2020-12-08 18:19:08 -07:00
|
|
|
end
|
|
|
|
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 executable(' .. input .. ')')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2020-12-08 18:19:08 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-10-28 19:13:40 -07:00
|
|
|
it('returns 0 for empty strings', function()
|
|
|
|
eq(0, call('executable', '""'))
|
|
|
|
end)
|
|
|
|
|
2016-09-01 14:50:26 -07:00
|
|
|
it('returns 0 for non-existent files', function()
|
|
|
|
eq(0, call('executable', 'no_such_file_exists_209ufq23f'))
|
|
|
|
end)
|
|
|
|
|
2017-02-02 05:16:15 -07:00
|
|
|
it('sibling to nvim binary', function()
|
|
|
|
-- Some executable in build/bin/, *not* in $PATH nor CWD.
|
|
|
|
local sibling_exe = 'printargs-test'
|
|
|
|
-- Windows: siblings are in Nvim's "pseudo-$PATH".
|
2022-11-21 17:13:30 -07:00
|
|
|
local expected = is_os('win') and 1 or 0
|
|
|
|
if is_os('win') then
|
2017-02-02 05:16:15 -07:00
|
|
|
eq('arg1=lemon;arg2=sky;arg3=tree;', call('system', sibling_exe .. ' lemon sky tree'))
|
|
|
|
end
|
2019-07-15 08:39:34 -07:00
|
|
|
eq(expected, call('executable', sibling_exe))
|
2017-02-02 05:16:15 -07:00
|
|
|
end)
|
|
|
|
|
2016-09-01 14:50:26 -07:00
|
|
|
describe('exec-bit', function()
|
|
|
|
setup(function()
|
2017-02-02 05:16:15 -07:00
|
|
|
clear()
|
2016-09-01 14:50:26 -07:00
|
|
|
write_file('Xtest_not_executable', 'non-executable file')
|
|
|
|
write_file('Xtest_executable', 'executable file (exec-bit set)')
|
2022-11-21 17:13:30 -07:00
|
|
|
if not is_os('win') then -- N/A for Windows.
|
2016-09-01 14:50:26 -07:00
|
|
|
call('system', { 'chmod', '-x', 'Xtest_not_executable' })
|
|
|
|
call('system', { 'chmod', '+x', 'Xtest_executable' })
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
os.remove('Xtest_not_executable')
|
|
|
|
os.remove('Xtest_executable')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('not set', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
eq(0, call('executable', 'Xtest_not_executable'))
|
|
|
|
eq(0, call('executable', './Xtest_not_executable'))
|
2016-09-01 14:50:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('set, unqualified and not in $PATH', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
eq(0, call('executable', 'Xtest_executable'))
|
2016-09-01 14:50:26 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('set, qualified as a path', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
local expected = is_os('win') and 0 or 1
|
2019-01-17 22:11:40 -07:00
|
|
|
eq(expected, call('executable', './Xtest_executable'))
|
2016-09-01 14:50:26 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('executable() (Windows)', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
if not is_os('win') then
|
|
|
|
pending('N/A for non-windows')
|
|
|
|
return
|
|
|
|
end
|
2016-09-01 14:50:26 -07:00
|
|
|
|
|
|
|
local exts = { 'bat', 'exe', 'com', 'cmd' }
|
|
|
|
setup(function()
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
write_file('test_executable_' .. ext .. '.' .. ext, '')
|
|
|
|
end
|
|
|
|
write_file('test_executable_zzz.zzz', '')
|
|
|
|
end)
|
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
os.remove('test_executable_' .. ext .. '.' .. ext)
|
|
|
|
end
|
|
|
|
os.remove('test_executable_zzz.zzz')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('tries default extensions on a filename if $PATHEXT is empty', function()
|
|
|
|
-- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
|
|
|
|
clear({ env = { PATHEXT = '' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', 'test_executable_' .. ext))
|
|
|
|
end
|
|
|
|
eq(0, call('executable', 'test_executable_zzz'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('tries default extensions on a filepath if $PATHEXT is empty', function()
|
|
|
|
-- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
|
|
|
|
clear({ env = { PATHEXT = '' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', '.\\test_executable_' .. ext))
|
|
|
|
end
|
|
|
|
eq(0, call('executable', '.\\test_executable_zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-07-21 07:37:07 -07:00
|
|
|
it('system([…]), jobstart([…]) use $PATHEXT #9569', function()
|
2023-04-27 00:51:44 -07:00
|
|
|
-- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
|
|
|
|
clear({ env = { PATHEXT = '' } })
|
2019-07-21 07:37:07 -07:00
|
|
|
-- Invoking `cmdscript` should find/execute `cmdscript.cmd`.
|
|
|
|
eq('much success\n', call('system', { 'test/functional/fixtures/cmdscript' }))
|
|
|
|
assert(0 < call('jobstart', { 'test/functional/fixtures/cmdscript' }))
|
|
|
|
end)
|
|
|
|
|
2017-02-03 08:56:31 -07:00
|
|
|
it('full path with extension', function()
|
2023-04-27 00:51:44 -07:00
|
|
|
-- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
|
|
|
|
clear({ env = { PATHEXT = '' } })
|
2017-02-03 08:56:31 -07:00
|
|
|
-- Some executable we can expect in the test env.
|
|
|
|
local exe = 'printargs-test'
|
2019-07-21 07:37:07 -07:00
|
|
|
local exedir = eval("fnamemodify(v:progpath, ':h')")
|
2017-02-03 08:56:31 -07:00
|
|
|
local exepath = exedir .. '/' .. exe .. '.exe'
|
|
|
|
eq(1, call('executable', exepath))
|
|
|
|
eq('arg1=lemon;arg2=sky;arg3=tree;', call('system', exepath .. ' lemon sky tree'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('full path without extension', function()
|
2023-04-27 00:51:44 -07:00
|
|
|
-- Empty $PATHEXT defaults to ".com;.exe;.bat;.cmd".
|
|
|
|
clear({ env = { PATHEXT = '' } })
|
2017-02-03 08:56:31 -07:00
|
|
|
-- Some executable we can expect in the test env.
|
|
|
|
local exe = 'printargs-test'
|
2019-07-21 07:37:07 -07:00
|
|
|
local exedir = eval("fnamemodify(v:progpath, ':h')")
|
2017-02-03 08:56:31 -07:00
|
|
|
local exepath = exedir .. '/' .. exe
|
|
|
|
eq('arg1=lemon;arg2=sky;arg3=tree;', call('system', exepath .. ' lemon sky tree'))
|
|
|
|
eq(1, call('executable', exepath))
|
|
|
|
end)
|
|
|
|
|
2016-09-01 14:50:26 -07:00
|
|
|
it('respects $PATHEXT when trying extensions on a filename', function()
|
|
|
|
clear({ env = { PATHEXT = '.zzz' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(0, call('executable', 'test_executable_' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', 'test_executable_zzz'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('respects $PATHEXT when trying extensions on a filepath', function()
|
|
|
|
clear({ env = { PATHEXT = '.zzz' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(0, call('executable', '.\\test_executable_' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', '.\\test_executable_zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it('with weird $PATHEXT', function()
|
|
|
|
clear({ env = { PATHEXT = ';' } })
|
|
|
|
eq(0, call('executable', '.\\test_executable_zzz'))
|
|
|
|
clear({ env = { PATHEXT = ';;;.zzz;;' } })
|
|
|
|
eq(1, call('executable', '.\\test_executable_zzz'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("unqualified filename, Unix-style 'shell'", function()
|
2016-09-01 14:50:26 -07:00
|
|
|
clear({ env = { PATHEXT = '' } })
|
2019-01-17 22:11:40 -07:00
|
|
|
command('set shell=sh')
|
2016-09-01 14:50:26 -07:00
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', 'test_executable_' .. ext .. '.' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', 'test_executable_zzz.zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it("relative path, Unix-style 'shell' (backslashes)", function()
|
2016-09-01 14:50:26 -07:00
|
|
|
clear({ env = { PATHEXT = '' } })
|
2019-01-17 22:11:40 -07:00
|
|
|
command('set shell=bash.exe')
|
2016-09-01 14:50:26 -07:00
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', '.\\test_executable_' .. ext .. '.' .. ext))
|
|
|
|
eq(1, call('executable', './test_executable_' .. ext .. '.' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', '.\\test_executable_zzz.zzz'))
|
|
|
|
eq(1, call('executable', './test_executable_zzz.zzz'))
|
|
|
|
end)
|
2019-01-17 22:11:40 -07:00
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it('unqualified filename, $PATHEXT contains dot', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
clear({ env = { PATHEXT = '.;.zzz' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', 'test_executable_' .. ext .. '.' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', 'test_executable_zzz.zzz'))
|
|
|
|
clear({ env = { PATHEXT = '.zzz;.' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', 'test_executable_' .. ext .. '.' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', 'test_executable_zzz.zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it('relative path, $PATHEXT contains dot (backslashes)', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
clear({ env = { PATHEXT = '.;.zzz' } })
|
|
|
|
for _, ext in ipairs(exts) do
|
|
|
|
eq(1, call('executable', '.\\test_executable_' .. ext .. '.' .. ext))
|
|
|
|
eq(1, call('executable', './test_executable_' .. ext .. '.' .. ext))
|
|
|
|
end
|
|
|
|
eq(1, call('executable', '.\\test_executable_zzz.zzz'))
|
|
|
|
eq(1, call('executable', './test_executable_zzz.zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it('ignores case of extension', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
clear({ env = { PATHEXT = '.ZZZ' } })
|
|
|
|
eq(1, call('executable', 'test_executable_zzz.zzz'))
|
|
|
|
end)
|
|
|
|
|
2019-04-01 14:21:38 -07:00
|
|
|
it('relative path does not search $PATH', function()
|
2019-01-17 22:11:40 -07:00
|
|
|
clear({ env = { PATHEXT = '' } })
|
|
|
|
eq(0, call('executable', './System32/notepad.exe'))
|
|
|
|
eq(0, call('executable', '.\\System32\\notepad.exe'))
|
|
|
|
eq(0, call('executable', '../notepad.exe'))
|
|
|
|
eq(0, call('executable', '..\\notepad.exe'))
|
|
|
|
end)
|
2016-09-01 14:50:26 -07:00
|
|
|
end)
|