diff --git a/lua/cp/config.lua b/lua/cp/config.lua index d92c267..0616e9f 100644 --- a/lua/cp/config.lua +++ b/lua/cp/config.lua @@ -36,6 +36,7 @@ ---@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 toggle_diff_key string Key to toggle diff mode +---@field max_output_lines number Maximum lines of test output to display ---@class DiffGitConfig ---@field command string Git executable name @@ -84,6 +85,7 @@ M.defaults = { next_test_key = '', prev_test_key = '', toggle_diff_key = 't', + max_output_lines = 50, }, diff = { git = { @@ -203,6 +205,13 @@ function M.setup(user_config) end, '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({ diff --git a/lua/cp/test.lua b/lua/cp/test.lua index 329f03c..385a105 100644 --- a/lua/cp/test.lua +++ b/lua/cp/test.lua @@ -118,7 +118,7 @@ end ---@param contest_config ContestConfig ---@param test_case TestCase ---@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_name = constants.filetype_to_language[language] or contest_config.default_language 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 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 ok = actual_output == expected_output @@ -238,7 +250,7 @@ end ---@param contest_config ContestConfig ---@param index number ---@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] if not test_case then return false