Refactor CompileKotlinAgainstKotlinTest
CKAKTest is now abstract, the actual testcases are generated via GenerateTests into CompileKotlinAgainstKotlinTestGenerated. Also invokeMain() now invokes namespace.main instead of bbb.namespace.main.
This commit is contained in:
+2
@@ -1 +1,3 @@
|
||||
package aaa
|
||||
|
||||
class A(val a: Int = 1)
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
package bbb
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
A()
|
||||
aaa.A()
|
||||
}
|
||||
-3
@@ -1,9 +1,6 @@
|
||||
package bbb
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val h = aaa.hello()
|
||||
if (h != 17) {
|
||||
throw Exception()
|
||||
}
|
||||
System.out?.println("It is 17!")
|
||||
}
|
||||
+17
-52
@@ -20,10 +20,11 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.*;
|
||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
@@ -33,31 +34,12 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.test.TestCaseWithTmpdir;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors", "JUnitTestCaseWithNoTests"})
|
||||
public final class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
|
||||
private final File ktAFile;
|
||||
private final File ktBFile;
|
||||
|
||||
public CompileKotlinAgainstKotlinTest(@NotNull File ktAFile) {
|
||||
Assert.assertTrue(ktAFile.getName().endsWith("A.kt"));
|
||||
this.ktAFile = ktAFile;
|
||||
this.ktBFile = new File(ktAFile.getPath().replaceFirst("A\\.kt$", "B.kt"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return ktAFile.getName();
|
||||
}
|
||||
|
||||
public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
private File aDir;
|
||||
private File bDir;
|
||||
|
||||
@@ -70,32 +52,31 @@ public final class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
JetTestUtils.mkdirs(bDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
compileA();
|
||||
compileB();
|
||||
public void doTest(@NotNull String fileName) throws Exception {
|
||||
compileA(new File(fileName));
|
||||
compileB(new File(fileName.replaceFirst("A\\.kt$", "B.kt")));
|
||||
invokeMain();
|
||||
}
|
||||
|
||||
private void invokeMain()
|
||||
throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
private void invokeMain() throws Exception {
|
||||
URLClassLoader classLoader = new URLClassLoader(
|
||||
new URL[]{ aDir.toURI().toURL(), bDir.toURI().toURL() },
|
||||
CompileKotlinAgainstKotlinTest.class.getClassLoader()
|
||||
AbstractCompileKotlinAgainstKotlinTest.class.getClassLoader()
|
||||
);
|
||||
Class<?> clazz = classLoader.loadClass("bbb.namespace");
|
||||
Method main = clazz.getMethod("main", new Class[] { String[].class });
|
||||
Class<?> clazz = classLoader.loadClass("namespace");
|
||||
Method main = clazz.getMethod("main", new Class[] {String[].class});
|
||||
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
|
||||
}
|
||||
|
||||
private void compileA() throws IOException {
|
||||
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable());
|
||||
private void compileA(@NotNull File ktAFile) throws IOException {
|
||||
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(),
|
||||
ConfigurationKind.JDK_ONLY);
|
||||
compileKotlin(ktAFile, aDir, jetCoreEnvironment, getTestRootDisposable());
|
||||
}
|
||||
|
||||
private void compileB() throws IOException {
|
||||
private void compileB(@NotNull File ktBFile) throws IOException {
|
||||
CompilerConfiguration configurationWithADirInClasspath = CompileCompilerDependenciesTest
|
||||
.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
|
||||
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
|
||||
compileKotlin(ktBFile, bDir, new JetCoreEnvironment(getTestRootDisposable(), configurationWithADirInClasspath),
|
||||
getTestRootDisposable());
|
||||
}
|
||||
@@ -115,20 +96,4 @@ public final class CompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
|
||||
Disposer.dispose(disposable);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
class Filter implements FilenameFilter {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith("A.kt");
|
||||
}
|
||||
}
|
||||
return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/compileKotlinAgainstKotlin", true, new Filter(), new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) {
|
||||
return new CompileKotlinAgainstKotlinTest(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.jvm.compiler;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.jvm.compiler.AbstractCompileKotlinAgainstKotlinTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@TestMetadata("compiler/testData/compileKotlinAgainstKotlin")
|
||||
public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotlinAgainstKotlinTest {
|
||||
public void testAllFilesPresentInCompileKotlinAgainstKotlin() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/compileKotlinAgainstKotlin"), "A.kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("DefaultConstructor.A.kt")
|
||||
public void testDefaultConstructor_A() throws Exception {
|
||||
doTest("compiler/testData/compileKotlinAgainstKotlin/DefaultConstructor.A.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Simple.A.kt")
|
||||
public void testSimple_A() throws Exception {
|
||||
doTest("compiler/testData/compileKotlinAgainstKotlin/Simple.A.kt");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.codegen.defaultConstructor.AbstractDefaultConstructorCo
|
||||
import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest;
|
||||
import org.jetbrains.jet.codegen.generated.AbstractCodegenTest;
|
||||
import org.jetbrains.jet.jvm.compiler.AbstractCompileJavaAgainstKotlinTest;
|
||||
import org.jetbrains.jet.jvm.compiler.AbstractCompileKotlinAgainstKotlinTest;
|
||||
import org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest;
|
||||
import org.jetbrains.jet.jvm.compiler.AbstractLoadJavaTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
|
||||
@@ -166,6 +167,13 @@ public class GenerateTests {
|
||||
testModel("compiler/testData/compileJavaAgainstKotlin", "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"compiler/tests/",
|
||||
"CompileKotlinAgainstKotlinTestGenerated",
|
||||
AbstractCompileKotlinAgainstKotlinTest.class,
|
||||
testModel("compiler/testData/compileKotlinAgainstKotlin", true, "A.kt", "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"compiler/tests/",
|
||||
"LazyResolveDescriptorRendererTestGenerated",
|
||||
|
||||
Reference in New Issue
Block a user