robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local uv =vim . uv 2 3---@return string 4local function repo_root () 5local source =debug . getinfo ( 1 , 'S' ). source 6assert ( type ( source ) == 'string' and vim . startswith ( source , '@' ), 'failed to resolve runner path' ) 7local script_path =assert ( uv . fs_realpath ( source : sub ( 2 )), 'failed to resolve runner path' ) 8return vim . fs . dirname ( vim . fs . dirname ( script_path )) 9end 10 11---@param roots string[] 12local function prepend_package_roots ( roots ) 13local entries ={} 14for _ , root in ipairs ( roots ) do 15entries [ # entries + 1 ] =root .. '/?.lua' 16entries [ # entries + 1 ] =root .. '/?/init.lua' 17end 18 19package . path =table . concat ( entries , ';' ) .. ';' .. package . path 20end 21 22_G . c_include_path ={} 23while _G . arg [ 1 ] and vim . startswith ( _G . arg [ 1 ], '-I' ) do 24table . insert ( _G . c_include_path , string . sub ( table . remove ( _G . arg , 1 ), 3 )) 25end 26-- TODO(bfredl): use also for cmake? 27if _G . arg [ 1 ] and vim . startswith ( _G . arg [ 1 ], '-P' ) then 28local build_dir =string . sub ( table . remove ( _G . arg , 1 ), 3 ) 29_G . nvim_build_dir =build_dir 30 31-- TMPDIR: for testutil.tmpname() and Nvim tempname(). 32vim . env . TMPDIR =build_dir .. '/Xtest_tmpdir' 33vim . fn . mkdir ( vim . env . TMPDIR , 'p' ) 34end 35if _G . arg [ 1 ] and vim . startswith ( _G . arg [ 1 ], '-X' ) then 36local xdg_dir =string . sub ( table . remove ( _G . arg , 1 ), 3 ) 37vim . env . NVIM_RPLUGIN_MANIFEST =xdg_dir .. '/Xtest_rplugin_manifest' 38vim . env . XDG_CONFIG_HOME =xdg_dir .. '/config' 39vim . env . XDG_DATA_HOME =xdg_dir .. '/share' 40vim . env . XDG_STATE_HOME =xdg_dir .. '/state' 41if vim . fn . has ( 'win32' ) == 0 then 42-- Socket dir (stdpath("run")), deliberately NOT in the build dir. sockaddr_un.sun_path is 104 43-- bytes on macOS/BSD, "/…/build/tmp/nvim.<pid>.<n>" can exceed it. #38623 44vim . env . XDG_RUNTIME_DIR =( '/tmp/nvim_%d' ): format ( vim . uv . os_getpid ()) 45vim . fn . mkdir ( vim . env . XDG_RUNTIME_DIR , 'p' ) 46end 47end 48 49local root =repo_root () 50prepend_package_roots ( { root , root .. '/test' , '.' , './test' } ) 51local entries ={ root .. '/src/?.lua' , root .. '/runtime/lua/?.lua' } 52package . path =table . concat ( entries , ';' ) .. ';' .. package . path 53vim . env . VIMRUNTIME =root .. '/runtime' 54 55-- The harness is not an Nvim instance under test. If its startup server stays 56-- visible, serverlist({ peer = true }) can connect back to the runner and wait 57-- forever for an RPC response. 58if vim . v . servername ~= '' then 59assert ( vim . fn . serverstop ( vim . v . servername ) == 1 ) 60end 61 62local exit_code =require ( 'test.harness' ). main ( _G . arg ) 63io . stdout : flush () 64io . stderr : flush () 65 66os . exit ( exit_code )