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 clear =n . clear 6local eq =t . eq 7local fn =n . fn 8local neq =t . neq 9local nvim_argv =n . nvim_argv 10local request =n . request 11local retry =t . retry 12local NIL =vim . NIL 13local is_os =t . is_os 14 15describe ( 'API' , function () 16before_each ( clear ) 17 18describe ( 'nvim_get_proc_children' , function () 19it ( 'returns child process ids' , function () 20local this_pid =fn . getpid () 21 22-- Might be non-zero already (left-over from some other test?), 23-- but this is not what is tested here. 24local initial_children =request ( 'nvim_get_proc_children' , this_pid ) 25 26local job1 =fn . jobstart ( nvim_argv ) 27retry ( nil , nil , function () 28eq ( # initial_children + 1 , # request ( 'nvim_get_proc_children' , this_pid )) 29end ) 30 31local job2 =fn . jobstart ( nvim_argv ) 32retry ( nil , nil , function () 33eq ( # initial_children + 2 , # request ( 'nvim_get_proc_children' , this_pid )) 34end ) 35 36fn . jobstop ( job1 ) 37retry ( nil , nil , function () 38eq ( # initial_children + 1 , # request ( 'nvim_get_proc_children' , this_pid )) 39end ) 40 41fn . jobstop ( job2 ) 42retry ( nil , nil , function () 43eq ( # initial_children , # request ( 'nvim_get_proc_children' , this_pid )) 44end ) 45end ) 46 47it ( 'validation' , function () 48local status , rv =pcall ( request , 'nvim_get_proc_children' , - 1 ) 49eq ( false , status ) 50eq ( "Invalid 'pid': -1" , string . match ( rv , 'Invalid.*' )) 51 52status , rv =pcall ( request , 'nvim_get_proc_children' , 0 ) 53eq ( false , status ) 54eq ( "Invalid 'pid': 0" , string . match ( rv , 'Invalid.*' )) 55 56-- Assume PID 99999 does not exist. 57status , rv =pcall ( request , 'nvim_get_proc_children' , 99999 ) 58eq ( true , status ) 59eq ( {} , rv ) 60end ) 61end ) 62 63describe ( 'nvim_get_proc' , function () 64it ( 'returns process info' , function () 65local pid =fn . getpid () 66local pinfo =request ( 'nvim_get_proc' , pid ) 67eq (( is_os ( 'win' ) and 'nvim.exe' or 'nvim' ), pinfo . name ) 68eq ( pid , pinfo . pid ) 69eq ( 'number' , type ( pinfo . ppid )) 70neq ( pid , pinfo . ppid ) 71end ) 72 73it ( 'validation' , function () 74local status , rv =pcall ( request , 'nvim_get_proc' , - 1 ) 75eq ( false , status ) 76eq ( "Invalid 'pid': -1" , string . match ( rv , 'Invalid.*' )) 77 78status , rv =pcall ( request , 'nvim_get_proc' , 0 ) 79eq ( false , status ) 80eq ( "Invalid 'pid': 0" , string . match ( rv , 'Invalid.*' )) 81 82-- Assume PID 99999 does not exist. 83status , rv =pcall ( request , 'nvim_get_proc' , 99999 ) 84eq ( true , status ) 85eq ( NIL , rv ) 86end ) 87end ) 88end )