feat(config): more sophisticated param validation
This commit is contained in:
parent
db85bacd4c
commit
69fc2ecdbb
5 changed files with 221 additions and 43 deletions
|
|
@ -119,6 +119,111 @@ describe('cp.config', function()
|
|||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('auto-configuration', function()
|
||||
it('sets default extensions for cpp and python', function()
|
||||
local user_config = {
|
||||
contests = {
|
||||
test = {
|
||||
cpp = { compile = { 'g++' } },
|
||||
python = { test = { 'python3' } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local result = config.setup(user_config)
|
||||
|
||||
assert.equals('cpp', result.contests.test.cpp.extension)
|
||||
assert.equals('py', result.contests.test.python.extension)
|
||||
end)
|
||||
|
||||
it('sets default_language to cpp when available', function()
|
||||
local user_config = {
|
||||
contests = {
|
||||
test = {
|
||||
cpp = { compile = { 'g++' } },
|
||||
python = { test = { 'python3' } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local result = config.setup(user_config)
|
||||
|
||||
assert.equals('cpp', result.contests.test.default_language)
|
||||
end)
|
||||
|
||||
it('sets default_language to first available when cpp not present', function()
|
||||
local user_config = {
|
||||
contests = {
|
||||
test = {
|
||||
python = { test = { 'python3' } },
|
||||
rust = { compile = { 'rustc' } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local result = config.setup(user_config)
|
||||
|
||||
assert.equals('python', result.contests.test.default_language)
|
||||
end)
|
||||
|
||||
it('preserves explicit default_language', function()
|
||||
local user_config = {
|
||||
contests = {
|
||||
test = {
|
||||
cpp = { compile = { 'g++' } },
|
||||
python = { test = { 'python3' } },
|
||||
default_language = 'python',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local result = config.setup(user_config)
|
||||
|
||||
assert.equals('python', result.contests.test.default_language)
|
||||
end)
|
||||
|
||||
it('errors when no language configurations exist', function()
|
||||
local invalid_config = {
|
||||
contests = {
|
||||
test = {},
|
||||
},
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end, 'No language configurations found for test')
|
||||
end)
|
||||
|
||||
it('validates language names against canonical_filetypes', function()
|
||||
local invalid_config = {
|
||||
contests = {
|
||||
test = {
|
||||
invalid_lang = { compile = { 'gcc' } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end, "Invalid language 'invalid_lang'")
|
||||
end)
|
||||
|
||||
it('validates default_language value', function()
|
||||
local invalid_config = {
|
||||
contests = {
|
||||
test = {
|
||||
cpp = { compile = { 'g++' } },
|
||||
default_language = 'xd',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end, "Invalid default_language 'xd'")
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('default_filename', function()
|
||||
|
|
|
|||
|
|
@ -186,18 +186,15 @@ describe('cp.execute', function()
|
|||
}
|
||||
end
|
||||
|
||||
-- Test the internal execute_command function indirectly
|
||||
local language_config = {
|
||||
run = { '{binary_file}' },
|
||||
}
|
||||
|
||||
-- This would be called by a higher-level function that uses execute_command
|
||||
execute.compile_generic(language_config, { binary_file = './test.run' })
|
||||
end)
|
||||
|
||||
it('handles command execution', function()
|
||||
vim.system = function(_, opts)
|
||||
-- Compilation doesn't set timeout, only text=true
|
||||
if opts then
|
||||
assert.equals(true, opts.text)
|
||||
end
|
||||
|
|
@ -259,8 +256,6 @@ describe('cp.execute', function()
|
|||
|
||||
describe('directory creation', function()
|
||||
it('creates build and io directories', function()
|
||||
-- This tests the ensure_directories function indirectly
|
||||
-- since it's called by other functions
|
||||
local language_config = {
|
||||
compile = { 'mkdir', '-p', 'build', 'io' },
|
||||
}
|
||||
|
|
@ -276,15 +271,10 @@ describe('cp.execute', function()
|
|||
|
||||
describe('language detection', function()
|
||||
it('detects cpp from extension', function()
|
||||
-- This tests get_language_from_file indirectly
|
||||
|
||||
-- Mock the file extension detection
|
||||
vim.fn.fnamemodify = function()
|
||||
return 'cpp'
|
||||
end
|
||||
|
||||
-- The actual function is local, but we can test it indirectly
|
||||
-- through functions that use it
|
||||
assert.has_no_errors(function()
|
||||
execute.compile_generic({}, {})
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ describe('cp.scrape', function()
|
|||
stored_data = { platform = platform, contest_id = contest_id, problems = problems }
|
||||
end
|
||||
|
||||
-- Reload the scraper module to pick up the updated mock
|
||||
package.loaded['cp.scrape'] = nil
|
||||
scrape = require('cp.scrape')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue