fix(ci): validate config after merge
This commit is contained in:
parent
97c7161c2e
commit
b5b37074fb
4 changed files with 61 additions and 66 deletions
|
|
@ -104,7 +104,7 @@ Here's an example configuration with lazy.nvim: >
|
|||
},
|
||||
},
|
||||
hooks = {
|
||||
before_test = function(ctx) vim.cmd.w() end,
|
||||
before_run = function(ctx) vim.cmd.w() end,
|
||||
before_debug = function(ctx) ... end,
|
||||
setup_code = function(ctx)
|
||||
vim.wo.foldmethod = "marker"
|
||||
|
|
@ -186,7 +186,7 @@ Here's an example configuration with lazy.nvim: >
|
|||
*cp.Hooks*
|
||||
|
||||
Fields: ~
|
||||
• {before_test}? (`function`) Called before test panel opens.
|
||||
• {before_run}? (`function`) Called before test panel opens.
|
||||
`function(ctx: ProblemContext)`
|
||||
• {before_debug}? (`function`) Called before debug compilation.
|
||||
`function(ctx: ProblemContext)`
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
---@field timeout_ms? number
|
||||
|
||||
---@class Hooks
|
||||
---@field before_test? fun(ctx: ProblemContext)
|
||||
---@field before_run? fun(ctx: ProblemContext)
|
||||
---@field before_debug? fun(ctx: ProblemContext)
|
||||
---@field setup_code? fun(ctx: ProblemContext)
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ M.defaults = {
|
|||
contests = {},
|
||||
snippets = {},
|
||||
hooks = {
|
||||
before_test = nil,
|
||||
before_run = nil,
|
||||
before_debug = nil,
|
||||
setup_code = nil,
|
||||
},
|
||||
|
|
@ -112,65 +112,6 @@ function M.setup(user_config)
|
|||
diff = { user_config.diff, { 'table', 'nil' }, true },
|
||||
})
|
||||
|
||||
if user_config.hooks then
|
||||
vim.validate({
|
||||
before_test = {
|
||||
user_config.hooks.before_test,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
before_debug = {
|
||||
user_config.hooks.before_debug,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
setup_code = {
|
||||
user_config.hooks.setup_code,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
if user_config.run_panel then
|
||||
vim.validate({
|
||||
diff_mode = {
|
||||
user_config.run_panel.diff_mode,
|
||||
function(value)
|
||||
return vim.tbl_contains({ 'vim', 'git' }, value)
|
||||
end,
|
||||
"diff_mode must be 'vim' or 'git'",
|
||||
},
|
||||
next_test_key = {
|
||||
user_config.run_panel.next_test_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'next_test_key must be a non-empty string',
|
||||
},
|
||||
prev_test_key = {
|
||||
user_config.run_panel.prev_test_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'prev_test_key must be a non-empty string',
|
||||
},
|
||||
toggle_diff_key = {
|
||||
user_config.run_panel.toggle_diff_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'toggle_diff_key must be a non-empty string',
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
if user_config.diff then
|
||||
vim.validate({
|
||||
git = { user_config.diff.git, { 'table', 'nil' }, true },
|
||||
})
|
||||
end
|
||||
|
||||
if user_config.contests then
|
||||
for contest_name, contest_config in pairs(user_config.contests) do
|
||||
for lang_name, lang_config in pairs(contest_config) do
|
||||
|
|
@ -214,6 +155,60 @@ function M.setup(user_config)
|
|||
|
||||
local config = vim.tbl_deep_extend('force', M.defaults, user_config or {})
|
||||
|
||||
-- Validate merged config values
|
||||
vim.validate({
|
||||
before_run = {
|
||||
config.hooks.before_run,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
before_debug = {
|
||||
config.hooks.before_debug,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
setup_code = {
|
||||
config.hooks.setup_code,
|
||||
{ 'function', 'nil' },
|
||||
true,
|
||||
},
|
||||
})
|
||||
|
||||
vim.validate({
|
||||
diff_mode = {
|
||||
config.run_panel.diff_mode,
|
||||
function(value)
|
||||
return vim.tbl_contains({ 'vim', 'git' }, value)
|
||||
end,
|
||||
"diff_mode must be 'vim' or 'git'",
|
||||
},
|
||||
next_test_key = {
|
||||
config.run_panel.next_test_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'next_test_key must be a non-empty string',
|
||||
},
|
||||
prev_test_key = {
|
||||
config.run_panel.prev_test_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'prev_test_key must be a non-empty string',
|
||||
},
|
||||
toggle_diff_key = {
|
||||
config.run_panel.toggle_diff_key,
|
||||
function(value)
|
||||
return type(value) == 'string' and value ~= ''
|
||||
end,
|
||||
'toggle_diff_key must be a non-empty string',
|
||||
},
|
||||
})
|
||||
|
||||
vim.validate({
|
||||
git = { config.diff.git, { 'table', 'nil' }, true },
|
||||
})
|
||||
|
||||
for _, contest_config in pairs(config.contests) do
|
||||
for lang_name, lang_config in pairs(contest_config) do
|
||||
if type(lang_config) == 'table' and not lang_config.extension then
|
||||
|
|
|
|||
|
|
@ -459,8 +459,8 @@ local function toggle_run_panel(is_debug)
|
|||
|
||||
setup_keybindings_for_buffer(test_buffers.tab_buf)
|
||||
|
||||
if config.hooks and config.hooks.before_test then
|
||||
config.hooks.before_test(ctx)
|
||||
if config.hooks and config.hooks.before_run then
|
||||
config.hooks.before_run(ctx)
|
||||
end
|
||||
|
||||
if is_debug and config.hooks and config.hooks.before_debug then
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ describe('cp.config', function()
|
|||
|
||||
it('validates hook functions', function()
|
||||
local invalid_config = {
|
||||
hooks = { before_test = 'not_a_function' },
|
||||
hooks = { before_run = 'not_a_function' },
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue