Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 393190545
  • Loading branch information
gkdn authored and Google Java Core Libraries committed Aug 26, 2021
1 parent 9d80113 commit 3c580fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/main/java/com/google/common/truth/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ static String floatToString(float value) {
return Float.toString(value);
}

/** Turns a non-double, non-float object into a string. */
static String stringValueOfNonFloatingPoint(Object o) {
return String.valueOf(o);
}

/** Returns a human readable string representation of the throwable's stack trace. */
static String getStackTraceAsString(Throwable throwable) {
return Throwables.getStackTraceAsString(throwable);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/google/common/truth/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Platform.doubleToString;
import static com.google.common.truth.Platform.floatToString;
import static com.google.common.truth.Platform.stringValueOfNonFloatingPoint;
import static com.google.common.truth.Subject.EqualityCheck.SAME_INSTANCE;
import static com.google.common.truth.SubjectUtils.accumulate;
import static com.google.common.truth.SubjectUtils.append;
Expand Down Expand Up @@ -408,7 +409,7 @@ private String formatActualOrExpected(@Nullable Object o) {
} else if (o instanceof Float) {
return floatToString((Float) o);
} else {
return String.valueOf(o);
return stringValueOfNonFloatingPoint(o);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static jsinterop.annotations.JsPackage.GLOBAL;

import com.google.common.collect.ImmutableList;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -136,6 +137,31 @@ private static String toLocaleString(double value) {
return ((NativeNumber) (Object) value).toLocaleString("en-US", JavaLikeOptions.INSTANCE);
}

@JsType(isNative = true, namespace = "proto.im")
private static class Message {
public native String serialize();
}

@JsMethod(namespace = "proto.im.debug")
private static native Object dump(Message msg) /*-{
// Emtpy stub to make GWT happy. This will never get executed under GWT.
throw new Error();
}-*/;

/** Turns a non-double, non-float object into a string. */
static String stringValueOfNonFloatingPoint(Object o) {
// Check if we are in J2CL mode by probing a system property that only exists in GWT.
boolean inJ2clMode = System.getProperty("superdevmode", "doesntexist").equals("doesntexist");
if (inJ2clMode && o instanceof Message) {
Message msg = (Message) o;
boolean dumpAvailable =
"true".equals(System.getProperty("goog.DEBUG", "true"))
&& !"true".equals(System.getProperty("COMPILED", "false"));
return dumpAvailable ? dump(msg).toString() : msg.serialize();
}
return String.valueOf(o);
}

/** Tests if current platform is Android which is always false. */
static boolean isAndroid() {
return false;
Expand Down

0 comments on commit 3c580fc

Please sign in to comment.