robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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