profile_spec.lua 2.5 KB

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