fix: revert multiple test cases
This commit is contained in:
parent
cf192fad83
commit
e10eab22d6
7 changed files with 51 additions and 329 deletions
|
|
@ -203,96 +203,5 @@ function M.run_problem(ctx, contest_config, is_debug)
|
|||
end
|
||||
end
|
||||
|
||||
function M.run_individual_tests(ctx, test_cases, contest_config, is_debug)
|
||||
ensure_directories()
|
||||
|
||||
if not test_cases or #test_cases == 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
logger.log(("running %d individual tests"):format(#test_cases))
|
||||
|
||||
local language = get_language_from_file(ctx.source_file)
|
||||
local language_config = contest_config[language]
|
||||
|
||||
if not language_config then
|
||||
return {
|
||||
compile_error = "Error: No configuration for language: " .. language,
|
||||
results = {},
|
||||
}
|
||||
end
|
||||
|
||||
local substitutions = {
|
||||
source = ctx.source_file,
|
||||
binary = ctx.binary_file,
|
||||
version = tostring(language_config.version or ""),
|
||||
}
|
||||
|
||||
local compile_cmd = is_debug and language_config.debug or language_config.compile
|
||||
if compile_cmd then
|
||||
local compile_result = compile_generic(language_config, substitutions)
|
||||
if compile_result.code ~= 0 then
|
||||
return {
|
||||
compile_error = compile_result.stderr,
|
||||
results = {},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local run_cmd = build_command(language_config.run, language_config.executable, substitutions)
|
||||
|
||||
local results = {}
|
||||
for i, test_case in ipairs(test_cases) do
|
||||
local exec_result = execute_command(run_cmd, test_case.input, contest_config.timeout_ms)
|
||||
|
||||
local actual_lines = vim.split(exec_result.stdout, "\n")
|
||||
while #actual_lines > 0 and actual_lines[#actual_lines] == "" do
|
||||
table.remove(actual_lines)
|
||||
end
|
||||
|
||||
local expected_lines = vim.split(test_case.output, "\n")
|
||||
while #expected_lines > 0 and expected_lines[#expected_lines] == "" do
|
||||
table.remove(expected_lines)
|
||||
end
|
||||
|
||||
local matches = #actual_lines == #expected_lines
|
||||
if matches then
|
||||
for j, line in ipairs(actual_lines) do
|
||||
if line ~= expected_lines[j] then
|
||||
matches = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(results, {
|
||||
id = i,
|
||||
status = exec_result.code == 0 and (matches and "PASS" or "FAIL") or "ERROR",
|
||||
time_ms = exec_result.time_ms,
|
||||
input = test_case.input,
|
||||
expected = test_case.output,
|
||||
actual = exec_result.stdout,
|
||||
exit_code = exec_result.code,
|
||||
timed_out = exec_result.timed_out,
|
||||
enabled = true,
|
||||
})
|
||||
end
|
||||
|
||||
local passed = 0
|
||||
local total_time = 0
|
||||
for _, result in ipairs(results) do
|
||||
if result.status == "PASS" then
|
||||
passed = passed + 1
|
||||
end
|
||||
total_time = total_time + result.time_ms
|
||||
end
|
||||
|
||||
logger.log(("test results: %d/%d passed, total execution time %.1fms"):format(passed, #results, total_time))
|
||||
|
||||
return {
|
||||
compile_error = nil,
|
||||
results = results,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue