-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: Make test_runner::TestState::stdout optional to fix parsing cargo test json output #18897
Conversation
This will make failure printing not work, no? I prefer we capture stdout. |
I think capturing still works if user didn't explicitly add |
Yup, I don't think this affects anything besides fixing buggy parsing of cargo json output because the schema isn't right. I have struggled to find the source for cargo's serialisation. Do unstable features only live in PRs of the tracking issue? This is what I believe it it is: /// Case-finished with failure event.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct TestFailed {
/// Test case name.
pub name: String,
/// Test's stdout
pub stdout: Option<String>,
/// Test failure mssage
pub message: Option<String>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
} |
Yeah, I meant it'll break when the user did add |
There is an argument for making
#[test]
fn my_integration_test() {
println!("message a");
std::thread::sleep(std::time::Duration::from_secs(3));
println!("message b");
std::thread::sleep(std::time::Duration::from_secs(3));
println!("message c");
}
#[test]
fn my_integration_test() {
println!("do the big thing...");
std::thread::sleep(std::time::Duration::from_secs(2000));
}
Anyway... not the goal of this quick fix! |
Is it possible to detect which output belongs to which test when running multiple tests using |
It's possible but not without undesirable trade-offs e.g. 1. Double-running I think it's basically a bug/oversight that The workaround that user does is to run a test twice: once for humans and then again for the json reports: rust-lang/rust#49359 (comment) 2. Debug-info You can match assertion failures to tests because they are panics that produce a stack-trace with
3. Single-threading You can't match non-panic stdout to tests in multi-threaded mode but with { "type": "test", "event": "started", "name": "time::timestamp::tests::test_math" }
test_math
{ "type": "test", "name": "time::timestamp::tests::test_math", "event": "ok" } Single threaded could be slower than running a test suite twice so... eh. 4. Custom-threading The threading issue could be solved by RA running multiple single-test 5. Custom Test Harness One of the reasons a) custom test harness
b) cargo-nextest
|
Conclusion However, I don't think this matters! For me, the "run multiple tests" and "view full live test output" use-cases are separate. My workflow would be satisfied by only using The full live test output is much more of a requirement/benefit when drilling-down and working on a specific test so I would personally choose to:
It would be possible to implement an optional |
So I'm inclined to merge this PR to prevent server panic, and defer future work (which I guess also needs some work in cargo) to future PRs. @ChayimFriedman2 what do you think? |
I don't have a strong opinion. |
For issue #18896 -
cargo test
json output does not include astdout
field if given the--nocapture
flag.RA only records the stdout for failed tests. It would be possible to move the
stdout
field toCargoTestMessage
so that the user can inspect the stdout of passing tests too.