-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Show only stderr diff when a ui test fails #47185
Conversation
cc @oli-obk |
src/tools/compiletest/src/runtest.rs
Outdated
match diff { | ||
diff::Result::Left(l) => println!("-{}", l), | ||
diff::Result::Right(r) => println!("+{}", r), | ||
_ => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we still show 3 lines of unchanged output to give the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean we should keep diff::Result::Both()
? I don't quite get it, could you please explain a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
diff::Result::Both(t, _) if context_lines_count <= 3 => {
println!(" {}", t);
context_lines_count += 1;
}
Mainly to emulate the diff -u
display style:
/ | (CastTy::Ptr(_), CastTy::Int(_)) |
3 lines before { | (CastTy::FnPtr, CastTy::Int(_)) =>
\ | bcx.ptrtoint(llval, ll_t_out),
| - (CastTy::Int(_), CastTy::Ptr(_)) =>
| - bcx.inttoptr(llval, ll_t_out),
| + (CastTy::Int(_), CastTy::Ptr(_)) => {
| + let usize_llval = bcx.intcast(llval, bcx.ccx.isize_ty(), signed);
| + bcx.inttoptr(usize_llval, ll_t_out)
| + }
/ | (CastTy::Int(_), CastTy::Float) =>
3 lines after { | cast_int_to_float(&bcx, signed, llval, ll_t_in, ll_t_out),
\ | (CastTy::Float, CastTy::Int(IntTy::I)) =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I get it now. I don't think this will be as straight forward and as @durka mentioned:
Sounds like reinventing features from existing diff libraries where there might be a crate that can do it nicely!
I checked out rustfmt and it looks like it already contains some functions we'll need src/tools/rustfmt/src/bin/rustfmt-format-diff.rs.
I tested it out by copying make_diff()
and other depending parts to runtest.rs and modifying compare_output()
with:
fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
if actual == expected {
return 0;
}
if expected.is_empty() {
println!("normalized {}:\n{}\n", kind, actual);
} else {
println!("diff of {}:\n", kind);
let results = make_diff(expected, actual, 3);
for result in results {
for line in result.lines {
match line {
DiffLine::Expected(e) => println!("+{}", e),
DiffLine::Context(c) => println!(" {}", c),
DiffLine::Resulting(r) => println!("-{}", r),
}
}
}
}
...
Here is an example generated diff:
...
---- [ui] ui/issue-10969.rs stdout ----
diff of stderr:
| ^
error[E0618]: expected function, found `i32`
-fun with .stderr
+ --> $DIR/issue-10969.rs:16:5
|
16 | i(); //~ERROR expected function, found `i32`
| ^^^
The actual stderr differed from the expected stderr.
...
What do you guys think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks nice; it'd look even better with some line numbers :)
What happens if there are multiple hunks? i.e., multiple distinct parts that changed?
c224f8a
to
9cfd5b3
Compare
I've made changes to show line numbers. Here is how the diff looks with committed changes:
My modified issue-10969.stderr:
|
9cfd5b3
to
5f84181
Compare
5f84181
to
4054030
Compare
This looks awesome =) |
@bors r+ |
📌 Commit 4054030 has been approved by |
…omatsakis Show only stderr diff when a ui test fails Addresses rust-lang#46826. This PR will print the normalized output if expected text is empty otherwise it will just print the diff. Should we also show a few (actual == expected) lines above & below when displaying the diff? What about indicating line numbers as well so one can quickly check mismatch lines in .stderr file?
☔ The latest upstream changes (presumably #47392) made this pull request unmergeable. Please resolve the merge conflicts. |
Addresses #46826.
This PR will print the normalized output if expected text is empty otherwise it will just print the diff.
Should we also show a few (actual == expected) lines above & below when displaying the diff? What about indicating line numbers as well so one can quickly check mismatch lines in .stderr file?