mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 20:59: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`.
89 lines
2.6 KiB
Lua
89 lines
2.6 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
local describe, it, before_each = t.describe, t.it, t.before_each
|
|
local clear = n.clear
|
|
local eq = t.eq
|
|
local fn = n.fn
|
|
local neq = t.neq
|
|
local nvim_argv = n.nvim_argv
|
|
local request = n.request
|
|
local retry = t.retry
|
|
local NIL = vim.NIL
|
|
local is_os = t.is_os
|
|
|
|
describe('API', function()
|
|
before_each(clear)
|
|
|
|
describe('nvim_get_proc_children', function()
|
|
it('returns child process ids', function()
|
|
local this_pid = fn.getpid()
|
|
|
|
-- Might be non-zero already (left-over from some other test?),
|
|
-- but this is not what is tested here.
|
|
local initial_children = request('nvim_get_proc_children', this_pid)
|
|
|
|
local job1 = fn.jobstart(nvim_argv)
|
|
retry(nil, nil, function()
|
|
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
|
|
end)
|
|
|
|
local job2 = fn.jobstart(nvim_argv)
|
|
retry(nil, nil, function()
|
|
eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid))
|
|
end)
|
|
|
|
fn.jobstop(job1)
|
|
retry(nil, nil, function()
|
|
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
|
|
end)
|
|
|
|
fn.jobstop(job2)
|
|
retry(nil, nil, function()
|
|
eq(#initial_children, #request('nvim_get_proc_children', this_pid))
|
|
end)
|
|
end)
|
|
|
|
it('validation', function()
|
|
local status, rv = pcall(request, 'nvim_get_proc_children', -1)
|
|
eq(false, status)
|
|
eq("Invalid 'pid': -1", string.match(rv, 'Invalid.*'))
|
|
|
|
status, rv = pcall(request, 'nvim_get_proc_children', 0)
|
|
eq(false, status)
|
|
eq("Invalid 'pid': 0", string.match(rv, 'Invalid.*'))
|
|
|
|
-- Assume PID 99999 does not exist.
|
|
status, rv = pcall(request, 'nvim_get_proc_children', 99999)
|
|
eq(true, status)
|
|
eq({}, rv)
|
|
end)
|
|
end)
|
|
|
|
describe('nvim_get_proc', function()
|
|
it('returns process info', function()
|
|
local pid = fn.getpid()
|
|
local pinfo = request('nvim_get_proc', pid)
|
|
eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name)
|
|
eq(pid, pinfo.pid)
|
|
eq('number', type(pinfo.ppid))
|
|
neq(pid, pinfo.ppid)
|
|
end)
|
|
|
|
it('validation', function()
|
|
local status, rv = pcall(request, 'nvim_get_proc', -1)
|
|
eq(false, status)
|
|
eq("Invalid 'pid': -1", string.match(rv, 'Invalid.*'))
|
|
|
|
status, rv = pcall(request, 'nvim_get_proc', 0)
|
|
eq(false, status)
|
|
eq("Invalid 'pid': 0", string.match(rv, 'Invalid.*'))
|
|
|
|
-- Assume PID 99999 does not exist.
|
|
status, rv = pcall(request, 'nvim_get_proc', 99999)
|
|
eq(true, status)
|
|
eq(NIL, rv)
|
|
end)
|
|
end)
|
|
end)
|