Skip to content

Commit 5c37803

Browse files
committed
ci: fix garbage collection test
1 parent a54935b commit 5c37803

4 files changed

Lines changed: 42 additions & 22 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: [ubuntu-latest, macos-latest, windows-latest]
21-
rev: [nightly, v0.11.1]
21+
rev: [nightly, v0.11.2]
2222
include:
2323
- os: macos-latest
2424
install-deps: brew update && brew install fzf ripgrep fd

lua/fzf-lua/shell.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function M.clear_protected()
3838
_protected = {}
3939
end
4040

41+
function M.clear_registry()
42+
_index = 0
43+
_registry = {}
44+
_protected = {}
45+
end
46+
4147
-- creates a new address to listen to messages from actions. This is important
4248
-- if the user is using a custom fixed $NVIM_LISTEN_ADDRESS. Different neovim
4349
-- instances will then use the same path as the address and it causes a mess,

lua/fzf-lua/test/helpers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ local os_detect = {
3535
},
3636
MAC = { name = "MacOS", fn = function() return vim.fn.has("mac") == 1 end },
3737
LINUX = { name = "Linux", fn = function() return vim.fn.has("linux") == 1 end },
38-
STABLE = { name = "Neovim stable", fn = function() return M.NVIM_VERSION() == "0.11.1" end },
38+
STABLE = { name = "Neovim stable", fn = function() return M.NVIM_VERSION() == "0.11.2" end },
3939
NIGHTLY = { name = "Neovim nightly", fn = function() return vim.fn.has("nvim-0.12") == 1 end },
4040
}
4141

@@ -139,7 +139,7 @@ M.new_child_neovim = function()
139139
_G._fzf_load_called = nil
140140
end,
141141
},
142-
-- TODO: why is gc called with builtin with this one?
142+
-- Using _fzf_cli_args so we can test keymap.fzf.load actions.load (api.events)
143143
-- keymap = { fzf = { true, load = function() _G._fzf_load_called = true end } }
144144
fzf_cli_args = "--bind=" .. FzfLua.libuv.shellescape("load:+execute-silent:"
145145
.. FzfLua.shell.stringify_data(function(_, _, _)

tests/win_spec.lua

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,40 @@ T["win"]["hide"]["ensure gc called after win hidden (#1782)"] = function()
3636
return setmetatable(t, mt)
3737
end
3838
]])
39-
child.wait_until(function()
40-
if helpers.IS_WIN() then
41-
local hidden_fzf_bufnr = child.lua_get(
42-
[[(FzfLua.utils.fzf_winobj() or {})._hidden_fzf_bufnr]])
43-
if hidden_fzf_bufnr ~= vim.NIL then
44-
local chan = child.lua_get(([=[vim.bo[%s].channel]=]):format(hidden_fzf_bufnr))
45-
child.api.nvim_chan_send(chan, vim.keycode("<c-c>"))
46-
end
39+
if helpers.IS_WIN() then
40+
local hidden_fzf_bufnr = child.lua_get(
41+
[[(FzfLua.utils.fzf_winobj() or {})._hidden_fzf_bufnr]])
42+
if hidden_fzf_bufnr ~= vim.NIL then
43+
local chan = child.lua_get(([=[vim.bo[%s].channel]=]):format(hidden_fzf_bufnr))
44+
child.api.nvim_chan_send(chan, vim.keycode("<c-c>"))
4745
end
48-
-- TODO: why isn't gc called with the builtin previewr
49-
-- child.lua([[FzfLua.files{ previewer = 'builtin' }]])
50-
child.lua([[FzfLua.files{ previewer = false }]])
51-
child.wait_until(function()
52-
return child.lua_get([[_G._fzf_load_called]]) == true
53-
end)
54-
child.lua([[FzfLua.hide()]])
55-
child.wait_until(function()
56-
return child.lua_get([[_G._fzf_load_called]]) == vim.NIL
57-
end)
58-
child.lua([[collectgarbage('collect')]])
46+
end
47+
child.lua([[FzfLua.files{ previewer = 'builtin' }]])
48+
-- child.lua([[FzfLua.files{ previewer = false }]])
49+
child.wait_until(function()
50+
return child.lua_get([[_G._fzf_load_called]]) == true
51+
end)
52+
child.lua([[FzfLua.hide()]])
53+
child.wait_until(function()
54+
return child.lua_get([[_G._fzf_load_called]]) == vim.NIL
55+
end)
56+
-- Clear the function registry to unref all the stored opts
57+
-- and verify we're cleared by testing the id of a new func
58+
child.lua([[FzfLua.shell.clear_registry()]])
59+
eq(child.lua_get([[FzfLua.shell.register_func(function() end)]]), 1)
60+
-- Open a new picker to unref the hidden window object, since
61+
-- we cleared the registry we need to re-setup the load event
62+
child.lua([[FzfLua.buffers{
63+
previewer = false,
64+
-- both keymap.fzf and actions work here
65+
-- keymap = { fzf = { load = function() _G._fzf_load_called = true end } }
66+
actions = { load = { fn = function() _G._fzf_load_called = true end, exec_silent = true } },
67+
}]])
68+
child.wait_until(function()
69+
return child.lua_get([[_G._fzf_load_called]]) == true
70+
end)
71+
child.lua([[collectgarbage('collect')]])
72+
child.wait_until(function()
5973
return child.lua_get([[_G._gc_called]]) == true
6074
end)
6175
end

0 commit comments

Comments
 (0)