robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it =t . describe , t . it 5local eq =t . eq 6local is_os =t . is_os 7local skip =t . skip 8local api =n . api 9local clear =n . clear 10 11describe ( "'shell…' option defaults based on $SHELL #28384" , function () 12---@param sh string 13---@param shcf string 14---@param sp string 15---@param srr string 16---@param sxq string 17---@param ssl boolean 18local function expect ( sh , shcf , sp , srr , sxq , ssl ) 19local opt ={ sh =sh , shcf =shcf , sp =sp , srr =srr , sxq =sxq , ssl =ssl } 20for k , v in pairs ( opt ) do 21eq ( v , api . nvim_get_option_info2 ( k , {} ). default ) 22end 23end 24it ( 'cmd.exe' , function () 25skip ( not is_os ( 'win' ), 'N/A: only works on Windows' ) 26clear () 27expect ( 'cmd.exe' , '/s /c' , '2>&1| tee' , '>%s 2>&1' , '"' , false ) 28end ) 29 30it ( 'powershell(PowerShell 5.x)' , function () 31t . skip ( not is_os ( 'win' ), 'N/A: only works on Windows' ) 32clear { 33env ={ SHELL ='powershell' } , 34} 35expect ( 'powershell' , '-Command' , '2>&1| tee' , '>%s 2>&1' , '' , true ) 36end ) 37 38it ( 'pwsh(PowerShell 7.x)' , function () 39clear { 40env ={ SHELL ='pwsh' } , 41} 42expect ( 'pwsh' , '-c' , '2>&1| tee' , '>%s 2>&1' , '' , true ) 43end ) 44 45it ( 'csh' , function () 46clear { 47env ={ SHELL ='csh' } , 48} 49expect ( 'csh' , '-c' , '|& tee' , '>&' , '' , true ) 50end ) 51 52it ( 'bash' , function () 53clear { 54env ={ SHELL ='bash' } , 55} 56expect ( 'bash' , '-c' , '2>&1| tee' , '>%s 2>&1' , '' , true ) 57end ) 58 59it ( 'unknown' , function () 60clear { 61env ={ SHELL ='unknown' } , 62} 63expect ( 64'unknown' , 65'-c' , 66not is_os ( 'win' ) and '| tee' or '2>&1| tee' , 67not is_os ( 'win' ) and '>' or '>%s 2>&1' , 68'' , 69not is_os ( 'win' ) and true or false 70) 71end ) 72 73it ( 'if the path contains spaces' , function () 74clear { 75env ={ SHELL =( '%s/foo bar/bash' ): format ( n . nvim_dir ) } , 76} 77expect (( '"%s/foo bar/bash"' ): format ( n . nvim_dir ), '-c' , '2>&1| tee' , '>%s 2>&1' , '' , true ) 78end ) 79 80it ( 'no crash when the shell path ends in a separator' , function () 81clear { args ={ '--cmd' , 'let &shell = "/bin/"' } } 82eq ( '/bin/' , api . nvim_get_option_value ( 'shell' , {} )) 83end ) 84end )