Skip to content

Commit

Permalink
Merge pull request #64 from igorlfs/fix-diagnostics
Browse files Browse the repository at this point in the history
fix(errors): handle diagnotics from latest version of nextest
  • Loading branch information
rouge8 committed Jan 25, 2024
2 parents d945ccc + 194b148 commit f04071c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lua/neotest-rust/errors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function M.parse_errors(output)
return {}
end

local message, line = output:match("thread '[^']+' panicked at '([^']+)', [^:]+:(%d+):%d+")
local line, message = output:match("thread '[^']+' panicked at [^:]+:(%d+):%d+:\n(.*)note:.*")

if message == nil then
-- Try a different expression
Expand Down
12 changes: 8 additions & 4 deletions tests/data/simple-package/multiple_test_suites.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<testsuites name="nextest-run" tests="4" failures="2" errors="0" uuid="148332a3-772e-45ec-be48-0cd9be5afd62" timestamp="2022-12-16T12:05:30.587+00:00" time="0.002">
<testsuite name="tmp::bin/tmp" tests="2" disabled="0" errors="0" failures="1">
<testcase name="foo::tests::should_fail" classname="tmp::bin/tmp" timestamp="2022-12-16T12:05:30.587+00:00" time="0.001">
<failure type="test failure">thread &apos;foo::tests::should_fail&apos; panicked at &apos;assertion failed: false&apos;, src/foo.rs:10:9
<failure type="test failure">thread &apos;foo::tests::should_fail&apos; panicked at src/foo.rs:10:9:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace</failure>
<system-out>
running 1 test
Expand All @@ -16,7 +17,8 @@ failures:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

</system-out>
<system-err>thread &apos;foo::tests::should_fail&apos; panicked at &apos;assertion failed: false&apos;, src/foo.rs:10:9
<system-err>thread &apos;foo::tests::should_fail&apos; panicked at src/foo.rs:10:9:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
</testcase>
Expand All @@ -25,7 +27,8 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</testsuite>
<testsuite name="tmp::tests" tests="2" disabled="0" errors="0" failures="1">
<testcase name="should_fail" classname="tmp::tests" timestamp="2022-12-16T12:05:30.587+00:00" time="0.001">
<failure type="test failure">thread &apos;should_fail&apos; panicked at &apos;assertion failed: false&apos;, tests/tests.rs:8:5
<failure type="test failure">thread &apos;should_fail&apos; panicked at tests/tests.rs:8:5:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace</failure>
<system-out>
running 1 test
Expand All @@ -39,7 +42,8 @@ failures:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

</system-out>
<system-err>thread &apos;should_fail&apos; panicked at &apos;assertion failed: false&apos;, tests/tests.rs:8:5
<system-err>thread &apos;should_fail&apos; panicked at tests/tests.rs:8:5
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
</testcase>
Expand Down
6 changes: 4 additions & 2 deletions tests/data/simple-package/single_test_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<testcase name="foo::tests::should_pass" classname="tmp::bin/tmp" timestamp="2022-12-16T12:05:54.600+00:00" time="0.001">
</testcase>
<testcase name="foo::tests::should_fail" classname="tmp::bin/tmp" timestamp="2022-12-16T12:05:54.600+00:00" time="0.002">
<failure type="test failure">thread &apos;foo::tests::should_fail&apos; panicked at &apos;assertion failed: false&apos;, src/foo.rs:10:9
<failure type="test failure">thread &apos;foo::tests::should_fail&apos; panicked at src/foo.rs:10:9:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace</failure>
<system-out>
running 1 test
Expand All @@ -18,7 +19,8 @@ failures:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s

</system-out>
<system-err>thread &apos;foo::tests::should_fail&apos; panicked at &apos;assertion failed: false&apos;, src/foo.rs:10:9
<system-err>thread &apos;foo::tests::should_fail&apos; panicked at src/foo.rs:10:9:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</system-err>
</testcase>
Expand Down
10 changes: 4 additions & 6 deletions tests/errors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ describe("parses errors from output", function()
end)

it("assert_eq", function()
local output = "test tests::failed_math ... FAILED\n"
.. "failures:\n\n"
.. "---- tests::failed_math stdout ----\n"
.. "thread 'tests::failed_math' panicked at 'assertion failed: `(left == right)`\n"
local output = "thread 'tests::failed_math' panicked at src/main.rs:16:9:\n"
.. "assertion `left == right` failed\n"
.. " left: `2`,\n"
.. " right: `3`', src/main.rs:16:9\n"
.. " right: `3`\n"
.. "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"

local results = errors.parse_errors(output)
local expected = {
{
line = 15,
message = "assertion failed: `(left == right)`\n left: `2`,\n right: `3`",
message = "assertion `left == right` failed\n left: `2`,\n right: `3`\n",
},
}

Expand Down
12 changes: 6 additions & 6 deletions tests/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,12 @@ describe("results", function()

local expected = {
["foo::tests::should_fail"] = {
short = "thread 'foo::tests::should_fail' panicked at 'assertion failed: false', src/foo.rs:10:9\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
short = "thread 'foo::tests::should_fail' panicked at src/foo.rs:10:9:\nassertion failed: false\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
status = "failed",
errors = {
{
line = 9,
message = "assertion failed: false",
message = "assertion failed: false\n",
},
},
},
Expand Down Expand Up @@ -1040,17 +1040,17 @@ describe("results", function()

local expected = {
["foo::tests::should_fail"] = {
short = "thread 'foo::tests::should_fail' panicked at 'assertion failed: false', src/foo.rs:10:9\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
short = "thread 'foo::tests::should_fail' panicked at src/foo.rs:10:9:\nassertion failed: false\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
status = "failed",
errors = { { line = 9, message = "assertion failed: false" } },
errors = { { line = 9, message = "assertion failed: false\n" } },
},
["foo::tests::should_pass"] = {
status = "passed",
},
should_fail = {
short = "thread 'should_fail' panicked at 'assertion failed: false', tests/tests.rs:8:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
short = "thread 'should_fail' panicked at tests/tests.rs:8:5:\nassertion failed: false\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
status = "failed",
errors = { { line = 7, message = "assertion failed: false" } },
errors = { { line = 7, message = "assertion failed: false\n" } },
},
should_pass = {
status = "passed",
Expand Down

0 comments on commit f04071c

Please sign in to comment.