feat(run_panel): max_output_lines
This commit is contained in:
parent
c7338d01d8
commit
f22eccfa89
2 changed files with 23 additions and 2 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
---@field next_test_key string Key to navigate to next test case
|
---@field next_test_key string Key to navigate to next test case
|
||||||
---@field prev_test_key string Key to navigate to previous test case
|
---@field prev_test_key string Key to navigate to previous test case
|
||||||
---@field toggle_diff_key string Key to toggle diff mode
|
---@field toggle_diff_key string Key to toggle diff mode
|
||||||
|
---@field max_output_lines number Maximum lines of test output to display
|
||||||
|
|
||||||
---@class DiffGitConfig
|
---@class DiffGitConfig
|
||||||
---@field command string Git executable name
|
---@field command string Git executable name
|
||||||
|
|
@ -84,6 +85,7 @@ M.defaults = {
|
||||||
next_test_key = '<c-n>',
|
next_test_key = '<c-n>',
|
||||||
prev_test_key = '<c-p>',
|
prev_test_key = '<c-p>',
|
||||||
toggle_diff_key = 't',
|
toggle_diff_key = 't',
|
||||||
|
max_output_lines = 50,
|
||||||
},
|
},
|
||||||
diff = {
|
diff = {
|
||||||
git = {
|
git = {
|
||||||
|
|
@ -203,6 +205,13 @@ function M.setup(user_config)
|
||||||
end,
|
end,
|
||||||
'toggle_diff_key must be a non-empty string',
|
'toggle_diff_key must be a non-empty string',
|
||||||
},
|
},
|
||||||
|
max_output_lines = {
|
||||||
|
config.run_panel.max_output_lines,
|
||||||
|
function(value)
|
||||||
|
return type(value) == 'number' and value > 0 and value == math.floor(value)
|
||||||
|
end,
|
||||||
|
'max_output_lines must be a positive integer',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.validate({
|
vim.validate({
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ end
|
||||||
---@param contest_config ContestConfig
|
---@param contest_config ContestConfig
|
||||||
---@param test_case TestCase
|
---@param test_case TestCase
|
||||||
---@return table
|
---@return table
|
||||||
local function run_single_test_case(ctx, contest_config, test_case)
|
local function run_single_test_case(ctx, contest_config, cp_config, test_case)
|
||||||
local language = vim.fn.fnamemodify(ctx.source_file, ':e')
|
local language = vim.fn.fnamemodify(ctx.source_file, ':e')
|
||||||
local language_name = constants.filetype_to_language[language] or contest_config.default_language
|
local language_name = constants.filetype_to_language[language] or contest_config.default_language
|
||||||
local language_config = contest_config[language_name]
|
local language_config = contest_config[language_name]
|
||||||
|
|
@ -187,6 +187,18 @@ local function run_single_test_case(ctx, contest_config, test_case)
|
||||||
local execution_time = (vim.uv.hrtime() - start_time) / 1000000
|
local execution_time = (vim.uv.hrtime() - start_time) / 1000000
|
||||||
|
|
||||||
local actual_output = (result.stdout or ''):gsub('\n$', '')
|
local actual_output = (result.stdout or ''):gsub('\n$', '')
|
||||||
|
|
||||||
|
local max_lines = cp_config.run_panel.max_output_lines
|
||||||
|
local output_lines = vim.split(actual_output, '\n')
|
||||||
|
if #output_lines > max_lines then
|
||||||
|
local trimmed_lines = {}
|
||||||
|
for i = 1, max_lines do
|
||||||
|
table.insert(trimmed_lines, output_lines[i])
|
||||||
|
end
|
||||||
|
table.insert(trimmed_lines, string.format('... (output trimmed after %d lines)', max_lines))
|
||||||
|
actual_output = table.concat(trimmed_lines, '\n')
|
||||||
|
end
|
||||||
|
|
||||||
local expected_output = test_case.expected:gsub('\n$', '')
|
local expected_output = test_case.expected:gsub('\n$', '')
|
||||||
local ok = actual_output == expected_output
|
local ok = actual_output == expected_output
|
||||||
|
|
||||||
|
|
@ -238,7 +250,7 @@ end
|
||||||
---@param contest_config ContestConfig
|
---@param contest_config ContestConfig
|
||||||
---@param index number
|
---@param index number
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.run_test_case(ctx, contest_config, index)
|
function M.run_test_case(ctx, contest_config, cp_config, index)
|
||||||
local test_case = run_panel_state.test_cases[index]
|
local test_case = run_panel_state.test_cases[index]
|
||||||
if not test_case then
|
if not test_case then
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue