Skip to content

Commit ea6d8ce

Browse files
phanenibhagwan
authored andcommitted
ci: remove uncessary attr screenshots (2nd try)
1 parent 9a1f4b6 commit ea6d8ce

12 files changed

+108
-304
lines changed

lua/fzf-lua/test/helpers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ M.new_child_neovim = function()
251251
local screenshot_opts = { redraw = opts.redraw, normalize_paths = opts.normalize_paths }
252252
opts.redraw = nil
253253
opts.force = not not vim.env["update_screenshots"]
254-
MiniTest.expect.reference_screenshot(child.get_screen_lines(screenshot_opts), path, opts)
254+
screenshot.reference_screenshot(child.get_screen_lines(screenshot_opts), path, opts)
255255
end
256256

257257
child.get_buf_lines = function(buf, opts)
@@ -263,7 +263,7 @@ M.new_child_neovim = function()
263263
local screenshot_opts = { redraw = opts.redraw, normalize_paths = opts.normalize_paths }
264264
opts.redraw = nil
265265
opts.force = not not vim.env["update_screenshots"]
266-
MiniTest.expect.reference_screenshot(child.get_buf_lines(buf, screenshot_opts), path, opts)
266+
screenshot.reference_screenshot(child.get_buf_lines(buf, screenshot_opts), path, opts)
267267
end
268268

269269
local wait_timeout = (M.IS_LINUX() and 2000 or 5000)

lua/fzf-lua/test/screenshot.lua

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
-- Used to compare screenshots without "attrs" (highlights)
33
local M = {}
44

5+
---@diagnostic disable: undefined-field, undefined-global
6+
7+
local MiniTest = require("mini.test")
8+
9+
-- get helper module from upvalues
10+
local _, H = debug.getupvalue(MiniTest.expect.reference_screenshot, 1)
11+
512
---@class MiniTestScreenshot
613

714
--- copied over from mini.test
@@ -28,7 +35,7 @@ local function screenshot_new(t)
2835

2936
return setmetatable(t, {
3037
__tostring = function(x)
31-
return string.format("%s\n\n%s", process_screen(x.text), process_screen(x.attr))
38+
return string.format("%s", process_screen(x.text))
3239
end,
3340
})
3441
end
@@ -61,7 +68,7 @@ function M.from_lines(text_lines, attr_lines, opts)
6168
local f = function(x)
6269
return string_to_chars(x)
6370
end
64-
return screenshot_new({ text = vim.tbl_map(f, text_lines), attr = vim.tbl_map(f, attr_linez) })
71+
return screenshot_new({ text = vim.tbl_map(f, text_lines) })
6572
end
6673

6774
function M.fromChildBufLines(child, buf, opts)
@@ -86,4 +93,101 @@ function M.fromChildScreen(child, opts)
8693
return M.from_lines(lines, {}, opts)
8794
end
8895

96+
-- modified version expect path has no attr
97+
local screenshot_read = function(path)
98+
local lines = vim.fn.readfile(path)
99+
local text_lines = vim.list_slice(lines, 2, #lines)
100+
101+
local f = function(x) return H.string_to_chars(x:gsub("^%d+|", "")) end
102+
return screenshot_new({ text = vim.tbl_map(f, text_lines) })
103+
end
104+
105+
106+
-- modified version expect path has no attr
107+
local screenshot_compare = function(screen_ref, screen_obs, opts)
108+
local compare = function(x, y, desc)
109+
if x ~= y then
110+
return false,
111+
("Different %s. Reference: %s. Observed: %s."):format(desc, vim.inspect(x), vim.inspect(y))
112+
end
113+
return true, ""
114+
end
115+
116+
--stylua: ignore start
117+
local ok, cause
118+
ok, cause = compare(#screen_ref.text, #screen_obs.text, "number of `text` lines")
119+
if not ok then return ok, cause end
120+
121+
local lines_to_check, ignore_lines = {}, opts.ignore_lines
122+
for i = 1, #screen_ref.text do
123+
if not vim.tbl_contains(ignore_lines, i) then table.insert(lines_to_check, i) end
124+
end
125+
126+
for _, i in ipairs(lines_to_check) do
127+
ok, cause = compare(#screen_ref.text[i], #screen_obs.text[i],
128+
"number of columns in `text` line " .. i)
129+
if not ok then return ok, cause end
130+
131+
for j = 1, #screen_ref.text[i] do
132+
ok, cause = compare(screen_ref.text[i][j], screen_obs.text[i][j],
133+
string.format("`text` cell at line %s column %s", i, j))
134+
if not ok then return ok, cause end
135+
end
136+
end
137+
--stylua: ignore end
138+
139+
return true, ""
140+
end
141+
142+
M.reference_screenshot = function(screenshot, path, opts)
143+
if screenshot == nil then return true end
144+
145+
opts = vim.tbl_extend("force",
146+
{ force = false, ignore_lines = {}, directory = "tests/screenshots" }, opts or {})
147+
148+
H.cache.n_screenshots = H.cache.n_screenshots + 1
149+
150+
if path == nil then
151+
-- Sanitize path. Replace any control characters, whitespace, OS specific
152+
-- forbidden characters with '-' (with some useful exception)
153+
local linux_forbidden = [[/]]
154+
local windows_forbidden = [[<>:"/\|?*]]
155+
local pattern = string.format("[%%c%%s%s%s]", vim.pesc(linux_forbidden),
156+
vim.pesc(windows_forbidden))
157+
local replacements = setmetatable({ ['"'] = "'" }, { __index = function() return "-" end })
158+
local name = H.case_to_stringid(MiniTest.current.case):gsub(pattern, replacements)
159+
160+
-- Don't end with whitespace or dot (forbidden on Windows)
161+
name = name:gsub("[%s%.]$", "-")
162+
163+
-- TODO: remove `:gsub()` after compatibility with Neovim=0.8 is dropped
164+
path = vim.fs.normalize(opts.directory):gsub("/$", "") .. "/" .. name
165+
166+
-- Deal with multiple screenshots
167+
if H.cache.n_screenshots > 1 then path = path .. string.format("-%03d", H.cache.n_screenshots) end
168+
end
169+
170+
-- If there is no readable screenshot file, create it. Pass with note.
171+
if opts.force or vim.fn.filereadable(path) == 0 then
172+
local dir_path = vim.fn.fnamemodify(path, ":p:h")
173+
vim.fn.mkdir(dir_path, "p")
174+
H.screenshot_write(screenshot, path)
175+
176+
MiniTest.add_note("Created reference screenshot at path " .. vim.inspect(path))
177+
return true
178+
end
179+
180+
local reference = screenshot_read(path)
181+
182+
-- Compare
183+
local are_same, cause = screenshot_compare(reference, screenshot, opts)
184+
185+
if are_same then return true end
186+
187+
local subject = "screenshot equality to reference at " .. vim.inspect(path)
188+
local context = string.format("%s\nReference:\n%s\n\nObserved:\n%s", cause, tostring(reference),
189+
tostring(screenshot))
190+
H.error_expect(subject, context)
191+
end
192+
89193
return M

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'fd'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,0-1 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'find-dir'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,0-1 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'rg'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,0-1 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'devicons',-'-attrs'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,0-1 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'mini',-'-attrs'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,0-1 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---preview-should-work-after-chdir-#1864

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,3 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

tests/screenshots/tests-file-ui_spec.lua---files()---previewer---1-+-args-{-'builtin'-}

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,3 @@
2727
26|
2828
27|
2929
28|-- TERMINAL -- 1,3 All
30-
31-
--|-
32-
01|
33-
02|
34-
03|
35-
04|
36-
05|
37-
06|
38-
07|
39-
08|
40-
09|
41-
10|
42-
11|
43-
12|
44-
13|
45-
14|
46-
15|
47-
16|
48-
17|
49-
18|
50-
19|
51-
20|
52-
21|
53-
22|
54-
23|
55-
24|
56-
25|
57-
26|
58-
27|
59-
28|

0 commit comments

Comments
 (0)