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