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`.
98 lines
2.6 KiB
Lua
98 lines
2.6 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
|
|
local uv = vim.uv
|
|
require('os')
|
|
|
|
local eval = n.eval
|
|
local command = n.command
|
|
local eq, neq = t.eq, t.neq
|
|
local tempfile = t.tmpname(false)
|
|
local source = n.source
|
|
local matches = t.matches
|
|
local read_file = t.read_file
|
|
|
|
local function assert_file_exists(filepath)
|
|
neq(nil, uv.fs_stat(filepath).uid)
|
|
end
|
|
|
|
local function assert_file_exists_not(filepath)
|
|
eq(nil, uv.fs_stat(filepath))
|
|
end
|
|
|
|
describe(':profile', function()
|
|
before_each(n.clear)
|
|
|
|
after_each(function()
|
|
n.expect_exit(command, 'qall!')
|
|
if uv.fs_stat(tempfile).uid ~= nil then
|
|
-- Delete the tempfile. We just need the name, ignoring any race conditions.
|
|
os.remove(tempfile)
|
|
end
|
|
end)
|
|
|
|
describe('dump', function()
|
|
it('works', function()
|
|
eq(0, eval('v:profiling'))
|
|
command('profile start ' .. tempfile)
|
|
eq(1, eval('v:profiling'))
|
|
assert_file_exists_not(tempfile)
|
|
command('profile dump')
|
|
assert_file_exists(tempfile)
|
|
end)
|
|
|
|
it('not resetting the profile', function()
|
|
source([[
|
|
function! Test()
|
|
endfunction
|
|
]])
|
|
command('profile start ' .. tempfile)
|
|
assert_file_exists_not(tempfile)
|
|
command('profile func Test')
|
|
command('call Test()')
|
|
command('profile dump')
|
|
assert_file_exists(tempfile)
|
|
local profile = read_file(tempfile)
|
|
matches('Called 1 time', profile)
|
|
command('call Test()')
|
|
command('profile dump')
|
|
assert_file_exists(tempfile)
|
|
profile = read_file(tempfile)
|
|
matches('Called 2 time', profile)
|
|
command('profile stop')
|
|
end)
|
|
end)
|
|
|
|
describe('stop', function()
|
|
it('works', function()
|
|
command('profile start ' .. tempfile)
|
|
assert_file_exists_not(tempfile)
|
|
command('profile stop')
|
|
assert_file_exists(tempfile)
|
|
eq(0, eval('v:profiling'))
|
|
end)
|
|
|
|
it('resetting the profile', function()
|
|
source([[
|
|
function! Test()
|
|
endfunction
|
|
]])
|
|
command('profile start ' .. tempfile)
|
|
assert_file_exists_not(tempfile)
|
|
command('profile func Test')
|
|
command('call Test()')
|
|
command('profile stop')
|
|
assert_file_exists(tempfile)
|
|
local profile = read_file(tempfile)
|
|
matches('Called 1 time', profile)
|
|
command('profile start ' .. tempfile)
|
|
command('profile func Test')
|
|
command('call Test()')
|
|
command('profile stop')
|
|
assert_file_exists(tempfile)
|
|
profile = read_file(tempfile)
|
|
matches('Called 1 time', profile)
|
|
end)
|
|
end)
|
|
end)
|