since the libtest
JSON output is not yet stabilised (Tracking issue for libtest JSON output · Issue #49359 · rust-lang/rust · GitHub) there should still be a chance to get this in:
it'd be great if the JSON output would contain the position information (file, line, character or better yet: span) for at least the test function being executed and in the best case also for assertions.
this could then be used by other tools which e.g. annotate pull requests on GitHub (e.g. i'm using nextest in combination with their JUnit output, followed by action-junit-report to publish the results). currently it does not contain the position information, accordingly no results are being printed on the actual files in the diff.
example: instead of:
{ "type": "test", "event": "started", "name": "tests::it_works" }
{ "type": "test", "name": "tests::it_works", "event": "failed", "stdout": "\nthread 'tests::it_works' panicked at src\\lib.rs:12:9:\nassertion `left == right` failed\n left: 4\n right: 5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
i'd like to see:
{ "type": "test", "event": "started", "name": "tests::it_works", "file": "src/lib.rs", "line": 10, "position": 8 }
{ "type": "test", "name": "tests::it_works", "event": "failed", "stdout": "\nthread 'tests::it_works' panicked at src\\lib.rs:12:9:\nassertion `left == right` failed\n left: 4\n right: 5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n", "line": 12, "position": 9 }
or, even better:
{ "type": "test", "event": "started", "name": "tests::it_works", "file": "src/lib.rs", "line_start": 10, "position_start": 8, "line_end": 10, "position_end": 16 }
{ "type": "test", "name": "tests::it_works", "event": "failed", "stdout": "\nthread 'tests::it_works' panicked at src\\lib.rs:12:9:\nassertion `left == right` failed\n left: 4\n right: 5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n", "line_start": 12, "position_start": 9, "line_end": 12, "position_end": 30 }
i'm aware of the fact that this request is - at least for the part about reporting this information on the failure message - is probably not fully fleshed out as it might be that it contains multiple failures (e.g. when using expect_that
from googletest
) or possibly no line where it failed (because it instead returned an Error
). i'm posting this to get the discussion started because i was surprised that i didn't see an existing issue/post about this yet.