Extract junit testcase, delete unneeded code

This commit is contained in:
Alexander Udalov
2013-02-07 21:07:33 +04:00
committed by Alexander Udalov
parent 8a605b3884
commit b311255d96
6 changed files with 60 additions and 82 deletions
@@ -0,0 +1,56 @@
/*
* 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 org.junit.Test;
import java.io.File;
import java.lang.reflect.Method;
public class JUnitUsageGenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
File junitJar = new File("libraries/lib/junit-4.9.jar");
if (!junitJar.exists()) {
throw new AssertionError("JUnit jar wasn't found");
}
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, junitJar));
}
public void testKt2344() throws Exception {
loadFile("junit/kt2344.kt");
generateFunction().invoke(null);
}
public void testKt1592() throws Exception {
loadFile("junit/kt1592.kt");
Class<?> namespaceClass = generateNamespaceClass();
Method method = namespaceClass.getMethod("foo", Method.class);
method.setAccessible(true);
Test annotation = method.getAnnotation(Test.class);
assertEquals(annotation.timeout(), 0l);
assertEquals(annotation.expected(), Test.None.class);
}
}
@@ -16,68 +16,27 @@
package org.jetbrains.jet.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.junit.Test;
import java.io.File;
import java.lang.annotation.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class StdlibTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
File junitJar = new File("libraries/lib/junit-4.9.jar");
if (!junitJar.exists()) {
throw new AssertionError();
}
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(), junitJar));
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar()));
}
@NotNull
@Override
protected GeneratedClassLoader createClassLoader(@NotNull ClassFileFactory codegens) {
try {
return new GeneratedClassLoader(
codegens,
new URLClassLoader(new URL[]{ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()},
getClass().getClassLoader()));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
//from NamespaceGenTest
// public void testPredicateOperator() throws Exception {
// loadText("fun foo(s: String) = s?startsWith(\"J\")");
// final Method main = generateFunction();
// try {
// assertEquals("JetBrains", main.invoke(null, "JetBrains"));
// assertNull(main.invoke(null, "IntelliJ"));
// } catch (Throwable t) {
//// System.out.println(generateToText());
// t.printStackTrace();
// throw t instanceof Exception ? (Exception)t : new RuntimeException(t);
// }
// }
//
public void testForInString() throws Exception {
loadText("fun foo() : Int { var sum = 0\n" +
" for(c in \"239\")\n" +
@@ -94,17 +53,6 @@ public class StdlibTest extends CodegenTestCase {
}
}
public void testKt1592 () throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
loadFile("regressions/kt1592.kt");
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFile())).getFqName().getFqName();
Class<?> namespaceClass = generateClass(fqName);
Method method = namespaceClass.getMethod("foo", Method.class);
method.setAccessible(true);
Test annotation = method.getAnnotation(Test.class);
assertEquals(annotation.timeout(), 0l);
assertEquals(annotation.expected(), Test.None.class);
}
public void testAnnotationClassWithClassProperty()
throws
NoSuchFieldException,