2015-04-14 19:14:40 -05:00
|
|
|
require('os')
|
2024-01-12 06:03:25 -06:00
|
|
|
local uv = vim.uv
|
2015-04-14 19:14:40 -05:00
|
|
|
|
2024-04-09 06:26:16 -05:00
|
|
|
local t = require('test.functional.testutil')()
|
2024-04-08 04:03:20 -05:00
|
|
|
local eval = t.eval
|
|
|
|
local command = t.command
|
|
|
|
local eq, neq = t.eq, t.neq
|
|
|
|
local tempfile = t.tmpname()
|
|
|
|
local source = t.source
|
|
|
|
local matches = t.matches
|
|
|
|
local read_file = t.read_file
|
2015-04-14 19:14:40 -05:00
|
|
|
|
2015-12-29 13:18:16 -06:00
|
|
|
-- tmpname() also creates the file on POSIX systems. Remove it again.
|
2015-04-14 19:14:40 -05:00
|
|
|
-- We just need the name, ignoring any race conditions.
|
2024-01-12 06:03:25 -06:00
|
|
|
if uv.fs_stat(tempfile).uid then
|
2015-04-14 19:14:40 -05:00
|
|
|
os.remove(tempfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function assert_file_exists(filepath)
|
2024-01-12 06:03:25 -06:00
|
|
|
neq(nil, uv.fs_stat(filepath).uid)
|
2015-04-14 19:14:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local function assert_file_exists_not(filepath)
|
2024-01-12 06:03:25 -06:00
|
|
|
eq(nil, uv.fs_stat(filepath))
|
2015-04-14 19:14:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe(':profile', function()
|
2024-04-08 04:03:20 -05:00
|
|
|
before_each(t.clear)
|
2015-04-14 19:14:40 -05:00
|
|
|
|
|
|
|
after_each(function()
|
2024-04-08 04:03:20 -05:00
|
|
|
t.expect_exit(command, 'qall!')
|
2024-01-12 06:03:25 -06:00
|
|
|
if uv.fs_stat(tempfile).uid ~= nil then
|
2015-04-14 19:14:40 -05:00
|
|
|
os.remove(tempfile)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2020-05-08 21:57:59 -05: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 19:14:40 -05:00
|
|
|
end)
|
|
|
|
|
2020-05-08 21:57:59 -05: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 19:14:40 -05:00
|
|
|
end)
|
|
|
|
end)
|