# HG changeset patch # User Tom Rodriguez # Date 1426050939 25200 # Node ID ea8d6fa333ab2119e586947b7dcf7d45a8d57ca0 # Parent 18be6264186f2255067c2dbc20799332eebfa7dd Add varargs versions of assertTrue and assertFalse diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test; -import static org.junit.Assert.*; - import org.junit.*; import com.oracle.graal.nodes.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConcreteSubtypeTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConcreteSubtypeTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConcreteSubtypeTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test; -import static org.junit.Assert.*; - import org.junit.*; import com.oracle.graal.api.code.Assumptions.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test; -import static org.junit.Assert.*; - import com.oracle.graal.api.code.*; import com.oracle.graal.api.code.Assumptions.Assumption; import com.oracle.graal.api.meta.*; @@ -70,9 +68,9 @@ try { Class.forName(fullName); } catch (ClassNotFoundException e) { - assertFalse(String.format("Can't find class %s", fullName), true); + fail("Can't find class %s", fullName); } - assertTrue(!willInvalidate == installedCode.isValid()); + assertTrue(!willInvalidate == installedCode.isValid(), "method should be %s", willInvalidate ? "invalid" : "valid"); } } @@ -83,7 +81,7 @@ found = true; } } - assertTrue(String.format("Can't find assumption %s", expectedAssumption), found); + assertTrue(found, "Can't find assumption %s", expectedAssumption); } /** diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -23,8 +23,6 @@ package com.oracle.graal.compiler.test; import static com.oracle.graal.compiler.common.GraalOptions.*; -import static org.junit.Assert.*; - import java.util.*; import org.junit.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SchedulingTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SchedulingTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SchedulingTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test; -import static org.junit.Assert.*; - import java.util.*; import org.junit.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test; -import static org.junit.Assert.*; - import java.util.*; import org.junit.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EAMergingTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EAMergingTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EAMergingTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test.ea; -import static org.junit.Assert.*; - import org.junit.*; import com.oracle.graal.nodes.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test.ea; -import static org.junit.Assert.*; - import java.util.concurrent.*; import org.junit.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test.ea; -import static org.junit.Assert.*; - import java.util.*; import org.junit.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.compiler.test.inlining; -import static org.junit.Assert.*; - import org.junit.*; import com.oracle.graal.api.code.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ArrayCopyIntrinsificationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ArrayCopyIntrinsificationTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ArrayCopyIntrinsificationTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.hotspot.test; -import static org.junit.Assert.*; - import java.lang.reflect.*; import java.util.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ClassSubstitutionsTests.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ClassSubstitutionsTests.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ClassSubstitutionsTests.java Tue Mar 10 22:15:39 2015 -0700 @@ -23,8 +23,6 @@ package com.oracle.graal.hotspot.test; -import static org.junit.Assert.*; - import org.junit.*; import com.oracle.graal.compiler.test.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.replacements.test; -import static org.junit.Assert.*; - import java.lang.reflect.*; import com.oracle.graal.api.code.*; diff -r 18be6264186f -r ea8d6fa333ab graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java --- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java Tue Mar 10 20:32:04 2015 -0700 +++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java Tue Mar 10 22:15:39 2015 -0700 @@ -22,8 +22,6 @@ */ package com.oracle.graal.test; -import static org.junit.Assert.*; - import java.io.*; import java.lang.reflect.*; import java.util.*; @@ -253,4 +251,105 @@ } } } + + /* + * Overrides to the normal JUnit {@link Assert} routines that provide varargs style formatting + * and produce an exception stack trace with the assertion frames trimmed out. + */ + + /** + * Fails a test with the given message. + * + * @param message the identifying message for the {@link AssertionError} (null + * okay) + * @see AssertionError + */ + public static void fail(String message, Object... objects) { + AssertionError e; + if (message == null) { + e = new AssertionError(); + } else { + e = new AssertionError(String.format(message, objects)); + } + // Trim the assert frames from the stack trace + StackTraceElement[] trace = e.getStackTrace(); + int start = 1; // Skip this frame + String thisClassName = GraalTest.class.getName(); + while (start < trace.length && trace[start].getClassName().equals(thisClassName) && (trace[start].getMethodName().equals("assertTrue") || trace[start].getMethodName().equals("assertFalse"))) { + start++; + } + e.setStackTrace(Arrays.copyOfRange(trace, start, trace.length)); + throw e; + } + + /** + * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the + * given message. + * + * @param message the identifying message for the {@link AssertionError} (null + * okay) + * @param condition condition to be checked + */ + public static void assertTrue(String message, boolean condition) { + assertTrue(condition, message); + } + + /** + * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} without a + * message. + * + * @param condition condition to be checked + */ + public static void assertTrue(boolean condition) { + assertTrue(condition, null); + } + + /** + * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the + * given message. + * + * @param message the identifying message for the {@link AssertionError} (null + * okay) + * @param condition condition to be checked + */ + public static void assertFalse(String message, boolean condition) { + assertTrue(!condition, message); + } + + /** + * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} without a + * message. + * + * @param condition condition to be checked + */ + public static void assertFalse(boolean condition) { + assertTrue(!condition, null); + } + + /** + * Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the + * given message. + * + * @param condition condition to be checked + * @param message the identifying message for the {@link AssertionError} + * @param objects arguments to the format string + */ + public static void assertTrue(boolean condition, String message, Object... objects) { + if (!condition) { + fail(message, objects); + } + } + + /** + * Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the + * given message produced by {@link String#format}. + * + * @param condition condition to be checked + * @param message the identifying message for the {@link AssertionError} + * @param objects arguments to the format string + */ + public static void assertFalse(boolean condition, String message, Object... objects) { + assertTrue(!condition, message, objects); + } + }