From a6eeb01b64723fde9b53235904f7c9d2996d93da Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Fri, 25 Nov 2011 22:31:29 +0400 Subject: [PATCH] try to fix VarArgTest Accoring to spec array of class.getMethods() is not sorted, so we can't just call getMethods()[0] to get desired method. --- .../jetbrains/jet/codegen/CodegenTestCase.java | 18 +++++++++++++++++- .../jet/codegen/NamespaceGenTest.java | 2 +- .../org/jetbrains/jet/codegen/VarArgTest.java | 11 +++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index 8c584e9cc26..485a97b80d2 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -7,10 +7,12 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetNamespace; import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.parsing.JetParsingTest; +import org.junit.Assert; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -157,7 +159,21 @@ public abstract class CodegenTestCase extends JetLiteFixture { protected Method generateFunction() { Class aClass = generateNamespaceClass(); try { - return aClass.getMethods()[0]; + Method r = null; + for (Method method : aClass.getMethods()) { + if (method.getDeclaringClass().equals(Object.class)) { + continue; + } + + if (r != null) { + throw new AssertionError("more then one public method in class " + aClass); + } + + r = method; + } + if (r == null) + throw new AssertionError(); + return r; } catch (Error e) { System.out.println(generateToText()); throw e; diff --git a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java index 81865f848af..295781b1837 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java @@ -487,7 +487,7 @@ public class NamespaceGenTest extends CodegenTestCase { public void testTupleLiteral() throws Exception { loadText("fun foo() = (1, \"foo\")"); // System.out.println(generateToText()); - final Method main = generateFunction(); + final Method main = generateFunction("foo"); Tuple2 tuple2 = (Tuple2) main.invoke(null); assertEquals(1, tuple2._1); assertEquals("foo", tuple2._2); diff --git a/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java b/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java index 62fbe452833..e08b515771c 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/VarArgTest.java @@ -26,7 +26,7 @@ public class VarArgTest extends CodegenTestCase { public void testIntArrayKotlinNoArgs () throws InvocationTargetException, IllegalAccessException { loadText("fun test() = testf(); fun testf(vararg ts: Int) = ts"); // System.out.println(generateToText()); - final Method main = generateFunction(); + final Method main = generateFunction("test"); Object res = main.invoke(null); assertTrue(((int[])res).length == 0); } @@ -34,8 +34,7 @@ public class VarArgTest extends CodegenTestCase { public void testIntArrayKotlin () throws InvocationTargetException, IllegalAccessException { loadText("fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts"); // System.out.println(generateToText()); - final Method main = generateFunction(); - System.out.println(main.toString()); + final Method main = generateFunction("test"); Object res = main.invoke(null); assertTrue(((int[])res).length == 2); assertTrue(((int[])res)[0] == 239); @@ -45,7 +44,7 @@ public class VarArgTest extends CodegenTestCase { public void testNullableIntArrayKotlin () throws InvocationTargetException, IllegalAccessException { loadText("fun test() = testf(239.byt, 7.byt); fun testf(vararg ts: Byte?) = ts"); // System.out.println(generateToText()); - final Method main = generateFunction(); + final Method main = generateFunction("test"); Object res = main.invoke(null); assertTrue(((Byte[])res).length == 2); assertTrue(((Byte[])res)[0] == (byte)239); @@ -55,7 +54,7 @@ public class VarArgTest extends CodegenTestCase { public void testIntArrayKotlinObj () throws InvocationTargetException, IllegalAccessException { loadText("fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts"); // System.out.println(generateToText()); - final Method main = generateFunction(); + final Method main = generateFunction("test"); Object res = main.invoke(null); assertTrue(((String[])res).length == 1); assertTrue(((String[])res)[0].equals("239")); @@ -64,7 +63,7 @@ public class VarArgTest extends CodegenTestCase { public void testArrayT () throws InvocationTargetException, IllegalAccessException { loadText("fun test() = _array(2, 4); fun _array(vararg elements : T) = elements"); // System.out.println(generateToText()); - final Method main = generateFunction(); + final Method main = generateFunction("test"); Object res = main.invoke(null); assertTrue(((Integer[])res).length == 2); assertTrue(((Integer[])res)[0].equals(2));