Delete StdlibTest and StdlibTestForever

Move remaining tests to AnnotationGenTest (where they did belong to in the
first place)
This commit is contained in:
Alexander Udalov
2013-02-08 15:36:06 +04:00
committed by Alexander Udalov
parent 90d255e7da
commit 544aad390d
7 changed files with 186 additions and 323 deletions
@@ -0,0 +1,11 @@
fun foo(): Int {
var sum = 0
for (c in "239")
sum += (c.toInt() - '0'.toInt())
return sum
}
fun box(): String {
val f = foo()
return if (f == 14) "OK" else "Fail $f"
}
@@ -29,7 +29,7 @@ public class AnnotationGenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
}
public void testPropField() throws NoSuchFieldException, NoSuchMethodException {
@@ -234,4 +234,158 @@ public class AnnotationGenTest extends CodegenTestCase {
assertEquals("C", cClass.getName());
assertEquals("239", cClass.getDeclaredMethod("c").invoke(invoke));
}
public void testAnnotationClassWithClassProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: java.lang.Class<*>)\n" +
"" +
"A(javaClass<String>()) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(Class.class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
assertEquals(String.class, methods[0].invoke(bClassAnnotation));
}
public void testAnnotationClassWithStringArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" +
"" +
"A(array(\"239\",\"932\")) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(String[].class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
assertEquals("239", ((String[])invoke)[0]);
assertEquals("932", ((String[])invoke)[1]);
}
public void testAnnotationClassWithIntArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" +
"" +
"A(intArray(239,932)) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(int[].class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
assertEquals(239, ((int[])invoke)[0]);
assertEquals(932, ((int[])invoke)[1]);
}
public void testAnnotationClassWithEnumArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Target(ElementType.TYPE, ElementType.METHOD) annotation class A");
Class aClass = generateClass("A");
Target annotation = (Target)aClass.getAnnotation(Target.class);
ElementType[] value = annotation.value();
assertEquals(2, value.length);
assertEquals(ElementType.TYPE, value[0]);
assertEquals(ElementType.METHOD, value[1]);
}
public void testAnnotationClassWithAnnotationArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" +
"" +
"A(array(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()");
Class aClass = generateClass("A");
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
Retention[] invoke1 = (Retention[])invoke;
assertEquals(2, invoke1.length);
assertEquals(invoke1[0].value(), RetentionPolicy.RUNTIME);
assertEquals(invoke1[1].value(), RetentionPolicy.SOURCE);
}
}
@@ -22,7 +22,7 @@ public class MultiFileGenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
}
public void testSimple() {
@@ -40,4 +40,8 @@ public class MultiFileGenTest extends CodegenTestCase {
public void testSameNames() {
blackBoxMultiFile("/multi/same/1/box.kt", "/multi/same/2/box.kt");
}
public void testKt1515() {
blackBoxMultiFile("/multi/kt1515/thisPackage.kt", "/multi/kt1515/otherPackage.kt");
}
}
@@ -1,213 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.codegen;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import java.lang.annotation.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class StdlibTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
if (myEnvironment != null) {
throw new IllegalStateException("must not set up myEnvironemnt twice");
}
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar()));
}
public void testForInString() throws Exception {
loadText("fun foo() : Int { var sum = 0\n" +
" for(c in \"239\")\n" +
" sum += (c.toInt() - '0'.toInt())\n" +
" return sum" +
"}" );
final Method main = generateFunction();
try {
assertEquals(14, main.invoke(null));
} catch (Throwable t) {
System.out.println(generateToText());
t.printStackTrace();
throw t instanceof Exception ? (Exception)t : new RuntimeException(t);
}
}
public void testAnnotationClassWithClassProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: java.lang.Class<*>)\n" +
"" +
"A(javaClass<String>()) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(Class.class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
assertEquals(String.class, methods[0].invoke(bClassAnnotation));
}
public void testAnnotationClassWithStringArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" +
"" +
"A(array(\"239\",\"932\")) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(String[].class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
assertEquals("239", ((String[])invoke)[0]);
assertEquals("932", ((String[])invoke)[1]);
}
public void testAnnotationClassWithIntArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" +
"" +
"A(intArray(239,932)) class B()");
Class aClass = generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value);
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
assertEquals(int[].class, methods[0].getReturnType());
assertEquals(0, methods[0].getParameterTypes().length);
assertTrue(aClass.isAnnotation());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
assertEquals(239, ((int[])invoke)[0]);
assertEquals(932, ((int[])invoke)[1]);
}
public void testAnnotationClassWithEnumArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Target(ElementType.TYPE, ElementType.METHOD) annotation class A");
Class aClass = generateClass("A");
Target annotation = (Target)aClass.getAnnotation(Target.class);
ElementType[] value = annotation.value();
assertEquals(2, value.length);
assertEquals(ElementType.TYPE, value[0]);
assertEquals(ElementType.METHOD, value[1]);
}
public void testAnnotationClassWithAnnotationArrayProperty()
throws
NoSuchFieldException,
NoSuchMethodException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException,
InvocationTargetException {
loadText("import java.lang.annotation.*\n" +
"" +
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" +
"" +
"A(array(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()");
Class aClass = generateClass("A");
Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length);
assertEquals("a", methods[0].getName());
Class<?> bClass = aClass.getClassLoader().loadClass("B");
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
assertNotNull(bClassAnnotation);
Object invoke = methods[0].invoke(bClassAnnotation);
Retention[] invoke1 = (Retention[])invoke;
assertEquals(2, invoke1.length);
assertEquals(invoke1[0].value(), RetentionPolicy.RUNTIME);
assertEquals(invoke1[1].value(), RetentionPolicy.SOURCE);
}
public void testKt1515() {
blackBoxMultiFile("/multi/kt1515/thisPackage.kt", "/multi/kt1515/otherPackage.kt");
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.codegen;
import com.google.common.base.Supplier;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.jet.test.TestForeverRunner;
public class StdlibTestForever {
public static void main(String[] args) {
TestForeverRunner.runTestForever(args, new Supplier<Test>() {
@Override
public Test get() {
return new TestSuite(StdlibTest.class);
}
});
}
}
@@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxWithStdlib")
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class})
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class})
public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInBoxWithStdlib() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithStdlib"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -693,6 +693,19 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/strings")
public static class Strings extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInStrings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithStdlib/strings"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("forInString.kt")
public void testForInString() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/strings/forInString.kt");
}
}
public static Test suite() {
TestSuite suite = new TestSuite("BlackBoxWithStdlibCodegenTestGenerated");
suite.addTestSuite(BlackBoxWithStdlibCodegenTestGenerated.class);
@@ -701,6 +714,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
suite.addTestSuite(JdkAnnotations.class);
suite.addTest(Ranges.innerSuite());
suite.addTestSuite(Regressions.class);
suite.addTestSuite(Strings.class);
return suite;
}
}
@@ -1,72 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.test;
import com.google.common.base.Supplier;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import org.junit.Assert;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
public class TestForeverRunner {
public static void runTestForever(String[] args, Supplier<Test> suite) {
Assert.assertTrue(TestRunner.run(suite.get()).wasSuccessful());
Assert.assertTrue(TestRunner.run(suite.get()).wasSuccessful());
int limit = args.length > 0 ? Integer.parseInt(args[0]) : Integer.MAX_VALUE;
long total = 0;
long min = Long.MAX_VALUE;
long[] last100 = new long[100];
long[] last10 = new long[10];
for (int i = -100; i < limit; ++i) {
TestRunner runner = new TestRunner();
runner.setPrinter(new ResultPrinter(new PrintStream(new ByteArrayOutputStream())));
long start = System.nanoTime();
TestResult result = runner.doRun(suite.get());
Assert.assertTrue(result.wasSuccessful());
long d = System.nanoTime() - start;
last100[(i + 100) % 100] = d;
last10[(i + 100) % 10] = d;
long dMs = d / 1000 / 1000;
if (i >= 1) {
total += d;
min = Math.min(min, d);
long avg = total / i / 1000 / 1000;
long avg10 = avg(last10) / 1000 / 1000;
long avg100 = avg(last100) / 1000 / 1000;
long minMs = min / 1000 / 1000;
System.out.println(dMs + "ms; avg=" + avg + "ms; avg10=" + avg10 + "ms; avg100=" + avg100 + "ms; min=" + minMs + "ms; iteration=" + i);
}
else {
System.out.println(dMs + "ms; iteration=" + i);
}
}
}
private static long avg(long[] array) {
long sum = 0;
for (long l : array) {
sum += l;
}
return sum / array.length;
}
}