robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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