Skip to content

Commit 55a1b76

Browse files
committed
ci: headless script tests
1 parent 2267c7d commit 55a1b76

28 files changed

Lines changed: 413 additions & 66 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
rev: [nightly, v0.11.3]
2222
include:
2323
- os: macos-latest
24-
install-deps: brew update && brew install fzf ripgrep fd
24+
install-deps: |
25+
brew update && brew install fzf ripgrep fd gnu-getopt
26+
brew link --force gnu-getopt
2527
- os: windows-latest
2628
install-deps: choco install fzf ripgrep fd
2729
- os: ubuntu-latest

scripts/devicons.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require("nvim-web-devicons").setup({
2+
override_by_extension = {
3+
sol = {
4+
-- icon = "♦",
5+
icon = "",
6+
color = "#a074c4",
7+
name = "Sol"
8+
},
9+
sh = {
10+
icon = "",
11+
color = "#89e051",
12+
cterm_color = "113",
13+
name = "Sh",
14+
},
15+
md = {
16+
icon = "󰍔",
17+
color = "#dddddd",
18+
cterm_color = "239",
19+
name = "Md",
20+
},
21+
norg = {
22+
icon = "",
23+
color = "#97eefc",
24+
name = "Neorg",
25+
},
26+
},
27+
})

scripts/headless_fd.sh

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22

33
BASEDIR=$(cd "$(dirname "$0")" ; pwd -P)
4+
GETOPT=getopt
45

56
usage() {
67
echo "Usage: $0 [options]"
@@ -12,26 +13,31 @@ usage() {
1213
echo "Display Options"
1314
echo "-c, --cwd Working Directory"
1415
echo "-x, --cmd Executed Command (default: fd --color=never)"
15-
echo "-g, --git-icons Git icons [0|1|false|true] (default:false)"
16-
echo "-f, --file-icons File icons [0|1|false|true] (default:true)"
17-
echo "--color Color icons [0|1|false|true] (default:true)"
16+
echo "-g, --git-icons Git icons [false|true] (default:false)"
17+
echo "-f, --file-icons File icons [false|true] (default:true)"
18+
echo "--color Color icons [false|true] (default:true)"
1819
}
1920

2021
# saner programming env: these switches turn some bugs into errors
2122
set -o noclobber -o nounset
2223

24+
# MacOs: `brew install gnu-getopt && brew link --force gnu-getopt`
25+
if [ -x /usr/local/bin/getopt ]; then
26+
GETOPT=/usr/local/bin/getopt
27+
fi
28+
2329
# -allow a command to fail with !’s side effect on errexit
2430
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
25-
getopt --test > /dev/null
31+
$GETOPT --test > /dev/null
2632
if [ $? -ne 4 ]; then
27-
echo '`getopt --test` failed in this environment.'
33+
echo "`$GETOPT --test` failed in this environment."
2834
exit 1
2935
fi
3036

3137
OPTIONS=hd:c:x:f:g:
3238
LONGOPTS=help,debug:,cwd:,file-icons:,git-icons:,color:,cmd:
3339

34-
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
40+
PARSED=$($GETOPT --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
3541
if [ $? -ne 0 ]; then
3642
# e.g. return value is 1
3743
# then getopt has complained about wrong arguments to stdout
@@ -55,17 +61,7 @@ while true; do
5561
exit 0
5662
;;
5763
-d|--debug)
58-
case $2 in
59-
"2"|"v"|"verbose")
60-
debug="v"
61-
;;
62-
"1"|"true")
63-
debug="true"
64-
;;
65-
*)
66-
debug="false"
67-
;;
68-
esac
64+
debug="$2"
6965
shift 2
7066
;;
7167
-c|--cwd)
@@ -78,35 +74,21 @@ while true; do
7874
;;
7975
-f|--file-icons)
8076
case $2 in
81-
"0"|"false")
82-
file_icons="false"
77+
"true"|"srv"|"mini"|"devicons")
78+
file_icons="$2"
8379
;;
8480
*)
85-
file_icons="true"
81+
file_icons="nil"
8682
;;
8783
esac
8884
shift 2
8985
;;
9086
-g|--git-icons)
91-
case $2 in
92-
"0"|"false")
93-
git_icons="false"
94-
;;
95-
*)
96-
git_icons="true"
97-
;;
98-
esac
87+
git_icons="$2"
9988
shift 2
10089
;;
10190
--color)
102-
case $2 in
103-
"0"|"false")
104-
color_icons="false"
105-
;;
106-
*)
107-
color_icons="true"
108-
;;
109-
esac
91+
color_icons="$2"
11092
shift 2
11193
;;
11294
--)
@@ -129,18 +111,38 @@ if [ $# -gt 0 ]; then
129111
exit 4
130112
fi
131113

132-
VIMRUNTIME=/usr/share/nvim/runtime \
133-
/usr/bin/nvim -u NONE -l ${BASEDIR}/../lua/fzf-lua/spawn.lua "return
114+
ICONS_PATH=nil
115+
ICONS_SETUP=nil
116+
117+
if [ $file_icons != "nil" ]; then
118+
if [ $file_icons != "mini" ]; then
119+
if [ -d "${BASEDIR}/../deps/nvim-web-devicons" ]; then
120+
ICONS_PATH="${BASEDIR}/../deps/nvim-web-devicons"
121+
else
122+
ICONS_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy/nvim-web-devicons"
123+
fi
124+
ICONS_SETUP="${BASEDIR}/devicons.lua"
125+
else
126+
if [ -d "${BASEDIR}/../deps/mini.nvim" ]; then
127+
ICONS_PATH="${BASEDIR}/../deps/mini.nvim"
128+
else
129+
ICONS_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy/mini.nvim"
130+
fi
131+
fi
132+
fi
133+
134+
# VIMRUNTIME=/usr/share/nvim/runtime \
135+
nvim -u NONE -l ${BASEDIR}/../lua/fzf-lua/spawn.lua "return
134136
-- opts
135137
{
136138
g = {
137-
--_fzf_lua_server = [[/run/user/1000/fzf-lua.1710687343.12851.1]],
138-
_devicons_path = [[${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lazy/nvim-web-devicons]],
139-
_devicons_setup = [[${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lua/plugins/devicons/setup.lua]],
139+
_fzf_lua_server = #[[${FZF_LUA_SERVER:-}]] > 0 and [[${FZF_LUA_SERVER:-}]] or nil,
140+
_devicons_path = [[${ICONS_PATH}]],
141+
_devicons_setup = [[${ICONS_SETUP}]],
140142
},
141143
_base64 = false,
142144
debug = [[$debug]] == [[v]] and [[v]] or $debug,
143-
file_icons = ${file_icons},
145+
file_icons = [[${file_icons}]] == true or [[${file_icons}]],
144146
git_icons = ${git_icons},
145147
color_icons = ${color_icons},
146148
cmd = [[${cmd:-fd --color=never}]],

tests/files_spec.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ T["files"]["multiprocess"] = new_set({ parametrize = { { false }, { true } } },
4747
previewer = false,
4848
cwd_prompt = false,
4949
multiprocess = multiprocess,
50-
cmd = "rg --files --sort=path -g !tests/**",
50+
-- Test file_ignore_patterns instead of rg filter
51+
file_ignore_patterns = { "^tests" },
52+
cmd = "rg --files --sort=path",
53+
-- cmd = "rg --files --sort=path -g !tests/**",
5154
})
5255
end,
5356
})
@@ -110,7 +113,10 @@ T["files"]["icons"]["defaults"] = new_set({ parametrize = { { "+attrs" }, { "-at
110113
previewer = false,
111114
cwd_prompt = false,
112115
file_icons = icons,
113-
cmd = "rg --files --sort=path -g !tests/**",
116+
-- Test file_ignore_patterns instead of rg filter
117+
file_ignore_patterns = { "^tests" },
118+
cmd = "rg --files --sort=path",
119+
-- cmd = "rg --files --sort=path -g !tests/**",
114120
})
115121
end,
116122
})

tests/headless_spec.lua

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---@diagnostic disable: unused-local, unused-function
2+
local MiniTest = require("mini.test")
3+
local helpers = require("fzf-lua.test.helpers")
4+
local child = helpers.new_child_neovim()
5+
local expect, eq = helpers.expect, helpers.expect.equality
6+
local new_set = MiniTest.new_set
7+
8+
local _mini_path = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "mini.nvim")
9+
if not vim.uv.fs_stat(_mini_path) then
10+
_mini_path = vim.fs.joinpath("deps", "mini.nvim")
11+
end
12+
13+
local _devicons_path = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "nvim-web-devicons")
14+
if not vim.uv.fs_stat(_devicons_path) then
15+
_devicons_path = vim.fs.joinpath("deps", "nvim-web-devicons")
16+
end
17+
18+
local T = helpers.new_set_with_child(child, {
19+
hooks = {
20+
pre_case = function()
21+
child.o.shell = "/bin/sh"
22+
child.o.termguicolors = true
23+
child.o.background = "dark"
24+
child.lua([[M = { devicons = require("fzf-lua.devicons") }]])
25+
end,
26+
},
27+
})
28+
29+
T["headless"] = new_set({})
30+
31+
T["headless"]["file_icons"] = new_set()
32+
33+
local exec_term = function(c, cmd, args)
34+
cmd = cmd or {}
35+
args = args or {}
36+
args.term = true
37+
local serpent = require "fzf-lua.lib.serpent"
38+
cmd = serpent.block(cmd, { comment = false, sortkeys = false })
39+
args = serpent.block(args, { comment = false, sortkeys = false })
40+
local id = c.lua_get(string.format("vim.fn.jobstart(%s, %s)", cmd, args))
41+
eq(tonumber(id) > 0, true)
42+
c.lua(string.format("vim.fn.jobwait({%s})", tostring(id)))
43+
c.wait_until(function()
44+
local lines = c.get_lines()
45+
for i = #lines, 1, -1 do
46+
if lines[i] == "" then
47+
table.remove(lines, i)
48+
end
49+
end
50+
return lines[#lines] == "[Process exited 0]"
51+
end)
52+
end
53+
54+
T["headless"]["file_icons"]["devicons - manual"] = new_set({ parametrize = { { false }, { true } } },
55+
{
56+
function(icons)
57+
helpers.SKIP_IF_WIN()
58+
-- helpers.SKIP_IF_NOT_LINUX()
59+
exec_term(child,
60+
{ "./scripts/headless_fd.sh", "-x", "rg --files --sort=path", "-f", tostring(icons) })
61+
child.expect_screenshot({ ignore_text = { 24 }, ignore_attr = { 25 } })
62+
end,
63+
})
64+
65+
T["headless"]["file_icons"]["server"] = new_set({ parametrize = { { "devicons" }, { "mini" } } }, {
66+
function(icons)
67+
helpers.SKIP_IF_WIN()
68+
-- helpers.SKIP_IF_NOT_LINUX()
69+
if icons == "mini" then
70+
child.lua("vim.opt.runtimepath:append(...)", { _mini_path })
71+
child.lua([[require("mini.icons").setup({})]])
72+
else
73+
child.lua("vim.opt.runtimepath:append(...)", { _devicons_path })
74+
child.lua([[ require("nvim-web-devicons").setup({})]])
75+
end
76+
child.lua([[M.devicons.load()]])
77+
eq(child.lua_get([[M.devicons.plugin_name()]]), icons)
78+
local fzf_lua_server = child.lua_get("vim.g.fzf_lua_server")
79+
eq(#fzf_lua_server > 0, true)
80+
local new_child = helpers.new_child_neovim()
81+
new_child.start()
82+
exec_term(new_child,
83+
{ "./scripts/headless_fd.sh", "-x", "rg --files --sort=path", "-f", icons },
84+
{ env = { ["FZF_LUA_SERVER"] = fzf_lua_server } })
85+
-- Ignore script path and attr the next line
86+
new_child.expect_screenshot({ ignore_text = { 23 }, ignore_attr = { 24 } })
87+
end,
88+
})
89+
90+
return T

tests/screenshots/tests-api_spec.lua---api---fzf_exec---rg---1-+-args-{-1-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────────────────────────────────────╮
5-
04|~ │> 82/82
5+
04|~ │> 83/83
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ LICENSE ││
88
07|~ │ Makefile ││

tests/screenshots/tests-api_spec.lua---api---fzf_exec---rg---1-+-args-{-false-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────────────────────────────────────╮
5-
04|~ │> 83/83
5+
04|~ │> 84/84
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [st] rg --files -g !.git -g !tests/*··││
88
07|~ │ LICENSE ││

tests/screenshots/tests-api_spec.lua---api---fzf_exec---rg---1-+-args-{-true-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────────────────────────────────────╮
5-
04|~ │> 83/83
5+
04|~ │> 84/84
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --files -g !.git -g !tests/*··││
88
07|~ │ LICENSE ││

tests/screenshots/tests-files_spec.lua---files---close-abort---1-+-args-{-'-c-c-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 83/83 (0) │
5+
04|~ │> 84/84 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --files --sort=path -g !test··││
88
07|~ │ LICENSE ││

tests/screenshots/tests-files_spec.lua---files---close-abort---1-+-args-{-'-esc-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 83/83 (0) │
5+
04|~ │> 84/84 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --files --sort=path -g !test··││
88
07|~ │ LICENSE ││

0 commit comments

Comments
 (0)