diff options
author | Skoh <101289702+SkohTV@users.noreply.github.com> | 2025-03-31 15:14:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-31 06:14:45 -0700 |
commit | 4dabeff308222307ede8e74a2bd341713a7f7d81 (patch) | |
tree | c033d839e8ef54644ebc849bfc91ab39792fcb91 /test | |
parent | 2e5958186aa36e90199e36de5dd9831ec6aefba3 (diff) | |
download | rneovim-4dabeff308222307ede8e74a2bd341713a7f7d81.tar.gz rneovim-4dabeff308222307ede8e74a2bd341713a7f7d81.tar.bz2 rneovim-4dabeff308222307ede8e74a2bd341713a7f7d81.zip |
feat(editor): 'autowriteall' on SIGHUP/SIGQUIT #32843
Problem:
Upon receiving a deadly signal, Nvim doesn't write buffers even if
the option 'autowriteall' is set.
Solution:
Write to all writable buffers upon SIGHUP or SIGQUIT (but not
SIGTERM), if the option 'autowriteall' is set.
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/autocmd/signal_spec.lua | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index 4416afb3ba..03e991f21c 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -8,39 +8,90 @@ local fn = n.fn local next_msg = n.next_msg local is_os = t.is_os local skip = t.skip +local read_file = t.read_file +local feed = n.feed +local retry = t.retry if skip(is_os('win'), 'Only applies to POSIX systems') then return end -local function posix_kill(signame, pid) - os.execute('kill -s ' .. signame .. ' -- ' .. pid .. ' >/dev/null') -end +describe("'autowriteall' on signal exit", function() + before_each(clear) + + local function test_deadly_sig(signame, awa, should_write) + local testfile = 'Xtest_SIG' .. signame .. (awa and '_awa' or '_noawa') + local teststr = 'Testaaaaaaa' + finally(function() + os.remove(testfile) + end) + + if awa then + command('set autowriteall') + end + + command('edit ' .. testfile) + feed('i' .. teststr) + vim.uv.kill(fn.getpid(), signame) + + retry(nil, 5000, function() + eq((should_write and (teststr .. '\n') or nil), read_file(testfile)) + end) + end + + it('dont write if SIGTERM & awa on', function() + test_deadly_sig('sigterm', true, false) + end) + it('dont write if SIGTERM & awa off', function() + test_deadly_sig('sigterm', false, false) + end) + + it('write if SIGHUP & awa on', function() + test_deadly_sig('sighup', true, true) + end) + it('dont write if SIGHUP & awa off', function() + test_deadly_sig('sighup', false, false) + end) + + it('write if SIGTSTP & awa on', function() + test_deadly_sig('sigtstp', true, true) + end) + it('dont write if SIGTSTP & awa off', function() + test_deadly_sig('sigtstp', false, false) + end) + + it('write if SIGQUIT & awa on', function() + test_deadly_sig('sigquit', true, true) + end) + it('dont write if SIGQUIT & awa off', function() + test_deadly_sig('sigquit', false, false) + end) +end) describe('autocmd Signal', function() before_each(clear) it('matches *', function() command('autocmd Signal * call rpcnotify(1, "foo")') - posix_kill('USR1', fn.getpid()) + vim.uv.kill(fn.getpid(), 'sigusr1') eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGUSR1', function() command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') - posix_kill('USR1', fn.getpid()) + vim.uv.kill(fn.getpid(), 'sigusr1') eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGWINCH', function() command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")') - posix_kill('WINCH', fn.getpid()) + vim.uv.kill(fn.getpid(), 'sigwinch') eq({ 'notification', 'foo', {} }, next_msg()) end) it('does not match unknown patterns', function() command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")') - posix_kill('USR1', fn.getpid()) + vim.uv.kill(fn.getpid(), 'sigusr2') eq(nil, next_msg(500)) end) end) |