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

Trigger diff-style output more aggressively #651

Open
vitiral opened this issue Dec 6, 2019 · 3 comments
Open

Trigger diff-style output more aggressively #651

vitiral opened this issue Dec 6, 2019 · 3 comments
Labels
P3 not scheduled type=enhancement Make an existing feature better

Comments

@vitiral
Copy link

vitiral commented Dec 6, 2019

Add an implementation of StringSubject.isEqualTo(String expected) which will do diffing in the error message if the strings are not equal.

https://truth.dev/api/1.0/com/google/common/truth/StringSubject.html

@vitiral
Copy link
Author

vitiral commented Dec 6, 2019

Adding a dependency on diff_match_patch should make this very easy.

@cpovirk
Copy link
Member

cpovirk commented Dec 6, 2019

Thanks. We do render a diff in some cases:

$ wget https://repo1.maven.org/maven2/{com/google/truth/truth/1.0/truth-1.0,com/google/guava/guava/27.1-jre/guava-27.1-jre,junit/junit/4.12/junit-4.12,com/googlecode/java-diff-utils/diffutils/1.3.0/diffutils-1.3.0,org/ow2/asm/asm/7.1/asm-7.1}.jar && echo 'import static com.google.common.truth.Truth.assertThat; class Foo { public static void main(String[] args) { assertThat("foo\nfoo\nfoo\nfoo\nfoo\nfoo\nbar\nbar\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\n").isEqualTo("foo\nfoo\nfoo\nfoo\nfoo\nfoo\nfoo\nbar\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\nbaz\n"); } }' > Foo.java && CP=.:truth-1.0.jar:guava-27.1-jre.jar:junit-4.12.jar:diffutils-1.3.0.jar:asm-7.1.jar && javac -cp $CP Foo.java && java -cp $CP Foo
Exception in thread "main" diff:
    @@ -4,8 +4,8 @@
     foo
     foo
     foo
    -foo
     bar
    +bar
     baz
     baz
     baz
  at Foo.main(Foo.java:1)

However, maybe we should do so more aggressively? (I had to add a lot of foos and bazzes to get the diff to trigger.)

Additionally, we could consider diff_match_patch for its ability to generate inline diffs, rather than only the line-by-line diffs that we currently support.

Are you interested more in generating line-by-line diffs more of the time or in generating inline diffs?

@vitiral
Copy link
Author

vitiral commented Dec 6, 2019

Interesting! I'm surprised the diff exists at all with the current code. I should have done some more internal testing.

I'd say when the diff is sufficiently large, inline diffs are probably better.

@cgdecker cgdecker added P3 not scheduled type=enhancement Make an existing feature better labels Dec 9, 2019
@cpovirk cpovirk changed the title Add string diffing on equality failure Trigger diff-style output more aggressively Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 not scheduled type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

3 participants