profile_spec.lua 2.7 KB

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