fix(ci): format
This commit is contained in:
parent
d83bc6c306
commit
972d9b1b63
2 changed files with 102 additions and 33 deletions
|
|
@ -10,7 +10,7 @@ describe('cp command parsing', function()
|
||||||
local mock_logger = {
|
local mock_logger = {
|
||||||
log = function(msg, level)
|
log = function(msg, level)
|
||||||
table.insert(logged_messages, { msg = msg, level = level })
|
table.insert(logged_messages, { msg = msg, level = level })
|
||||||
end
|
end,
|
||||||
}
|
}
|
||||||
package.loaded['cp.log'] = mock_logger
|
package.loaded['cp.log'] = mock_logger
|
||||||
end)
|
end)
|
||||||
|
|
@ -120,7 +120,9 @@ describe('cp command parsing', function()
|
||||||
|
|
||||||
local error_logged = false
|
local error_logged = false
|
||||||
for _, log_entry in ipairs(logged_messages) do
|
for _, log_entry in ipairs(logged_messages) do
|
||||||
if log_entry.level == vim.log.levels.ERROR and log_entry.msg:match('--lang requires a value') then
|
if
|
||||||
|
log_entry.level == vim.log.levels.ERROR and log_entry.msg:match('--lang requires a value')
|
||||||
|
then
|
||||||
error_logged = true
|
error_logged = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@ describe('cp.scrape', function()
|
||||||
|
|
||||||
mock_cache = {
|
mock_cache = {
|
||||||
load = function() end,
|
load = function() end,
|
||||||
get_contest_data = function() return nil end,
|
get_contest_data = function()
|
||||||
set_contest_data = function() end
|
return nil
|
||||||
|
end,
|
||||||
|
set_contest_data = function() end,
|
||||||
}
|
}
|
||||||
|
|
||||||
mock_system_calls = {}
|
mock_system_calls = {}
|
||||||
|
|
@ -30,14 +32,15 @@ describe('cp.scrape', function()
|
||||||
if vim.tbl_contains(cmd, 'metadata') then
|
if vim.tbl_contains(cmd, 'metadata') then
|
||||||
result.stdout = '{"success": true, "problems": [{"id": "a", "name": "Test Problem"}]}'
|
result.stdout = '{"success": true, "problems": [{"id": "a", "name": "Test Problem"}]}'
|
||||||
elseif vim.tbl_contains(cmd, 'tests') then
|
elseif vim.tbl_contains(cmd, 'tests') then
|
||||||
result.stdout = '{"success": true, "tests": [{"input": "1 2", "expected": "3"}], "url": "https://example.com"}'
|
result.stdout =
|
||||||
|
'{"success": true, "tests": [{"input": "1 2", "expected": "3"}], "url": "https://example.com"}'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
wait = function()
|
wait = function()
|
||||||
return result
|
return result
|
||||||
end
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -46,15 +49,21 @@ describe('cp.scrape', function()
|
||||||
local original_fn = vim.fn
|
local original_fn = vim.fn
|
||||||
vim.fn = vim.tbl_extend('force', vim.fn, {
|
vim.fn = vim.tbl_extend('force', vim.fn, {
|
||||||
executable = function(cmd)
|
executable = function(cmd)
|
||||||
if cmd == 'uv' then return 1 end
|
if cmd == 'uv' then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
return original_fn.executable(cmd)
|
return original_fn.executable(cmd)
|
||||||
end,
|
end,
|
||||||
isdirectory = function(path)
|
isdirectory = function(path)
|
||||||
if path:match('%.venv$') then return 1 end
|
if path:match('%.venv$') then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
return original_fn.isdirectory(path)
|
return original_fn.isdirectory(path)
|
||||||
end,
|
end,
|
||||||
filereadable = function(path)
|
filereadable = function(path)
|
||||||
if temp_files[path] then return 1 end
|
if temp_files[path] then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
readfile = function(path)
|
readfile = function(path)
|
||||||
|
|
@ -69,7 +78,7 @@ describe('cp.scrape', function()
|
||||||
return path:gsub('%..*$', '')
|
return path:gsub('%..*$', '')
|
||||||
end
|
end
|
||||||
return original_fn.fnamemodify(path, modifier)
|
return original_fn.fnamemodify(path, modifier)
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -115,7 +124,9 @@ describe('cp.scrape', function()
|
||||||
describe('system dependency checks', function()
|
describe('system dependency checks', function()
|
||||||
it('handles missing uv executable', function()
|
it('handles missing uv executable', function()
|
||||||
vim.fn.executable = function(cmd)
|
vim.fn.executable = function(cmd)
|
||||||
if cmd == 'uv' then return 0 end
|
if cmd == 'uv' then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -128,14 +139,28 @@ describe('cp.scrape', function()
|
||||||
it('handles python environment setup failure', function()
|
it('handles python environment setup failure', function()
|
||||||
vim.system = function(cmd, opts)
|
vim.system = function(cmd, opts)
|
||||||
if cmd[1] == 'ping' then
|
if cmd[1] == 'ping' then
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
elseif cmd[1] == 'uv' and cmd[2] == 'sync' then
|
elseif cmd[1] == 'uv' and cmd[2] == 'sync' then
|
||||||
return { wait = function() return { code = 1, stderr = 'setup failed' } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 1, stderr = 'setup failed' }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.fn.isdirectory = function() return 0 end
|
vim.fn.isdirectory = function()
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||||
|
|
||||||
|
|
@ -146,9 +171,17 @@ describe('cp.scrape', function()
|
||||||
it('handles network connectivity issues', function()
|
it('handles network connectivity issues', function()
|
||||||
vim.system = function(cmd, opts)
|
vim.system = function(cmd, opts)
|
||||||
if cmd[1] == 'ping' then
|
if cmd[1] == 'ping' then
|
||||||
return { wait = function() return { code = 1 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 1 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||||
|
|
@ -197,11 +230,23 @@ describe('cp.scrape', function()
|
||||||
it('handles subprocess execution failure', function()
|
it('handles subprocess execution failure', function()
|
||||||
vim.system = function(cmd, opts)
|
vim.system = function(cmd, opts)
|
||||||
if cmd[1] == 'ping' then
|
if cmd[1] == 'ping' then
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
||||||
return { wait = function() return { code = 1, stderr = 'execution failed' } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 1, stderr = 'execution failed' }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||||
|
|
@ -216,11 +261,23 @@ describe('cp.scrape', function()
|
||||||
it('handles invalid json output', function()
|
it('handles invalid json output', function()
|
||||||
vim.system = function(cmd, opts)
|
vim.system = function(cmd, opts)
|
||||||
if cmd[1] == 'ping' then
|
if cmd[1] == 'ping' then
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
||||||
return { wait = function() return { code = 0, stdout = 'invalid json' } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0, stdout = 'invalid json' }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||||
|
|
@ -232,16 +289,26 @@ describe('cp.scrape', function()
|
||||||
it('handles scraper-reported failures', function()
|
it('handles scraper-reported failures', function()
|
||||||
vim.system = function(cmd, opts)
|
vim.system = function(cmd, opts)
|
||||||
if cmd[1] == 'ping' then
|
if cmd[1] == 'ping' then
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
elseif cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then
|
||||||
return { wait = function()
|
return {
|
||||||
return {
|
wait = function()
|
||||||
code = 0,
|
return {
|
||||||
stdout = '{"success": false, "error": "contest not found"}'
|
code = 0,
|
||||||
}
|
stdout = '{"success": false, "error": "contest not found"}',
|
||||||
end }
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return { wait = function() return { code = 0 } end }
|
return {
|
||||||
|
wait = function()
|
||||||
|
return { code = 0 }
|
||||||
|
end,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
local result = scrape.scrape_contest_metadata('atcoder', 'abc123')
|
||||||
|
|
@ -261,7 +328,7 @@ describe('cp.scrape', function()
|
||||||
problem_id = 'a',
|
problem_id = 'a',
|
||||||
problem_name = 'abc123a',
|
problem_name = 'abc123a',
|
||||||
input_file = 'io/abc123a.cpin',
|
input_file = 'io/abc123a.cpin',
|
||||||
expected_file = 'io/abc123a.expected'
|
expected_file = 'io/abc123a.expected',
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -352,7 +419,7 @@ describe('cp.scrape', function()
|
||||||
problem_id = 'a',
|
problem_id = 'a',
|
||||||
problem_name = 'abc123a',
|
problem_name = 'abc123a',
|
||||||
input_file = 'io/abc123a.cpin',
|
input_file = 'io/abc123a.cpin',
|
||||||
expected_file = 'io/abc123a.expected'
|
expected_file = 'io/abc123a.expected',
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.has_error(function()
|
assert.has_error(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue