changeset 19765:ea8d6fa333ab

Add varargs versions of assertTrue and assertFalse
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 10 Mar 2015 22:15:39 -0700
parents 18be6264186f
children 29916dcee0b8
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConcreteSubtypeTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerAssumptionsTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SchedulingTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EAMergingTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ArrayCopyIntrinsificationTest.java graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/ClassSubstitutionsTests.java graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java
diffstat 14 files changed, 104 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- 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.*;
--- 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.*;
--- 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);
     }
 
     /**
--- 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.*;
--- 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.*;
--- 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.*;
--- 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.*;
--- 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.*;
--- 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.*;
--- 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.*;
--- 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.*;
 
--- 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.*;
--- 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.*;
--- 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} (<code>null</code>
+     *            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} (<code>null</code>
+     *            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} (<code>null</code>
+     *            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);
+    }
+
 }