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 , finally =t . describe , t . it , t . before_each , t . finally 5local clear =n . clear 6local command =n . command 7local eq =t . eq 8local fn =n . fn 9local next_msg =n . next_msg 10local is_os =t . is_os 11local skip =t . skip 12local read_file =t . read_file 13local feed =n . feed 14local retry =t . retry 15 16if skip ( is_os ( 'win' ), 'N/A: Only applies to POSIX systems' ) then 17return 18end 19 20describe ( "'autowriteall' on signal exit" , function () 21before_each ( clear ) 22 23local function test_deadly_sig ( signame , awa , should_write ) 24local testfile ='Xtest_SIG' .. signame .. ( awa and '_awa' or '_noawa' ) 25local teststr ='Testaaaaaaa' 26finally ( function () 27os . remove ( testfile ) 28end ) 29 30if awa then 31command ( 'set autowriteall' ) 32end 33 34command ( 'edit ' .. testfile ) 35feed ( 'i' .. teststr ) 36vim . uv . kill ( fn . getpid (), signame ) 37 38retry ( nil , 5000 , function () 39eq (( should_write and ( teststr .. '\n' ) or nil ), read_file ( testfile )) 40end ) 41end 42 43it ( 'dont write if SIGTERM & awa on' , function () 44test_deadly_sig ( 'sigterm' , true , false ) 45end ) 46it ( 'dont write if SIGTERM & awa off' , function () 47test_deadly_sig ( 'sigterm' , false , false ) 48end ) 49 50it ( 'write if SIGHUP & awa on' , function () 51test_deadly_sig ( 'sighup' , true , true ) 52end ) 53it ( 'dont write if SIGHUP & awa off' , function () 54test_deadly_sig ( 'sighup' , false , false ) 55end ) 56 57it ( 'write if SIGTSTP & awa on' , function () 58test_deadly_sig ( 'sigtstp' , true , true ) 59end ) 60it ( 'dont write if SIGTSTP & awa off' , function () 61test_deadly_sig ( 'sigtstp' , false , false ) 62end ) 63 64it ( 'write if SIGQUIT & awa on' , function () 65test_deadly_sig ( 'sigquit' , true , true ) 66end ) 67it ( 'dont write if SIGQUIT & awa off' , function () 68test_deadly_sig ( 'sigquit' , false , false ) 69end ) 70it ( 'dont write if SIGINT & awa on' , function () 71test_deadly_sig ( 'sigint' , true , false ) 72end ) 73end ) 74 75describe ( 'autocmd Signal' , function () 76before_each ( clear ) 77 78it ( 'matches *' , function () 79command ( 'autocmd Signal * call rpcnotify(1, "foo")' ) 80vim . uv . kill ( fn . getpid (), 'sigusr1' ) 81eq ( { 'notification' , 'foo' , {} } , next_msg ()) 82end ) 83 84it ( 'matches SIGUSR1' , function () 85command ( 'autocmd Signal SIGUSR1 call rpcnotify(1, "foo")' ) 86vim . uv . kill ( fn . getpid (), 'sigusr1' ) 87eq ( { 'notification' , 'foo' , {} } , next_msg ()) 88end ) 89 90it ( 'matches SIGWINCH' , function () 91command ( 'autocmd Signal SIGWINCH call rpcnotify(1, "foo")' ) 92vim . uv . kill ( fn . getpid (), 'sigwinch' ) 93eq ( { 'notification' , 'foo' , {} } , next_msg ()) 94end ) 95 96it ( 'does not match unknown patterns' , function () 97command ( 'autocmd Signal SIGUSR2 call rpcnotify(1, "foo")' ) 98vim . uv . kill ( fn . getpid (), 'sigusr2' ) 99eq ( nil , next_msg ( 500 )) 100end ) 101end )