Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit a32a70d

Browse files
committed
ci: fix workflow
1 parent 7293a1a commit a32a70d

File tree

3 files changed

+107
-127
lines changed

3 files changed

+107
-127
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
token: ${{ secrets.GITHUB_TOKEN }}
2323
version: latest
24-
args: --check .
24+
args: --check ./lua
2525

2626
documentation:
2727
runs-on: ubuntu-latest

tests/helpers.lua

Lines changed: 89 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,161 +6,160 @@ Helpers.expect = vim.deepcopy(MiniTest.expect)
66

77
-- The error message returned when a test fails.
88
local function errorMessage(str, pattern)
9-
return string.format("Pattern: %s\nObserved string: %s", vim.inspect(pattern), str)
9+
return string.format("Pattern: %s\nObserved string: %s", vim.inspect(pattern), str)
1010
end
1111

1212
-- Check equality of a global `field` against `value` in the given `child` process.
1313
-- @usage global_equality(child, "_G.CommitMsgSgLoaded", true)
1414
Helpers.expect.global_equality = MiniTest.new_expectation(
15-
"variable in child process matches",
16-
function(child, field, value)
17-
return Helpers.expect.equality(child.lua_get(field), value)
18-
end,
19-
errorMessage
15+
"variable in child process matches",
16+
function(child, field, value)
17+
return Helpers.expect.equality(child.lua_get(field), value)
18+
end,
19+
errorMessage
2020
)
2121

2222
-- Check type equality of a global `field` against `value` in the given `child` process.
2323
-- @usage global_type_equality(child, "_G.CommitMsgSgLoaded", "boolean")
2424
Helpers.expect.global_type_equality = MiniTest.new_expectation(
25-
"variable type in child process matches",
26-
function(child, field, value)
27-
return Helpers.expect.global_equality(child, "type(" .. field .. ")", value)
28-
end,
29-
errorMessage
25+
"variable type in child process matches",
26+
function(child, field, value)
27+
return Helpers.expect.global_equality(child, "type(" .. field .. ")", value)
28+
end,
29+
errorMessage
3030
)
3131

3232
-- Check equality of a config `field` against `value` in the given `child` process.
3333
-- @usage option_equality(child, "debug", true)
3434
Helpers.expect.config_equality = MiniTest.new_expectation(
35-
"config option matches",
36-
function(child, field, value)
37-
return Helpers.expect.global_equality(child, "_G.CommitMsgSg.config." .. field, value)
38-
end,
39-
errorMessage
35+
"config option matches",
36+
function(child, field, value)
37+
return Helpers.expect.global_equality(child, "_G.CommitMsgSg.config." .. field, value)
38+
end,
39+
errorMessage
4040
)
4141

4242
-- Check type equality of a config `field` against `value` in the given `child` process.
4343
-- @usage config_type_equality(child, "debug", "boolean")
4444
Helpers.expect.config_type_equality = MiniTest.new_expectation(
45-
"config option type matches",
46-
function(child, field, value)
47-
return Helpers.expect.global_equality(
48-
child,
49-
"type(_G.CommitMsgSg.config." .. field .. ")",
50-
value
51-
)
52-
end,
53-
errorMessage
45+
"config option type matches",
46+
function(child, field, value)
47+
return Helpers.expect.global_equality(
48+
child,
49+
"type(_G.CommitMsgSg.config." .. field .. ")",
50+
value
51+
)
52+
end,
53+
errorMessage
5454
)
5555

5656
-- Check equality of a state `field` against `value` in the given `child` process.
5757
-- @usage state_equality(child, "enabled", true)
5858
Helpers.expect.state_equality = MiniTest.new_expectation(
59-
"state matches",
60-
function(child, field, value)
61-
return Helpers.expect.global_equality(child, "_G.CommitMsgSg.enabled." .. field, value)
62-
end,
63-
errorMessage
59+
"state matches",
60+
function(child, field, value)
61+
return Helpers.expect.global_equality(child, "_G.CommitMsgSg.enabled." .. field, value)
62+
end,
63+
errorMessage
6464
)
6565

6666
-- Check type equality of a state `field` against `value` in the given `child` process.
6767
-- @usage state_type_equality(child, "enabled", "boolean")
6868
Helpers.expect.state_type_equality = MiniTest.new_expectation(
69-
"state type matches",
70-
function(child, field, value)
71-
return Helpers.expect.global_equality(
72-
child,
73-
"type(_G.CommitMsgSg.state." .. field .. ")",
74-
value
75-
)
76-
end,
77-
errorMessage
69+
"state type matches",
70+
function(child, field, value)
71+
return Helpers.expect.global_equality(
72+
child,
73+
"type(_G.CommitMsgSg.state." .. field .. ")",
74+
value
75+
)
76+
end,
77+
errorMessage
7878
)
7979

8080
Helpers.expect.match = MiniTest.new_expectation("string matching", function(str, pattern)
81-
return str:find(pattern) ~= nil
81+
return str:find(pattern) ~= nil
8282
end, errorMessage)
8383

8484
Helpers.expect.no_match = MiniTest.new_expectation("no string matching", function(str, pattern)
85-
return str:find(pattern) == nil
85+
return str:find(pattern) == nil
8686
end, errorMessage)
8787

8888
-- Monkey-patch `MiniTest.new_child_neovim` with helpful wrappers
8989
Helpers.new_child_neovim = function()
90-
local child = MiniTest.new_child_neovim()
90+
local child = MiniTest.new_child_neovim()
9191

92-
local prevent_hanging = function(method)
92+
local prevent_hanging = function(method)
9393
-- stylua: ignore
9494
if not child.is_blocked() then return end
9595

96-
local msg =
97-
string.format("Can not use `child.%s` because child process is blocked.", method)
98-
error(msg)
99-
end
100-
101-
child.setup = function()
102-
child.restart({ "-u", "scripts/minimal_init.lua" })
96+
local msg = string.format("Can not use `child.%s` because child process is blocked.", method)
97+
error(msg)
98+
end
10399

104-
-- Change initial buffer to be readonly. This not only increases execution
105-
-- speed, but more closely resembles manually opened Neovim.
106-
child.bo.readonly = false
107-
end
100+
child.setup = function()
101+
child.restart({ "-u", "scripts/minimal_init.lua" })
108102

109-
child.set_lines = function(arr, start, finish)
110-
prevent_hanging("set_lines")
103+
-- Change initial buffer to be readonly. This not only increases execution
104+
-- speed, but more closely resembles manually opened Neovim.
105+
child.bo.readonly = false
106+
end
111107

112-
if type(arr) == "string" then
113-
arr = vim.split(arr, "\n")
114-
end
108+
child.set_lines = function(arr, start, finish)
109+
prevent_hanging("set_lines")
115110

116-
child.api.nvim_buf_set_lines(0, start or 0, finish or -1, false, arr)
111+
if type(arr) == "string" then
112+
arr = vim.split(arr, "\n")
117113
end
118114

119-
child.get_lines = function(start, finish)
120-
prevent_hanging("get_lines")
115+
child.api.nvim_buf_set_lines(0, start or 0, finish or -1, false, arr)
116+
end
121117

122-
return child.api.nvim_buf_get_lines(0, start or 0, finish or -1, false)
123-
end
118+
child.get_lines = function(start, finish)
119+
prevent_hanging("get_lines")
124120

125-
child.set_cursor = function(line, column, win_id)
126-
prevent_hanging("set_cursor")
121+
return child.api.nvim_buf_get_lines(0, start or 0, finish or -1, false)
122+
end
127123

128-
child.api.nvim_win_set_cursor(win_id or 0, { line, column })
129-
end
124+
child.set_cursor = function(line, column, win_id)
125+
prevent_hanging("set_cursor")
130126

131-
child.get_cursor = function(win_id)
132-
prevent_hanging("get_cursor")
127+
child.api.nvim_win_set_cursor(win_id or 0, { line, column })
128+
end
133129

134-
return child.api.nvim_win_get_cursor(win_id or 0)
135-
end
130+
child.get_cursor = function(win_id)
131+
prevent_hanging("get_cursor")
136132

137-
child.set_size = function(lines, columns)
138-
prevent_hanging("set_size")
133+
return child.api.nvim_win_get_cursor(win_id or 0)
134+
end
139135

140-
if type(lines) == "number" then
141-
child.o.lines = lines
142-
end
136+
child.set_size = function(lines, columns)
137+
prevent_hanging("set_size")
143138

144-
if type(columns) == "number" then
145-
child.o.columns = columns
146-
end
139+
if type(lines) == "number" then
140+
child.o.lines = lines
147141
end
148142

149-
child.get_size = function()
150-
prevent_hanging("get_size")
151-
152-
return { child.o.lines, child.o.columns }
143+
if type(columns) == "number" then
144+
child.o.columns = columns
153145
end
146+
end
154147

155-
child.expect_screenshot = function(opts, path, screenshot_opts)
156-
if child.fn.has("nvim-0.8") == 0 then
157-
MiniTest.skip("Screenshots are tested for Neovim>=0.8 (for simplicity).")
158-
end
148+
child.get_size = function()
149+
prevent_hanging("get_size")
159150

160-
MiniTest.expect.reference_screenshot(child.get_screenshot(screenshot_opts), path, opts)
151+
return { child.o.lines, child.o.columns }
152+
end
153+
154+
child.expect_screenshot = function(opts, path, screenshot_opts)
155+
if child.fn.has("nvim-0.8") == 0 then
156+
MiniTest.skip("Screenshots are tested for Neovim>=0.8 (for simplicity).")
161157
end
162158

163-
return child
159+
MiniTest.expect.reference_screenshot(child.get_screenshot(screenshot_opts), path, opts)
160+
end
161+
162+
return child
164163
end
165164

166165
return Helpers

tests/test_API.lua

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,36 @@ local helpers = dofile("tests/helpers.lua")
44

55
local child = helpers.new_child_neovim()
66
local eq_global, eq_config, eq_state =
7-
helpers.expect.global_equality, helpers.expect.config_equality, helpers.expect.state_equality
7+
helpers.expect.global_equality, helpers.expect.config_equality, helpers.expect.state_equality
88
local eq_type_global, eq_type_config, eq_type_state =
9-
helpers.expect.global_type_equality,
10-
helpers.expect.config_type_equality,
11-
helpers.expect.state_type_equality
9+
helpers.expect.global_type_equality,
10+
helpers.expect.config_type_equality,
11+
helpers.expect.state_type_equality
1212

1313
local T = MiniTest.new_set({
14-
hooks = {
15-
-- This will be executed before every (even nested) case
16-
pre_case = function()
17-
-- Restart child process with custom 'init.lua' script
18-
child.restart({ "-u", "scripts/minimal_init.lua" })
19-
end,
20-
-- This will be executed one after all tests from this set are finished
21-
post_once = child.stop,
22-
},
14+
hooks = {
15+
-- This will be executed before every (even nested) case
16+
pre_case = function()
17+
-- Restart child process with custom 'init.lua' script
18+
child.restart({ "-u", "scripts/minimal_init.lua" })
19+
end,
20+
-- This will be executed one after all tests from this set are finished
21+
post_once = child.stop,
22+
},
2323
})
2424

2525
-- Tests related to the `setup` method.
2626
T["setup()"] = MiniTest.new_set()
2727

28-
T["setup()"]["sets exposed methods and default options value"] = function()
29-
child.lua([[require('commit-msg-sg').setup()]])
30-
31-
-- global object that holds your plugin information
32-
eq_type_global(child, "_G.CommitMsgSg", "table")
33-
34-
-- public methods
35-
eq_type_global(child, "_G.CommitMsgSg.toggle", "function")
36-
eq_type_global(child, "_G.CommitMsgSg.disable", "function")
37-
eq_type_global(child, "_G.CommitMsgSg.enable", "function")
38-
39-
-- config
40-
eq_type_global(child, "_G.CommitMsgSg.config", "table")
41-
42-
-- assert the value, and the type
43-
eq_config(child, "debug", false)
44-
eq_type_config(child, "debug", "boolean")
45-
end
46-
4728
T["setup()"]["overrides default values"] = function()
48-
child.lua([[require('commit-msg-sg').setup({
29+
child.lua([[require('commit-msg-sg').setup({
4930
-- write all the options with a value different than the default ones
5031
debug = true,
5132
})]])
5233

53-
-- assert the value, and the type
54-
eq_config(child, "debug", true)
55-
eq_type_config(child, "debug", "boolean")
34+
-- assert the value, and the type
35+
eq_config(child, "debug", true)
36+
eq_type_config(child, "debug", "boolean")
5637
end
5738

5839
return T

0 commit comments

Comments
 (0)