exepath_spec.lua (2362B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local eq, clear, call = t.eq, n.clear, n.call 5 local command = n.command 6 local exc_exec = n.exc_exec 7 local matches = t.matches 8 local is_os = t.is_os 9 local set_shell_powershell = n.set_shell_powershell 10 local eval = n.eval 11 12 local find_dummies = function(ext_pat) 13 local tmp_path = eval('$PATH') 14 command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') 15 matches('null' .. ext_pat, call('exepath', 'null')) 16 matches('true' .. ext_pat, call('exepath', 'true')) 17 matches('false' .. ext_pat, call('exepath', 'false')) 18 command("let $PATH = '" .. tmp_path .. "'") 19 end 20 21 describe('exepath()', function() 22 before_each(clear) 23 24 it('fails for invalid values', function() 25 for _, input in ipairs({ 'v:null', 'v:true', 'v:false', '{}', '[]' }) do 26 eq( 27 'Vim(call):E1174: String required for argument 1', 28 exc_exec('call exepath(' .. input .. ')') 29 ) 30 end 31 eq('Vim(call):E1175: Non-empty string required for argument 1', exc_exec('call exepath("")')) 32 command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")') 33 for _, input in ipairs({ 'v:null', 'v:true', 'v:false' }) do 34 eq( 35 'Vim(call):E1174: String required for argument 1', 36 exc_exec('call exepath(' .. input .. ')') 37 ) 38 end 39 end) 40 41 if is_os('win') then 42 it('returns 1 for commands in $PATH (Windows)', function() 43 local exe = 'ping' 44 matches(exe .. '%.EXE$', call('exepath', exe)) 45 end) 46 47 it('append extension if omitted', function() 48 local filename = 'cmd' 49 local pathext = '.exe' 50 clear({ env = { PATHEXT = pathext } }) 51 eq(call('exepath', filename .. pathext), call('exepath', filename)) 52 end) 53 54 it( 55 'returns file WITH extension if files both with and without extension exist in $PATH', 56 function() 57 local ext_pat = '%.CMD$' 58 find_dummies(ext_pat) 59 set_shell_powershell() 60 find_dummies(ext_pat) 61 end 62 ) 63 else 64 it('returns 1 for commands in $PATH (not Windows)', function() 65 local exe = 'ls' 66 matches(exe .. '$', call('exepath', exe)) 67 end) 68 69 it( 70 'returns file WITHOUT extension if files both with and without extension exist in $PATH', 71 function() 72 find_dummies('$') 73 end 74 ) 75 end 76 end)