Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for nil testsuite when parsing test results #63

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lua/neotest-rust/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ function adapter.results(spec, result, tree)
local root = xml.parse(data)

local testsuites
if #root.testsuites.testsuite == 0 then
if root.testsuites.testsuite == nil then
testsuites = {}
elseif #root.testsuites.testsuite == 0 then
testsuites = { root.testsuites.testsuite }
else
testsuites = root.testsuites.testsuite
Expand Down
3 changes: 3 additions & 0 deletions tests/data/simple-package/no_test_suite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="nextest-run" tests="2" failures="1" errors="0" uuid="17fb0f4a-f4d2-40b2-b229-ba30aac4b211" timestamp="2022-12-16T12:05:54.600+00:00" time="0.002">
</testsuites>
13 changes: 13 additions & 0 deletions tests/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,19 @@ describe("results", function()
assert.are.same(expected, results)
end)

it("parses results with no test suite in it", function()
local adapter = require("neotest-rust")({})
local path = vim.loop.cwd() .. "/tests/data/simple-package/no_test_suite.xml"
local spec = { context = { junit_path = path }, strategy = { stdio = nil } }
local strategy_result = { code = 101, output = "/some/path" }

local results = adapter.results(spec, strategy_result, nil)

local expected = {}

assert.are.same(expected, results)
end)

it("parses results with empty system-out and system-err", function()
local adapter = require("neotest-rust")({})
local path = vim.loop.cwd() .. "/tests/data/simple-package/test_failure_with_empty_stdout_stder.xml"
Expand Down