signal_spec.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local command = n.command
  5. local eq = t.eq
  6. local fn = n.fn
  7. local next_msg = n.next_msg
  8. local is_os = t.is_os
  9. local skip = t.skip
  10. if skip(is_os('win'), 'Only applies to POSIX systems') then
  11. return
  12. end
  13. local function posix_kill(signame, pid)
  14. os.execute('kill -s ' .. signame .. ' -- ' .. pid .. ' >/dev/null')
  15. end
  16. describe('autocmd Signal', function()
  17. before_each(clear)
  18. it('matches *', function()
  19. command('autocmd Signal * call rpcnotify(1, "foo")')
  20. posix_kill('USR1', fn.getpid())
  21. eq({ 'notification', 'foo', {} }, next_msg())
  22. end)
  23. it('matches SIGUSR1', function()
  24. command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")')
  25. posix_kill('USR1', fn.getpid())
  26. eq({ 'notification', 'foo', {} }, next_msg())
  27. end)
  28. it('matches SIGWINCH', function()
  29. command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")')
  30. posix_kill('WINCH', fn.getpid())
  31. eq({ 'notification', 'foo', {} }, next_msg())
  32. end)
  33. it('does not match unknown patterns', function()
  34. command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")')
  35. posix_kill('USR1', fn.getpid())
  36. eq(nil, next_msg(500))
  37. end)
  38. end)