Skip to content

Commit 8befd5c

Browse files
Grace Petryks1n7ax
authored andcommitted
status colors + handling for skipped/errored test results
1 parent 84b9253 commit 8befd5c

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

lua/java-test/reports/junit.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local class = require('java-core.utils.class')
22
local log = require('java-core.utils.log2')
33

44
---@class java-test.JUnitTestReport
5-
---@field private conn uv_tcp_t
5+
---@field private conn uv.uv_tcp_t
66
---@field private result_parser java-test.TestParser
77
---@field private result_parser_fac java-test.TestParserFactory
88
---@field private report_viewer java-test.ReportViewer
@@ -29,7 +29,7 @@ function JUnitReport:show_report()
2929
end
3030

3131
---Returns a stream reader function
32-
---@param conn uv_tcp_t
32+
---@param conn uv.uv_tcp_t
3333
---@return fun(err: string, buffer: string) # callback function
3434
function JUnitReport:get_stream_reader(conn)
3535
self.conn = conn

lua/java-test/results/message-id.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ local MessageId = {
2323
ActualEnd = '%ACTUALE',
2424
TraceStart = '%TRACES',
2525
TraceEnd = '%TRACEE',
26-
IGNORE_TEST_PREFIX = '@Ignore: ',
27-
ASSUMPTION_FAILED_TEST_PREFIX = '@AssumptionFailure: ',
2826
}
2927

3028
return MessageId

lua/java-test/results/result-parser.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ TestParser.node_parsers = {
1919
[MessageId.TestStart] = 'parse_test_start',
2020
[MessageId.TestEnd] = 'parse_test_end',
2121
[MessageId.TestFailed] = 'parse_test_failed',
22+
[MessageId.TestError] = 'parse_test_failed',
23+
}
24+
25+
---@private
26+
TestParser.skip_prefixes = {
27+
'@Ignore:',
28+
'@AssumptionFailure:',
2229
}
2330

2431
---@private
@@ -101,6 +108,12 @@ function TestParser:parse_test_end(data)
101108
local node = self:find_result_node(test_id)
102109
assert(node)
103110
node.result.execution = TestExecStatus.Ended
111+
112+
for _, prefix in ipairs(TestParser.skip_prefixes) do
113+
if string.match(data[2], '^'..prefix) then
114+
node.result.status = TestStatus.Skipped
115+
end
116+
end
104117
end
105118

106119
---@private
@@ -109,7 +122,13 @@ function TestParser:parse_test_failed(data, line_iter)
109122
local node = self:find_result_node(test_id)
110123
assert(node)
111124

112-
node.result.status = TestStatus.Failed
125+
node.result.status = node.result.status or TestStatus.Failed
126+
127+
for _, prefix in ipairs(TestParser.skip_prefixes) do
128+
if string.match(data[2], '^'..prefix) then
129+
node.result.status = TestStatus.Skipped
130+
end
131+
end
113132

114133
while true do
115134
local line = line_iter()
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
---@enum java-test.TestStatus
1+
---@class java-test.TestStatus
2+
---@field icon string
3+
---@field highlight string
4+
5+
---@type { [string]: java-test.TestStatus}
26
local TestStatus = {
3-
Failed = 'failed',
4-
Skipped = 'skipped',
7+
Failed = { icon = '', highlight = 'DiagnosticError'},
8+
Skipped = { icon = '', highlight = 'DiagnosticWarn'},
9+
Passed = { icon = '', highlight = 'DiagnosticOk'},
510
}
611

712
return TestStatus

lua/java-test/ui/floating-report-viewer.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ function FloatingReportViewer:show(test_results)
2424
if result.is_suite then
2525
tc.append('' .. result.test_name).lbreak()
2626
else
27+
local status = result.result.status or TestStatus.Passed
28+
tc.append(status.icon .. result.test_name).lbreak()
2729
if result.result.status == TestStatus.Failed then
28-
tc.append('󰅙 ' .. result.test_name).lbreak().append(indentation).append(result.result.trace, indentation)
29-
elseif result.result.status == TestStatus.Skipped then
30-
tc.append('' .. result.test_name).lbreak()
31-
else
32-
tc.append('' .. result.test_name).lbreak()
30+
tc.append(indentation).append(result.result.trace, indentation)
3331
end
3432
end
3533

@@ -45,10 +43,19 @@ function FloatingReportViewer:show(test_results)
4543

4644
local res = build_result(test_results, '', '')
4745

48-
self:show_in_window(vim.split(res, '\n'))
46+
FloatingReportViewer.show_in_window(vim.split(res, '\n'))
4947
end
5048

51-
function FloatingReportViewer:show_in_window(content)
49+
function FloatingReportViewer.show_in_window(content)
50+
vim.api.nvim_create_autocmd('BufWinEnter', {
51+
once = true,
52+
callback = function()
53+
for _, status in pairs(TestStatus) do
54+
vim.fn.matchadd(status.highlight, status.icon)
55+
end
56+
end,
57+
})
58+
5259
local Popup = require('nui.popup')
5360
local event = require('nui.utils.autocmd').event
5461

0 commit comments

Comments
 (0)