profile_spec.lua (2597B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local uv = vim.uv 4 require('os') 5 6 local eval = n.eval 7 local command = n.command 8 local eq, neq = t.eq, t.neq 9 local tempfile = t.tmpname(false) 10 local source = n.source 11 local matches = t.matches 12 local read_file = t.read_file 13 14 local function assert_file_exists(filepath) 15 neq(nil, uv.fs_stat(filepath).uid) 16 end 17 18 local function assert_file_exists_not(filepath) 19 eq(nil, uv.fs_stat(filepath)) 20 end 21 22 describe(':profile', function() 23 before_each(n.clear) 24 25 after_each(function() 26 n.expect_exit(command, 'qall!') 27 if uv.fs_stat(tempfile).uid ~= nil then 28 -- Delete the tempfile. We just need the name, ignoring any race conditions. 29 os.remove(tempfile) 30 end 31 end) 32 33 describe('dump', function() 34 it('works', function() 35 eq(0, eval('v:profiling')) 36 command('profile start ' .. tempfile) 37 eq(1, eval('v:profiling')) 38 assert_file_exists_not(tempfile) 39 command('profile dump') 40 assert_file_exists(tempfile) 41 end) 42 43 it('not resetting the profile', function() 44 source([[ 45 function! Test() 46 endfunction 47 ]]) 48 command('profile start ' .. tempfile) 49 assert_file_exists_not(tempfile) 50 command('profile func Test') 51 command('call Test()') 52 command('profile dump') 53 assert_file_exists(tempfile) 54 local profile = read_file(tempfile) 55 matches('Called 1 time', profile) 56 command('call Test()') 57 command('profile dump') 58 assert_file_exists(tempfile) 59 profile = read_file(tempfile) 60 matches('Called 2 time', profile) 61 command('profile stop') 62 end) 63 end) 64 65 describe('stop', function() 66 it('works', function() 67 command('profile start ' .. tempfile) 68 assert_file_exists_not(tempfile) 69 command('profile stop') 70 assert_file_exists(tempfile) 71 eq(0, eval('v:profiling')) 72 end) 73 74 it('resetting the profile', function() 75 source([[ 76 function! Test() 77 endfunction 78 ]]) 79 command('profile start ' .. tempfile) 80 assert_file_exists_not(tempfile) 81 command('profile func Test') 82 command('call Test()') 83 command('profile stop') 84 assert_file_exists(tempfile) 85 local profile = read_file(tempfile) 86 matches('Called 1 time', profile) 87 command('profile start ' .. tempfile) 88 command('profile func Test') 89 command('call Test()') 90 command('profile stop') 91 assert_file_exists(tempfile) 92 profile = read_file(tempfile) 93 matches('Called 1 time', profile) 94 end) 95 end) 96 end)