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
@@ -52,8 +52,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
private JetCoreEnvironment environmentWithMockJdk = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
private JetCoreEnvironment environmentWithFullJdk = JetTestUtils.createEnvironmentWithFullJdk(myTestRootDisposable);
private JetCoreEnvironment environmentWithFullJdkAndJUnit;
private final Pattern packagePattern = Pattern.compile("package (.*)");
private final List<String> generatedTestNames = Lists.newArrayList();
@@ -64,16 +63,6 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
private CodegenTestsOnAndroidGenerator(PathManager pathManager) {
this.pathManager = pathManager;
File junitJar = new File("libraries/lib/junit-4.9.jar");
if (!junitJar.exists()) {
throw new AssertionError();
}
environmentWithFullJdkAndJUnit = new JetCoreEnvironment(myTestRootDisposable, JetTestUtils.compilerConfigurationForTests(
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, JetTestUtils.getAnnotationsJar(), junitJar));
}
private void generateOutputFiles() throws Throwable {
@@ -130,7 +119,6 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
Assert.assertNotNull("Folder with testData is empty: " + dir.getAbsolutePath(), files);
Set<String> excludedFiles = SpecialFiles.getExcludedFiles();
Set<String> filesCompiledWithoutStdLib = SpecialFiles.getFilesCompiledWithoutStdLib();
Set<String> filesCompiledWithJUnit = SpecialFiles.getFilesCompiledWithJUnit();
for (File file : files) {
if (excludedFiles.contains(file.getName())) {
continue;
@@ -149,9 +137,6 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
if (filesCompiledWithoutStdLib.contains(file.getName())) {
factory = getFactoryFromText(file.getAbsolutePath(), text, environmentWithMockJdk);
}
else if (filesCompiledWithJUnit.contains(file.getName())) {
factory = getFactoryFromText(file.getAbsolutePath(), text, environmentWithFullJdkAndJUnit);
}
else {
factory = getFactoryFromText(file.getAbsolutePath(), text, environmentWithFullJdk);
}
@@ -24,19 +24,13 @@ import java.util.Set;
public class SpecialFiles {
private static final Set<String> excludedFiles = Sets.newHashSet();
private static final Set<String> filesCompiledWithoutStdLib = Sets.newHashSet();
private static final Set<String> filesCompiledWithJUnit = Sets.newHashSet();
static {
fillExcludedFiles();
fillFilesCompiledWithoutStdLib();
fillFilesCompiledWithJUnit();
}
public static Set<String> getFilesCompiledWithJUnit() {
return filesCompiledWithJUnit;
}
public static Set<String> getExcludedFiles() {
return excludedFiles;
}
@@ -45,10 +39,6 @@ public class SpecialFiles {
return filesCompiledWithoutStdLib;
}
private static void fillFilesCompiledWithJUnit() {
filesCompiledWithJUnit.add("kt2334.kt");
}
private static void fillFilesCompiledWithoutStdLib() {
filesCompiledWithoutStdLib.add("kt1980.kt");
filesCompiledWithoutStdLib.add("kt1953_class.kt"); // Exception in code
@@ -7,7 +7,6 @@ public class Test {
}
}
fun box() : String {
Test().f()
return "OK"
fun foo() {
Test().f()
}
@@ -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,