2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2024-01-12 05:03:25 -07:00
|
|
|
local uv = vim.uv
|
2024-04-20 08:44:13 -07:00
|
|
|
require('os')
|
2015-04-14 17:14:40 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local eval = n.eval
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq, neq = t.eq, t.neq
|
2024-09-02 10:14:09 -07:00
|
|
|
local tempfile = t.tmpname(false)
|
2024-04-20 08:44:13 -07:00
|
|
|
local source = n.source
|
2024-04-08 02:03:20 -07:00
|
|
|
local matches = t.matches
|
|
|
|
local read_file = t.read_file
|
2015-04-14 17:14:40 -07:00
|
|
|
|
|
|
|
local function assert_file_exists(filepath)
|
2024-01-12 05:03:25 -07:00
|
|
|
neq(nil, uv.fs_stat(filepath).uid)
|
2015-04-14 17:14:40 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local function assert_file_exists_not(filepath)
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, uv.fs_stat(filepath))
|
2015-04-14 17:14:40 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe(':profile', function()
|
2024-04-20 08:44:13 -07:00
|
|
|
before_each(n.clear)
|
2015-04-14 17:14:40 -07:00
|
|
|
|
|
|
|
after_each(function()
|
2024-04-20 08:44:13 -07:00
|
|
|
n.expect_exit(command, 'qall!')
|
2024-01-12 05:03:25 -07:00
|
|
|
if uv.fs_stat(tempfile).uid ~= nil then
|
2024-09-02 10:14:09 -07:00
|
|
|
-- Delete the tempfile. We just need the name, ignoring any race conditions.
|
2015-04-14 17:14:40 -07:00
|
|
|
os.remove(tempfile)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2020-05-08 19:57:59 -07:00
|
|
|
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)
|
2015-04-14 17:14:40 -07:00
|
|
|
end)
|
|
|
|
|
2020-05-08 19:57:59 -07:00
|
|
|
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)
|
2015-04-14 17:14:40 -07:00
|
|
|
end)
|
|
|
|
end)
|