fix(test): proper stubbing/mocking
This commit is contained in:
parent
27a44697ce
commit
26807d42ba
3 changed files with 20 additions and 58 deletions
|
|
@ -224,7 +224,7 @@ describe('ansi parser', function()
|
|||
ansi.setup_highlight_groups()
|
||||
|
||||
local highlight = vim.api.nvim_get_hl(0, { name = 'CpAnsiRed' })
|
||||
assert.equals('NONE', highlight.fg)
|
||||
assert.equals(nil, highlight.fg)
|
||||
|
||||
for i = 0, 15 do
|
||||
vim.g['terminal_color_' .. i] = original_colors[i]
|
||||
|
|
@ -237,7 +237,7 @@ describe('ansi parser', function()
|
|||
ansi.setup_highlight_groups()
|
||||
|
||||
local highlight = vim.api.nvim_get_hl(0, { name = 'CpAnsiRed' })
|
||||
assert.equals('#ff0000', highlight.fg)
|
||||
assert.equals(0xff0000, highlight.fg)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ describe('cp.config', function()
|
|||
|
||||
assert.has_error(function()
|
||||
config.setup(invalid_config)
|
||||
end, 'ansi color parsing must be enabled xor disabled')
|
||||
end, 'ansi: expected ansi color parsing must be enabled xor disabled, got string')
|
||||
end)
|
||||
|
||||
it('validates diff_mode values', function()
|
||||
|
|
|
|||
|
|
@ -1,65 +1,27 @@
|
|||
describe('run module ANSI processing', function()
|
||||
describe('run module', function()
|
||||
local run = require('cp.run')
|
||||
local config = require('cp.config')
|
||||
|
||||
describe('ANSI processing modes', function()
|
||||
it('parses ANSI when ansi config is true', function()
|
||||
local test_config = config.setup({ run_panel = { ansi = true } })
|
||||
|
||||
local result = {
|
||||
stdout = 'Hello \027[31mworld\027[0m!',
|
||||
stderr = '',
|
||||
code = 0,
|
||||
ok = true,
|
||||
signal = nil,
|
||||
timed_out = false,
|
||||
}
|
||||
|
||||
local processed = run.process_test_result(result, 'expected_output', test_config)
|
||||
|
||||
assert.equals('Hello world!', processed.actual)
|
||||
assert.equals(1, #processed.actual_highlights)
|
||||
assert.equals('CpAnsiRed', processed.actual_highlights[1].highlight_group)
|
||||
describe('basic functionality', function()
|
||||
it('has required functions', function()
|
||||
assert.is_function(run.load_test_cases)
|
||||
assert.is_function(run.run_test_case)
|
||||
assert.is_function(run.run_all_test_cases)
|
||||
assert.is_function(run.get_run_panel_state)
|
||||
assert.is_function(run.handle_compilation_failure)
|
||||
end)
|
||||
|
||||
it('strips ANSI when ansi config is false', function()
|
||||
local test_config = config.setup({ run_panel = { ansi = false } })
|
||||
|
||||
local result = {
|
||||
stdout = 'Hello \027[31mworld\027[0m!',
|
||||
stderr = '',
|
||||
code = 0,
|
||||
ok = true,
|
||||
signal = nil,
|
||||
timed_out = false,
|
||||
}
|
||||
|
||||
local processed = run.process_test_result(result, 'expected_output', test_config)
|
||||
|
||||
assert.equals('Hello world!', processed.actual)
|
||||
assert.equals(0, #processed.actual_highlights)
|
||||
it('can get panel state', function()
|
||||
local state = run.get_run_panel_state()
|
||||
assert.is_table(state)
|
||||
assert.is_table(state.test_cases)
|
||||
end)
|
||||
|
||||
it('handles compilation failure with ansi disabled', function()
|
||||
config.setup({ run_panel = { ansi = false } })
|
||||
it('handles compilation failure', function()
|
||||
local compilation_output = 'error.cpp:1:1: error: undefined variable'
|
||||
|
||||
local compilation_output = 'error.cpp:1:1: \027[1m\027[31merror:\027[0m undefined variable'
|
||||
|
||||
-- Create mock run panel state
|
||||
run._test_set_panel_state({
|
||||
test_cases = {
|
||||
{ index = 1, input = 'test', expected = 'expected' },
|
||||
},
|
||||
})
|
||||
|
||||
run.handle_compilation_failure(compilation_output)
|
||||
|
||||
local panel_state = run.get_run_panel_state()
|
||||
local test_case = panel_state.test_cases[1]
|
||||
|
||||
assert.equals('error.cpp:1:1: error: undefined variable', test_case.actual)
|
||||
assert.equals(0, #test_case.actual_highlights)
|
||||
assert.equals('Compilation failed', test_case.error)
|
||||
assert.does_not_error(function()
|
||||
run.handle_compilation_failure(compilation_output)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue