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

--format=junit doesn't include stdout / test failure reason #110336

Closed
ssbr opened this issue Apr 14, 2023 · 2 comments · Fixed by #110651
Closed

--format=junit doesn't include stdout / test failure reason #110336

ssbr opened this issue Apr 14, 2023 · 2 comments · Fixed by #110651
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@ssbr
Copy link

ssbr commented Apr 14, 2023

I tried this code:

#[test]
fn it_breaks() { panic!("PANICCC"); }

I expected to see this happen: the string PANICCC in the test output, when running cargo test -- --format=junit -Zunstable-options.

Instead, this happened:

<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="1" tests="1" skipped="0" ><testcase classname="crate" name="it_breaks" time="0"><failure type="assert"/></testcase><system-out/><system-err/></testsuite></testsuites>

Meta

rustc --version --verbose:

rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-unknown-linux-gnu
release: 1.68.2
LLVM version: 15.0.6

@ssbr ssbr added the C-bug Category: This is a bug. label Apr 14, 2023
@saethlin saethlin added A-libtest Area: `#[test]` / the `test` library T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 15, 2023
@Manishearth
Copy link
Member

Note that this works fine under other message formats

@Manishearth
Copy link
Member

Ah, it seems like the JSON backend emits this as a "stdout" entry

let display_stdout = state.options.display_output || *result != TestResult::TrOk;
let stdout = if display_stdout && !stdout.is_empty() {
Some(String::from_utf8_lossy(stdout))
} else {
None
};

Whereas the junit backend does not

The test runner maintains a distinction between TrFailed and TrFailedMsg, except that the latter is only for failures with messages that come from the test suite (as opposed to panic messages). The testsuite doesn't distinguish between panic messages and otherwise, though it can for should_panic tests.

The simplest thing to do is probably just dump stdout inside the failure text body. I'm not sure if that's ideal, it would be nice if we could get it into message instead.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 1, 2023
libtest: include test output in junit xml reports

Fixes rust-lang#110336.
@bors bors closed this as completed in bf72b64 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants