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