Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java @ 11544:e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 16:11:15 +0200 |
parents | 80de3bbfa8b9 |
children | 5d1308c78ddc |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java Fri Sep 06 16:10:09 2013 +0200 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java Fri Sep 06 16:11:15 2013 +0200 @@ -37,6 +37,17 @@ public class PolymorphicTest { + private static void assertParent(Node expectedParent, Node child) { + Node parent = child.getParent(); + while (parent != null && parent != expectedParent) { + parent = parent.getParent(); + } + + if (parent != expectedParent) { + assertEquals(expectedParent, parent); + } + } + @Test public void testJustSpecialize() { TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); @@ -45,8 +56,8 @@ assertEquals("(int,boolean)", executeWith(node, 42, false)); assertEquals("(boolean,int)", executeWith(node, false, 42)); assertEquals(Kind.SPECIALIZED, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @Test @@ -55,8 +66,8 @@ assertEquals("(int,boolean)", executeWith(node, 42, false)); assertEquals("(int,int)", executeWith(node, 42, 42)); assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @Test @@ -66,8 +77,8 @@ assertEquals("(boolean,boolean)", executeWith(node, true, false)); assertEquals("(int,int)", executeWith(node, 42, 42)); assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @Test @@ -78,17 +89,17 @@ assertEquals("(boolean,boolean)", executeWith(node, true, false)); assertEquals("(int,int)", executeWith(node, 42, 42)); assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @Test public void testGenericInitial() { TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); - assertEquals("(generic,generic)", executeWith(node, "", "")); + assertEquals("(generic,generic)", executeWith(node, "1", "1")); assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @Test @@ -99,8 +110,8 @@ assertEquals("(generic,generic)", executeWith(node, "", "")); assertEquals(Kind.GENERIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); /* Assertions for bug GRAAL-425 */ - assertEquals(node.getNode(), node.getNode().getLeft().getParent()); - assertEquals(node.getNode(), node.getNode().getRight().getParent()); + assertParent(node.getNode(), node.getNode().getLeft()); + assertParent(node.getNode(), node.getNode().getRight()); } @SuppressWarnings("unused")