robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4local describe , it , before_each , after_each , finally = 5t . describe , t . it , t . before_each , t . after_each , t . finally 6local uv =vim . uv 7 8local eq =t . eq 9local matches =t . matches 10local eval =n . eval 11local clear =n . clear 12local fn =n . fn 13local write_file =t . write_file 14local is_os =t . is_os 15 16describe ( 'command-line option' , function () 17describe ( '-s' , function () 18local fname ='Xtest-functional-core-main-s' 19local fname_2 =fname .. '.2' 20local nonexistent_fname =fname .. '.nonexistent' 21local dollar_fname ='$' .. fname 22 23before_each ( function () 24clear () 25os . remove ( fname ) 26os . remove ( dollar_fname ) 27end ) 28 29after_each ( function () 30os . remove ( fname ) 31os . remove ( dollar_fname ) 32end ) 33 34it ( 'treats - as stdin' , function () 35eq ( nil , uv . fs_stat ( fname )) 36fn . system ( { 37n . nvim_prog , 38'-u' , 39'NONE' , 40'-i' , 41'NONE' , 42'--headless' , 43'--cmd' , 44'set noswapfile shortmess+=IFW fileformats=unix' , 45'-s' , 46'-' , 47fname , 48} , { ':call setline(1, "42")' , ':wqall!' , '' } ) 49eq ( 0 , eval ( 'v:shell_error' )) 50local attrs =uv . fs_stat ( fname ) 51eq ( # '42\n' , attrs . size ) 52end ) 53 54it ( 'does not expand $VAR' , function () 55eq ( nil , uv . fs_stat ( fname )) 56eq ( true , not not dollar_fname : find ( '%$%w+' )) 57write_file ( dollar_fname , ':call setline(1, "100500")\n:wqall!\n' ) 58local p =n . spawn_wait ( 59'--cmd' , 60'set noswapfile shortmess+=IFW fileformats=unix' , 61'-s' , 62dollar_fname , 63fname 64) 65eq ( 0 , p . status ) 66local attrs =uv . fs_stat ( fname ) 67eq ( # '100500\n' , attrs . size ) 68end ) 69 70it ( 'does not crash when running completion in Ex mode' , function () 71local p = 72n . spawn_wait ( '--clean' , '-e' , '-s' , '--cmd' , 'exe "norm! i\\<C-X>\\<C-V>"' , '--cmd' , 'qa!' ) 73eq ( 0 , p . status ) 74end ) 75 76it ( 'does not crash when running completion from -l script' , function () 77local lua_fname ='Xinscompl.lua' 78write_file ( lua_fname , [=[vim.cmd([[exe "norm! i\<C-X>\<C-V>"]])]=] ) 79finally ( function () 80os . remove ( lua_fname ) 81end ) 82local p =n . spawn_wait ( '--clean' , '-l' , lua_fname ) 83eq ( 0 , p . status ) 84end ) 85 86it ( 'does not crash after reading from stdin in non-headless mode' , function () 87-- Repro from fdfa1ed (2017): the empty `echo ""` pipe makes scriptin (`-s -`) hit EOF 88-- immediately and call closescript(); if scriptin held fd 0 directly, libuv asserts. 89-- 90-- Note: can't use nvim_chan_send because pty stdin never EOFs. 91local nvim_set ='set noswapfile shortmess+=IFW fileformats=unix notermguicolors' 92local shell_cmd =( [[echo "" | %s "%s" --clean --cmd "%s" -s -]] ): format ( 93is_os ( 'win' ) and '&' or '' , 94n . nvim_prog , 95nvim_set 96) 97if is_os ( 'win' ) then 98-- Use PowerShell; cmd.exe mis-parses libuv's `\"…\"` (MSVCRT quoting). 99n . set_shell_powershell () 100end 101local screen =Screen . new ( 40 , 8 ) 102fn . jobstart ( shell_cmd , { 103term =true , 104env ={ VIMRUNTIME =os . getenv ( 'VIMRUNTIME' ) } , 105} ) 106-- First screen confirms Nvim reached TUI (didn't crash closing scriptin). 107screen : expect ( 108[[ 109^ | 110~ |*4 111{1:[No Name] 0,0-1 All}| 112|*2 113]] , 114{ [ 1 ] ={ reverse =true } } 115) 116 117-- Exit with code 42 to avoid false positives. 118n . feed ( 'i:cq 42<CR>' ) 119 120if is_os ( 'win' ) then 121-- XXX: `:cq 42` isn't reaching Nvim, or Nvim exits 1 anyway? 122screen : expect ( { any ='%[Process exited 1%]' } ) 123else 124screen : expect ( { any ='%[Process exited 42%]' } ) 125end 126--[=[ Example of incorrect output: 127screen:expect([[ 128^nvim: /var/tmp/portage/dev-libs/libuv-1.| 12910.2/work/libuv-1.10.2/src/unix/core.c:5| 13019: uv__close: Assertion `fd > STDERR_FI| 131LENO' failed. | 132| 133[Process exited 6] | 134|*2 135]]) 136]=] 137end ) 138 139it ( 'fails when trying to use nonexistent file with -s' , function () 140local p =n . spawn_wait ( 141'--cmd' , 142'set noswapfile shortmess+=IFW fileformats=unix' , 143'--cmd' , 144'language C' , 145'-s' , 146nonexistent_fname 147) 148eq ( 149'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n' , 150--- TODO(justinmk): using `p.output` because Nvim emits CRLF even on non-Win. Emit LF instead? 151p : output () 152) 153eq ( 2 , p . status ) 154end ) 155 156it ( 'errors out when trying to use -s twice' , function () 157write_file ( fname , ':call setline(1, "1")\n:wqall!\n' ) 158write_file ( dollar_fname , ':call setline(1, "2")\n:wqall!\n' ) 159local p =n . spawn_wait ( 160'--cmd' , 161'set noswapfile shortmess+=IFW fileformats=unix' , 162'--cmd' , 163'language C' , 164'-s' , 165fname , 166'-s' , 167dollar_fname , 168fname_2 169) 170--- TODO(justinmk): using `p.output` because Nvim emits CRLF even on non-Win. Emit LF instead? 171eq ( 'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n' , p : output ()) 172eq ( 2 , p . status ) 173eq ( nil , uv . fs_stat ( fname_2 )) 174end ) 175end ) 176 177it ( 'nvim -v, :version' , function () 178matches ( 'Run ":verbose version"' , fn . execute ( ':version' )) 179matches ( 'fall%-back for %$VIM: .*Run :checkhealth' , fn . execute ( ':verbose version' )) 180matches ( 'Run "nvim %-V1 %-v"' , n . spawn_wait ( '-v' ). stdout ) 181matches ( 'fall%-back for %$VIM: .*Run :checkhealth' , n . spawn_wait ( '-V1' , '-v' ). stdout ) 182end ) 183end ) 184 185describe ( 'vim._core' , function () 186it ( 'works with "-u NONE" and no VIMRUNTIME' , function () 187clear { 188args_rm ={ '-u' } , 189args ={ '-u' , 'NONE' } , 190env ={ VIMRUNTIME ='non-existent' } , 191} 192 193-- `vim.hl` is NOT a builtin module. 194t . matches ( "^module 'vim%.hl' not found:" , t . pcall_err ( n . exec_lua , [[require('vim.hl')]] )) 195 196-- All `vim._core.*` modules are builtin. 197t . eq ( 198{ 'ex_session_restart' , 'rebind_after_restart' , 'serverlist' } , 199n . exec_lua ( [[local k = vim.tbl_keys(require('vim._core.server')); table.sort(k); return k]] ) 200) 201local expected ={ 202'vim.F' , 203'vim._core.cmdwin' , 204'vim._core.defaults' , 205'vim._core.editor' , 206'vim._core.ex_cmd' , 207'vim._core.exmode' , 208'vim._core.exrc' , 209'vim._core.help' , 210'vim._core.log' , 211'vim._core.marks' , 212'vim._core.mcursor' , 213'vim._core.options' , 214'vim._core.proc' , 215'vim._core.server' , 216'vim._core.shared' , 217'vim._core.spell' , 218'vim._core.stringbuffer' , 219'vim._core.swapfile' , 220'vim._core.system' , 221'vim._core.table' , 222'vim._core.tag' , 223'vim._core.time' , 224'vim._core.ui' , 225'vim._core.ui2' , 226'vim._core.util' , 227'vim._core.vimfn' , 228'vim._init_packages' , 229'vim.filetype' , 230'vim.fs' , 231'vim.inspect' , 232'vim.keymap' , 233'vim.loader' , 234'vim.text' , 235'vim.tty' , 236} 237if n . exec_lua [[return not not _G.jit]] then 238expected =vim . list_extend ( { 239'ffi' , 240'jit.profile' , 241'jit.util' , 242'string.buffer' , 243'table.clear' , 244'table.new' , 245} , expected ) 246end 247t . eq ( expected , n . exec_lua ( [[local t = vim.tbl_keys(package.preload); table.sort(t); return t]] )) 248end ) 249end )