Skip to content

Commit c9a2deb

Browse files
committed
ci: replace child.lua with syntax aware exec_lua
1 parent 1bcac02 commit c9a2deb

6 files changed

Lines changed: 56 additions & 52 deletions

File tree

tests/devicons_spec.lua

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local assert = helpers.assert
55
local child = helpers.new_child_neovim()
66
local expect, eq = helpers.expect, helpers.expect.equality
77
local new_set = MiniTest.new_set
8+
local exec_lua = child.lua
89

910
local _devicons_path = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "nvim-web-devicons")
1011
if not vim.uv.fs_stat(_devicons_path) then
@@ -51,24 +52,24 @@ local T = helpers.new_set_with_child(child, {
5152
pre_case = function()
5253
child.o.termguicolors = true
5354
child.o.background = "dark"
54-
child.lua([[M = { devicons = require("fzf-lua.devicons") }]])
55+
exec_lua([[M = { devicons = require("fzf-lua.devicons") }]])
5556
end,
5657
},
5758
})
5859

5960
T["setup"] = new_set()
6061

6162
T["setup"]["verify lazy load"] = function()
62-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
63+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
6364
-- Shouldn't be loaded after setup
6465
eq(child.lua_get("type(M.devicons)"), "table")
6566
eq(child.lua_get("package.loaded['nvim-web-devicons']"), vim.NIL)
6667
-- eq(child.lua_get([[type(require "nvim-web-devicons")]]), "table")
6768
end
6869

6970
T["setup"]["auto-detect"] = function()
70-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
71-
child.lua([[
71+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
72+
exec_lua([[
7273
require("nvim-web-devicons").setup({})
7374
M.devicons.load()
7475
]])
@@ -77,7 +78,7 @@ T["setup"]["auto-detect"] = function()
7778
end
7879

7980
T["setup"]["_G.devicons_path"] = function()
80-
child.lua(string.format([==[
81+
exec_lua(string.format([==[
8182
_G._devicons_path = [[%s]]
8283
_G._fzf_lua_server = nil
8384
_G._fzf_lua_is_headless = true
@@ -88,8 +89,8 @@ T["setup"]["_G.devicons_path"] = function()
8889
end
8990

9091
T["setup"]["headless RPC, vim.g.fzf_lua_server"] = function()
91-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
92-
child.lua([[M.devicons.load()]])
92+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
93+
exec_lua([[M.devicons.load()]])
9394
eq(child.lua_get([[M.devicons.plugin_name()]]), "devicons")
9495
local fzf_lua_server = child.lua_get("vim.g.fzf_lua_server")
9596
eq(#fzf_lua_server > 0, true)
@@ -110,9 +111,9 @@ T["setup"]["headless RPC, vim.g.fzf_lua_server"] = function()
110111
end
111112

112113
T["setup"]["vim.o.background=dark"] = function()
113-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
114+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
114115
child.o.background = "dark"
115-
child.lua([[M.devicons.load()]])
116+
exec_lua([[M.devicons.load()]])
116117
devicons_are_same("foo/", { "", nil })
117118
devicons_are_same("", { "", "#6d8086" })
118119
devicons_are_same(".", { "", "#6d8086" })
@@ -135,12 +136,12 @@ T["setup"]["vim.o.background=dark"] = function()
135136
end
136137

137138
T["setup"]["vim.o.background=light"] = function()
138-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
139+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
139140
-- NOTE: test bg change with a loaded pkg
140141
child.o.background = "dark"
141-
child.lua([[M.devicons.load()]])
142+
exec_lua([[M.devicons.load()]])
142143
child.o.background = "light"
143-
child.lua([[M.devicons.load()]])
144+
exec_lua([[M.devicons.load()]])
144145
devicons_are_same("foo/", { "", nil })
145146
devicons_are_same("", { "", "#6d8086" })
146147
devicons_are_same(".", { "", "#6d8086" })
@@ -163,10 +164,10 @@ T["setup"]["vim.o.background=light"] = function()
163164
end
164165

165166
T["setup"]["notermguicolors (dark)"] = function()
166-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
167+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
167168
child.o.background = "dark"
168169
child.o.termguicolors = false
169-
child.lua([[M.devicons.load()]])
170+
exec_lua([[M.devicons.load()]])
170171
devicons_are_same("foo/", { "", nil })
171172
devicons_are_same("", { "", "66" })
172173
devicons_are_same(".", { "", "66" })
@@ -188,10 +189,10 @@ T["setup"]["notermguicolors (dark)"] = function()
188189
devicons_are_same("foo.R", { "󰟔", "25" })
189190
end
190191
T["setup"]["notermguicolors (light)"] = function()
191-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
192+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
192193
child.o.background = "light"
193194
child.o.termguicolors = false
194-
child.lua([[M.devicons.load()]])
195+
exec_lua([[M.devicons.load()]])
195196
devicons_are_same("foo/", { "", nil })
196197
devicons_are_same("", { "", "66" })
197198
devicons_are_same(".", { "", "66" })

tests/files_spec.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local helpers = require("fzf-lua.test.helpers")
44
local child = helpers.new_child_neovim()
55
local expect, eq = helpers.expect, helpers.expect.equality
66
local new_set = MiniTest.new_set
7+
local exec_lua = child.lua
78

89
-- Helpers with child processes
910
--stylua: ignore start
@@ -64,8 +65,8 @@ T["files"]["previewer"]["builtin"] = new_set({ parametrize = { { "ci" }, { "buil
6465
if not vim.uv.fs_stat(path) then
6566
path = vim.fs.joinpath("deps", "mini.nvim")
6667
end
67-
child.lua("vim.opt.runtimepath:append(...)", { path })
68-
child.lua([[require("mini.icons").setup({})]])
68+
exec_lua("vim.opt.runtimepath:append(...)", { path })
69+
exec_lua([[require("mini.icons").setup({})]])
6970
end
7071
helpers.FzfLua.files(child, {
7172
__expect_lines = true,
@@ -105,8 +106,8 @@ T["files"]["icons"]["defaults"] = new_set({ parametrize = { { "+attrs" }, { "-at
105106
if not vim.uv.fs_stat(path) then
106107
path = vim.fs.joinpath("deps", plugin)
107108
end
108-
child.lua("vim.opt.runtimepath:append(...)", { path })
109-
child.lua(([[require("%s").setup({})]]):format(icons == "mini" and "mini.icons" or plugin))
109+
exec_lua("vim.opt.runtimepath:append(...)", { path })
110+
exec_lua(([[require("%s").setup({})]]):format(icons == "mini" and "mini.icons" or plugin))
110111
helpers.FzfLua.files(child, {
111112
__expect_lines = not attrs,
112113
hidden = false,
@@ -149,7 +150,7 @@ T["files"]["executable"] = new_set({ parametrize = { { "fd" }, { "rg" }, { "find
149150
table.insert(screen_opts.ignore_text, i)
150151
end
151152
end
152-
child.lua(([[
153+
exec_lua(([[
153154
_G._exec = vim.fn.executable
154155
vim.fn.executable = function(x)
155156
if vim.tbl_contains(%s, x) then return 0 end
@@ -179,7 +180,7 @@ T["files"]["preview should work after chdir #1864"] = function()
179180
previewer = "builtin",
180181
winopts = { preview = { hidden = false } },
181182
__after_open = function()
182-
child.lua([[vim.cmd.cd("./tests")]])
183+
exec_lua([[vim.cmd.cd("./tests")]])
183184
child.type_keys([[<c-n>]])
184185
sleep(100)
185186
end

tests/grep_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local helpers = require("fzf-lua.test.helpers")
44
local child = helpers.new_child_neovim()
55
local expect, eq = helpers.expect, helpers.expect.equality
66
local new_set = MiniTest.new_set
7-
7+
local exec_lua = child.lua
88

99
local T = helpers.new_set_with_child(child)
1010

@@ -24,8 +24,8 @@ T["grep"]["search"]["regex"] = new_set({ parametrize = { { false }, { true } } }
2424
if not vim.uv.fs_stat(path) then
2525
path = vim.fs.joinpath("deps", "nvim-web-devicons")
2626
end
27-
child.lua("vim.opt.runtimepath:append(...)", { path })
28-
child.lua([[require("nvim-web-devicons").setup({})]])
27+
exec_lua("vim.opt.runtimepath:append(...)", { path })
28+
exec_lua([[require("nvim-web-devicons").setup({})]])
2929
helpers.FzfLua.grep(child, {
3030
__expect_lines = true,
3131
__screen_opts = screen_opts,

tests/headless_spec.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local helpers = require("fzf-lua.test.helpers")
44
local child = helpers.new_child_neovim()
55
local expect, eq = helpers.expect, helpers.expect.equality
66
local new_set = MiniTest.new_set
7+
local exec_lua = child.lua
78

89
local _mini_path = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "mini.nvim")
910
if not vim.uv.fs_stat(_mini_path) then
@@ -21,7 +22,7 @@ local T = helpers.new_set_with_child(child, {
2122
child.o.shell = "/bin/sh"
2223
child.o.termguicolors = true
2324
child.o.background = "dark"
24-
child.lua([[M = { devicons = require("fzf-lua.devicons") }]])
25+
exec_lua([[M = { devicons = require("fzf-lua.devicons") }]])
2526
end,
2627
},
2728
})
@@ -67,13 +68,13 @@ T["headless"]["file_icons"]["server"] = new_set({ parametrize = { { "devicons" }
6768
helpers.SKIP_IF_WIN()
6869
-- helpers.SKIP_IF_NOT_LINUX()
6970
if icons == "mini" then
70-
child.lua("vim.opt.runtimepath:append(...)", { _mini_path })
71-
child.lua([[require("mini.icons").setup({})]])
71+
exec_lua("vim.opt.runtimepath:append(...)", { _mini_path })
72+
exec_lua([[require("mini.icons").setup({})]])
7273
else
73-
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
74-
child.lua([[ require("nvim-web-devicons").setup({})]])
74+
exec_lua("vim.opt.runtimepath:append(...)", { _devicons_path })
75+
exec_lua([[ require("nvim-web-devicons").setup({})]])
7576
end
76-
child.lua([[M.devicons.load()]])
77+
exec_lua([[M.devicons.load()]])
7778
eq(child.lua_get([[M.devicons.plugin_name()]]), icons)
7879
local fzf_lua_server = child.lua_get("vim.g.fzf_lua_server")
7980
eq(#fzf_lua_server > 0, true)

tests/minicons_spec.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local assert = helpers.assert
55
local child = helpers.new_child_neovim()
66
local expect, eq = helpers.expect, helpers.expect.equality
77
local new_set = MiniTest.new_set
8+
local exec_lua = child.lua
89

910
-- Setup mini.icons locally
1011
local _mini_path = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "mini.nvim")
@@ -56,7 +57,7 @@ local T = helpers.new_set_with_child(child, {
5657
pre_case = function()
5758
child.o.termguicolors = true
5859
child.o.background = "dark"
59-
child.lua([[M = { devicons = require("fzf-lua.devicons") }]])
60+
exec_lua([[M = { devicons = require("fzf-lua.devicons") }]])
6061
end,
6162
},
6263
})
@@ -71,7 +72,7 @@ T["setup"]["verify lazy load"] = function()
7172
end
7273

7374
T["setup"]["auto-detect"] = function()
74-
child.lua([[
75+
exec_lua([[
7576
require("mini.icons").setup({})
7677
M.devicons.load()
7778
]])
@@ -81,7 +82,7 @@ T["setup"]["auto-detect"] = function()
8182
end
8283

8384
T["setup"]["hlgroup modifications"] = function()
84-
child.lua([[
85+
exec_lua([[
8586
require("mini.icons").setup({})
8687
vim.api.nvim_set_hl(0, "MiniIconsGrey", { default = false, link = "Directory" })
8788
M.devicons.load({ mode = "gui" })
@@ -96,7 +97,7 @@ T["setup"]["hlgroup modifications"] = function()
9697
end
9798

9899
T["setup"]["devicons mock"] = function()
99-
child.lua([[
100+
exec_lua([[
100101
require("mini.icons").mock_nvim_web_devicons()
101102
M.devicons.load({ mode = "gui" })
102103
]])
@@ -106,8 +107,8 @@ T["setup"]["devicons mock"] = function()
106107
end
107108

108109
T["setup"]["headless RPC, vim.g.fzf_lua_server"] = function()
109-
child.lua("vim.opt.runtimepath:append(...)", { _mini_path })
110-
child.lua([[
110+
exec_lua("vim.opt.runtimepath:append(...)", { _mini_path })
111+
exec_lua([[
111112
require("mini.icons").setup({})
112113
M.devicons.load()
113114
]])

tests/win_spec.lua

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ T["win"]["hide"]["ensure gc called after win hidden (#1782)"] = function()
4040
-- Reduce cache size to 20 so functions get evicted quicker
4141
-- otherwise opts refs that are stored in the funcs are never
4242
-- cleared preventing the win object's __gc from being called
43-
child.lua([[FzfLua.shell.cache_set_size(20)]])
43+
exec_lua([[FzfLua.shell.cache_set_size(20)]])
4444
child.wait_until(function()
4545
if helpers.IS_WIN() then
4646
local hidden_fzf_bufnr = child.lua_get(
@@ -50,32 +50,32 @@ T["win"]["hide"]["ensure gc called after win hidden (#1782)"] = function()
5050
child.api.nvim_chan_send(chan, vim.keycode("<c-c>"))
5151
end
5252
end
53-
child.lua([[FzfLua.files{ previewer = 'builtin' }]])
53+
exec_lua([[FzfLua.files{ previewer = 'builtin' }]])
5454
child.wait_until(function()
5555
return child.lua_get([[_G._fzf_load_called]]) == true
5656
end)
57-
child.lua([[FzfLua.hide()]])
57+
exec_lua([[FzfLua.hide()]])
5858
child.wait_until(function()
5959
return child.lua_get([[_G._fzf_load_called]]) == vim.NIL
6060
end)
61-
child.lua([[collectgarbage('collect')]])
61+
exec_lua([[collectgarbage('collect')]])
6262
return child.lua_get([[_G._gc_called]]) == true
6363
end)
6464
-- Restore original cache size
65-
child.lua([[FzfLua.shell.cache_set_size(50)]])
65+
exec_lua([[FzfLua.shell.cache_set_size(50)]])
6666
end
6767

6868
T["win"]["hide"]["buffer deleted after win hidden (#1783)"] = function()
6969
eq(child.lua_get([[_G._fzf_lua_on_create]]), vim.NIL)
70-
child.lua([[FzfLua.files()]])
70+
exec_lua([[FzfLua.files()]])
7171
child.wait_until(function()
7272
return child.lua_get([[_G._fzf_lua_on_create]]) == true
7373
end)
74-
child.lua([[FzfLua.hide()]])
74+
exec_lua([[FzfLua.hide()]])
7575
child.wait_until(function()
7676
return child.lua_get([[_G._fzf_lua_on_create]]) == vim.NIL
7777
end)
78-
child.lua([[
78+
exec_lua([[
7979
vim.cmd("%bd!")
8080
FzfLua.files()
8181
]])
@@ -87,34 +87,34 @@ end
8787
T["win"]["hide"]["can resume after close CTX win (#1936)"] = function()
8888
eq(child.lua_get([[_G._fzf_lua_on_create]]), vim.NIL)
8989
child.cmd([[new]])
90-
child.lua([[FzfLua.files()]])
90+
exec_lua([[FzfLua.files()]])
9191
child.wait_until(function()
9292
return child.lua_get([[_G._fzf_lua_on_create]]) == true
9393
end)
94-
child.lua([[FzfLua.hide()]])
94+
exec_lua([[FzfLua.hide()]])
9595
child.wait_until(function()
9696
return child.lua_get([[_G._fzf_lua_on_create]]) == vim.NIL
9797
end)
9898
child.cmd([[close]])
99-
child.lua([[FzfLua.unhide()]])
99+
exec_lua([[FzfLua.unhide()]])
100100
child.wait_until(function()
101101
return child.lua_get([[_G._fzf_lua_on_create]]) == true
102102
end)
103103
child.type_keys("<c-j>")
104104
child.type_keys("<c-j>")
105105

106106
-- `:quit` on other window should not kill fzf job #2011
107-
child.lua([[FzfLua.hide()]])
107+
exec_lua([[FzfLua.hide()]])
108108
child.wait_until(function()
109109
return child.lua_get([[_G._fzf_lua_on_create]]) == vim.NIL
110110
end)
111111
child.cmd([[new]])
112112
child.cmd([[quit]])
113-
child.lua([[FzfLua.unhide()]])
113+
exec_lua([[FzfLua.unhide()]])
114114
child.wait_until(function()
115115
return child.lua_get([[_G._fzf_lua_on_create]]) == true
116116
end)
117-
child.lua([[FzfLua.hide()]])
117+
exec_lua([[FzfLua.hide()]])
118118
child.wait_until(function()
119119
return child.lua_get([[_G._fzf_lua_on_create]]) == vim.NIL
120120
end)
@@ -127,7 +127,7 @@ end
127127

128128
T["win"]["hide"]["actions on multi-select but zero-match #1961"] = function()
129129
reload({ "hide" })
130-
child.lua([[FzfLua.files{
130+
exec_lua([[FzfLua.files{
131131
-- profile = "hide",
132132
query = "README.md",
133133
fzf_opts = { ["--multi"] = true },

0 commit comments

Comments
 (0)