Files
neovim/test/functional/legacy/crash_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

77 lines
2.0 KiB
Lua

local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local it, before_each, finally = t.it, t.before_each, t.finally
local assert_alive = n.assert_alive
local clear = n.clear
local command = n.command
local eq = t.eq
local eval = n.eval
local exec = n.exec
local feed = n.feed
local pcall_err = t.pcall_err
before_each(clear)
it('no crash when ending Visual mode while editing buffer closes window', function()
command('new')
command('autocmd ModeChanged v:n ++once close')
feed('v')
command('enew')
assert_alive()
end)
it('no crash when ending Visual mode close the window to switch to', function()
command('new')
command('autocmd ModeChanged v:n ++once only')
feed('v')
command('wincmd p')
assert_alive()
end)
it('no crash when truncating overlong message', function()
pcall(command, 'source test/old/testdir/crash/vim_msg_trunc_poc')
assert_alive()
end)
it('no crash with very long option error message', function()
pcall(command, 'source test/old/testdir/crash/poc_did_set_langmap')
assert_alive()
end)
it('no crash when closing window with tag in loclist', function()
exec([[
new
lexpr ['foo']
lopen
let g:qf_bufnr = bufnr()
lclose
call settagstack(1, #{items: [#{tagname: 'foo', from: [g:qf_bufnr, 1, 1, 0]}]})
]])
eq(1, eval('bufexists(g:qf_bufnr)'))
command('1close')
eq(0, eval('bufexists(g:qf_bufnr)'))
assert_alive()
end)
it('no crash when writing "Untitled" file fails', function()
t.mkdir('Untitled')
finally(function()
vim.uv.fs_rmdir('Untitled')
end)
feed('ifoobar')
command('set bufhidden=unload')
eq('Vim(enew):E502: "Untitled" is a directory', pcall_err(command, 'confirm enew'))
assert_alive()
end)
-- oldtest: Test_crash_bufwrite()
it('no crash when converting buffer with incomplete multibyte chars', function()
command('edit ++bin test/old/testdir/samples/buffer-test.txt')
finally(function()
os.remove('Xoutput')
end)
command('w! ++enc=ucs4 Xoutput')
assert_alive()
end)