neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

signal_spec.lua (2704B)


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