mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 12:49:11 +00:00
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`.
35 lines
1.0 KiB
Lua
35 lines
1.0 KiB
Lua
local t = require('test.unit.testutil')
|
|
local describe = t.describe
|
|
local itp = t.gen_itp(t.it)
|
|
|
|
local ffi = t.ffi
|
|
local cimport = t.cimport
|
|
local to_cstr = t.to_cstr
|
|
local eq = t.eq
|
|
|
|
-- Import terminfo headers
|
|
local terminfo = cimport('./src/nvim/tui/terminfo.h')
|
|
|
|
describe('terminfo_fmt', function()
|
|
itp('stack overflow fails before producing output', function()
|
|
-- Creates a buffer
|
|
local buf = ffi.new('char[256]')
|
|
local buf_end = buf + ffi.sizeof(buf) -- One past end
|
|
|
|
-- Sets input parameters
|
|
local params = ffi.new('TPVAR[9]')
|
|
params[0].num = 65 -- 'A'
|
|
params[0].string = nil
|
|
|
|
-- 20 pushes (TPSTACK nums array limit) then prints one char
|
|
local valid_fmt = string.rep('%p1', 20) .. '%c'
|
|
local valid_n = terminfo.terminfo_fmt(buf, buf_end, to_cstr(valid_fmt), params)
|
|
eq(1, valid_n)
|
|
|
|
-- Overflows with 21 pushes and fails before print
|
|
local overflow_fmt = string.rep('%p1', 21) .. '%c'
|
|
local overflow_n = terminfo.terminfo_fmt(buf, buf_end, to_cstr(overflow_fmt), params)
|
|
eq(0, overflow_n)
|
|
end)
|
|
end)
|