|
1 | 1 | local neotest = require("neotest.lib")
|
| 2 | +local async = require("neotest.async") |
2 | 3 | local treesitter = require("neotest-kotlin.treesitter")
|
3 | 4 |
|
4 | 5 | local M = {}
|
5 | 6 |
|
| 7 | +---@enum neotest.ResultStatus |
| 8 | +local ResultStatus = { |
| 9 | + passed = "passed", |
| 10 | + failed = "failed", |
| 11 | + skipped = "skipped", |
| 12 | + -- None is not part of neotest |
| 13 | + none = "none" |
| 14 | +} |
| 15 | + |
6 | 16 | ---Gets the result of a Gradle test output line
|
7 | 17 | ---@param line string
|
8 |
| ----@return string status passed, skipped, failed, none |
| 18 | +---@return neotest.ResultStatus status passed, skipped, failed, none |
9 | 19 | function M.parse_status(line)
|
| 20 | + ---@type neotest.ResultStatus |
10 | 21 | local result = "none"
|
11 | 22 |
|
12 | 23 | if vim.endswith(line, "PASSED") then
|
|
83 | 94 | ---@field id string neotest id
|
84 | 95 | ---@field status string passed, skipped, failed, none
|
85 | 96 |
|
86 |
| ----@param line string test output line |
87 |
| ----@param class_to_path table<string, string> fully qualified class name to path |
88 |
| ----@return TestResult? |
89 |
| -function M.parse_line(line, class_to_path) |
90 |
| - if not M.is_valid_gradle_test_line(line, class_to_path) then |
91 |
| - return nil |
92 |
| - end |
93 |
| - |
94 |
| - local id = M.parse_test_id(line, class_to_path) |
95 |
| - if not id then |
96 |
| - return nil |
97 |
| - end |
98 |
| - |
99 |
| - return { |
100 |
| - id = id, |
101 |
| - status = M.parse_status(line), |
102 |
| - } |
103 |
| -end |
104 |
| - |
105 | 97 | ---Determines all fully qualified classes in the provided file
|
106 | 98 | ---@param file string
|
107 | 99 | ---@return table<string, string>
|
@@ -146,14 +138,45 @@ end
|
146 | 138 | ---@param path string
|
147 | 139 | ---@return table<string, neotest.Result>
|
148 | 140 | function M.parse_lines(lines, path)
|
| 141 | + ---@type neotest.Result[] |
149 | 142 | local results = {}
|
150 | 143 | local classes = M.determine_all_classes(path)
|
151 | 144 |
|
152 |
| - for _, line in ipairs(lines) do |
153 |
| - local result = M.parse_line(line, classes) |
154 |
| - if result ~= nil then |
155 |
| - results[result.id] = result |
| 145 | + for i, line in ipairs(lines) do |
| 146 | + if not M.is_valid_gradle_test_line(line, classes) then |
| 147 | + goto continue |
156 | 148 | end
|
| 149 | + |
| 150 | + local id = M.parse_test_id(line, classes) |
| 151 | + if not id then |
| 152 | + goto continue |
| 153 | + end |
| 154 | + |
| 155 | + ---@type string[] |
| 156 | + local output = {line} |
| 157 | + ---@type neotest.Error[] |
| 158 | + local errors = {} |
| 159 | + |
| 160 | + for j = i+1, #lines do |
| 161 | + if vim.trim(lines[j]) == "" or M.is_valid_gradle_test_line(lines[j], classes) then |
| 162 | + break |
| 163 | + end |
| 164 | + |
| 165 | + table.insert(errors, { message = lines[j], line = j }) |
| 166 | + table.insert(output, lines[j]) |
| 167 | + end |
| 168 | + |
| 169 | + local output_path = async.fn.tempname() |
| 170 | + async.fn.writefile(output, output_path) |
| 171 | + |
| 172 | + results[id] = { |
| 173 | + short = line, |
| 174 | + status = M.parse_status(line), |
| 175 | + output = output_path, |
| 176 | + errors = errors, |
| 177 | + } |
| 178 | + |
| 179 | + ::continue:: |
157 | 180 | end
|
158 | 181 |
|
159 | 182 | return results
|
|
0 commit comments