robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
772cfcf267
master
1-- execute old style tests 2 3-- when compared to the testdir/Makefile based approach, this replaces 4-- all wrapper process logic: 5-- Makefile 6-- runnvim.sh and its library test.sh 7-- runnvim.vim (wrapper which runs a nested vim inside a terminal) 8 9-- it DOES NOT not replace the logic running inside the nvim-under-test 10-- runtest.vim and its libraries setup.vim, shared.vim, check.vim 11 12local nvim_bin =vim . v . progpath -- must be absolute 13 14vim . api . nvim_set_current_dir ( 'test/old/testdir/' ) 15 16local function readable ( fn ) 17return vim . fn . filereadable ( fn ) ~= 0 18end 19 20local errlog ='test.log' 21local messages ='messages' 22local starttime ='starttime' 23local gen_opt_log ='gen_opt_test.log' 24 25function oksystem ( args ) 26local res =vim . system ( args , {} ): wait () 27if res . code ~= 0 then 28error ( vim . inspect ( args ) .. ' failed:\n' .. res . stdout .. res . stderr ) 29end 30return res 31end 32 33function clean_output () 34for _ , f in ipairs { errlog , messages , starttime , gen_opt_log , 'opt_test.vim' } do 35vim . uv . fs_unlink ( f ) 36end 37-- check status, some tests mess with perms so this could fail: 38oksystem { 'bash' , '-c' , 'rm -rf X* viminfo test.out test.ok' } 39end 40 41function if_nonempty ( rawtext , name ) 42text =vim . trim ( rawtext ) 43if # text > 0 then 44if name then 45( '== ' .. name ) 46end 47( text ) 48( name and '== END ' .. name or '\n' ) 49end 50end 51 52function if_exists ( fn , name ) 53local fil =io . open ( fn ) 54if fil then 55if_nonempty ( fil : read '*a' , name ) 56fil : close () 57return true 58end 59end 60 61local verbose =vim . env . VERBOSE 62 63function run_nvim ( ... ) 64local cmd =vim . system ( 65{ nvim_bin , '-u' , 'NONE' , '-i' , 'NONE' , '--headless' , ... } , 66{ env ={ VIMRUNTIME ='../../../runtime' } } 67) 68return cmd : wait () 69end 70 71function run_test ( testfile ) 72if not vim . endswith ( testfile , '.vim' ) then 73error 'not an oldtest' 74end 75 76clean_output () 77 78if testfile == 'test_options_all.vim' then 79local res =run_nvim ( 80'-S' , 81'gen_opt_test.vim' , 82'../../../src/nvim/options.lua' , 83'../../../runtime/doc/options.txt' 84) 85 86if if_exists ( gen_opt_log , 'GEN opt_test.vim' ) or res . code > 0 then 87return false 88end 89end 90 91local resfile =string . sub ( testfile , 1 , - 4 ) .. 'res' 92vim . uv . fs_unlink ( resfile ) 93assert ( not readable ( resfile )) 94 95local opts ='set shortmess-=F backupdir=. undodir=. viewdir=.' 96local res =run_nvim ( '--cmd' , opts , '-S' , 'runtest.vim' , testfile ) 97local passed =( readable ( resfile ) and res . code == 0 ) 98 99if_exists ( messages ) 100 101if verbose or not passed then 102if_nonempty ( res . stdout , 'STDOUT' ) 103if_nonempty ( res . stderr , 'STDERR' ) 104-- if_exists(starttime, "starttime") 105if_exists ( errlog , 'test.log' ) 106end 107return passed 108end 109 110local function all_tests () 111local nested_tests ={} 112local alot =io . open ( 'test_alot.vim' ) 113local sourcepat ='^source (test_.*%.vim)$' 114for line in alot : lines () do 115local m =string . match ( line , sourcepat ) 116if m then 117nested_tests [ m ] =true 118end 119end 120alot : close () 121 122local files ={} 123for name , type in vim . fs . dir ( '.' ) do 124match =string . match ( name , '^test_.*%.vim$' ) 125if match then 126if nested_tests [ match ] then 127nested_tests [ match ] =nil 128elseif match == 'test_largefile.vim' then 129-- ignored: uses too much resources to run on CI 130else 131table . insert ( files , match ) 132end 133end 134end 135return files 136end 137 138local files 139if # arg > 0 then 140files ={} 141for _ , a in ipairs ( arg ) do 142table . insert ( files , string . match ( a , '[^/]*$' )) 143end 144else 145files =all_tests () 146end 147 148local count =# files 149local failures ={} 150for i , fil in ipairs ( files ) do 151( 'run: ' , fil ) 152if not run_test ( fil ) then 153table . insert ( failures , fil ) 154end 155end 156 157if # failures > 0 then 158( 'failed:' , vim . inspect ( failures )) 159vim . cmd 'cquit' 160end