Skip to content

Commit

Permalink
When falling back to plain AssertionError, still include the "expecte…
Browse files Browse the repository at this point in the history
…d" and "but was" lines.

I have no idea what I was thinking when I went out of my way to omit them in CL 353141904.

And I think it had crossed my mind at one point to test the contents of the AssertionError, but I did not....

This CL does *not* address the main discussion of the day from #333 (comment); it's just *another* bug I noticed along the way. Sigh.

RELNOTES=When JUnit 4 is excluded from the classpath, the `AssertionError` Truth generates as a substitute for `ComparisonFailure` now includes the expected and actual values that were missing in 1.1.1.
PiperOrigin-RevId: 353319232
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jan 22, 2021
1 parent 2d65326 commit 6b01407
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void failEqualityCheck(
if (!isLinkageError(probablyJunitNotOnClasspath)) {
throw probablyJunitNotOnClasspath;
}
failure = new AssertionErrorWithFacts(messages, concat(headFacts, tailFacts), cause);
failure = new AssertionErrorWithFacts(messages, facts, cause);
}
doFail(failure);
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/test/java/com/google/common/truth/NoJUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;

/** Truth-using binary to be run without JUnit on the classpath to verify that it still works. */
public final class NoJUnitTest {
public static void main(String[] args) {
try {
assertThat("a").isEqualTo("b");
throw new Error("assertion should have failed");
} catch (AssertionError expected) {
ImmutableList<Fact> facts = ((AssertionErrorWithFacts) expected).facts();
assertThat(facts.get(0).key).isEqualTo("expected");
assertThat(facts.get(0).value).isEqualTo("b");
assertThat(facts.get(1).key).isEqualTo("but was");
assertThat(facts.get(1).value).isEqualTo("a");
}
}

Expand Down

0 comments on commit 6b01407

Please sign in to comment.