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

Show only stderr diff when a ui test fails #47185

Merged
merged 2 commits into from
Jan 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2708,15 +2708,16 @@ impl<'test> TestCx<'test> {
return 0;
}

println!("normalized {}:\n{}\n", kind, actual);
println!("expected {}:\n{}\n", kind, expected);
println!("diff of {}:\n", kind);

for diff in diff::lines(expected, actual) {
match diff {
diff::Result::Left(l) => println!("-{}", l),
diff::Result::Both(l, _) => println!(" {}", l),
diff::Result::Right(r) => println!("+{}", r),
if expected.is_empty() {
println!("normalized {}:\n{}\n", kind, actual);
} else {
println!("diff of {}:\n", kind);
for diff in diff::lines(expected, actual) {
match diff {
diff::Result::Left(l) => println!("-{}", l),
diff::Result::Right(r) => println!("+{}", r),
_ => {},
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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)) =>

Copy link
Member Author

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?

Copy link
Contributor

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?

}
}
}

Expand Down