Test framework for inline

This commit is contained in:
Mikhael Bogdanov
2014-02-18 12:14:06 +04:00
parent 769b07fbc8
commit 4f5b20a8db
93 changed files with 2593 additions and 8 deletions
@@ -0,0 +1,259 @@
/*
* Copyright 2010-2014 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.generated;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxInline")
public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInBoxInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxInline"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("builders")
public void testBuilders() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/builders");
}
@TestMetadata("captureInlinable")
public void testCaptureInlinable() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/captureInlinable");
}
@TestMetadata("captureInlinableAndOther")
public void testCaptureInlinableAndOther() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/captureInlinableAndOther");
}
@TestMetadata("captureThisAndReceiver")
public void testCaptureThisAndReceiver() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/captureThisAndReceiver");
}
@TestMetadata("classObject")
public void testClassObject() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/classObject");
}
@TestMetadata("closureChain")
public void testClosureChain() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/closureChain");
}
@TestMetadata("extension")
public void testExtension() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/extension");
}
@TestMetadata("forEachLine")
public void testForEachLine() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/forEachLine");
}
@TestMetadata("generics")
public void testGenerics() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/generics");
}
@TestMetadata("identityCheck")
public void testIdentityCheck() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/identityCheck");
}
@TestMetadata("ifBranches")
public void testIfBranches() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/ifBranches");
}
@TestMetadata("iinc")
public void testIinc() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/iinc");
}
@TestMetadata("inlineChain")
public void testInlineChain() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/inlineChain");
}
@TestMetadata("lambdaClassClash")
public void testLambdaClassClash() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/lambdaClassClash");
}
@TestMetadata("lambdaCloning")
public void testLambdaCloning() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/lambdaCloning");
}
@TestMetadata("lambdaInLambda")
public void testLambdaInLambda() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/lambdaInLambda");
}
@TestMetadata("lambdaInLambda2")
public void testLambdaInLambda2() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/lambdaInLambda2");
}
@TestMetadata("lambdaInLambdaNoInline")
public void testLambdaInLambdaNoInline() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/lambdaInLambdaNoInline");
}
@TestMetadata("localFunInLambda")
public void testLocalFunInLambda() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/localFunInLambda");
}
@TestMetadata("noInline")
public void testNoInline() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/noInline");
}
@TestMetadata("noInlineLambdaX2")
public void testNoInlineLambdaX2() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/noInlineLambdaX2");
}
@TestMetadata("params")
public void testParams() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/params");
}
@TestMetadata("plusAssign")
public void testPlusAssign() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/plusAssign");
}
@TestMetadata("regeneratedLambdaName")
public void testRegeneratedLambdaName() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/regeneratedLambdaName");
}
@TestMetadata("rootConstructor")
public void testRootConstructor() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/rootConstructor");
}
@TestMetadata("severalClosures")
public void testSeveralClosures() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/severalClosures");
}
@TestMetadata("severalUsage")
public void testSeveralUsage() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/severalUsage");
}
@TestMetadata("simpleCapturingInClass")
public void testSimpleCapturingInClass() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleCapturingInClass");
}
@TestMetadata("simpleCapturingInPackage")
public void testSimpleCapturingInPackage() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleCapturingInPackage");
}
@TestMetadata("simpleDouble")
public void testSimpleDouble() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleDouble");
}
@TestMetadata("simpleEnum")
public void testSimpleEnum() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleEnum");
}
@TestMetadata("simpleGenerics")
public void testSimpleGenerics() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleGenerics");
}
@TestMetadata("simpleInt")
public void testSimpleInt() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleInt");
}
@TestMetadata("simpleLambda")
public void testSimpleLambda() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleLambda");
}
@TestMetadata("simpleObject")
public void testSimpleObject() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/simpleObject");
}
@TestMetadata("stackHeightBug")
public void testStackHeightBug() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/stackHeightBug");
}
@TestMetadata("trait")
public void testTrait() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/trait");
}
@TestMetadata("tryCatch")
public void testTryCatch() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/tryCatch");
}
@TestMetadata("tryCatch2")
public void testTryCatch2() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/tryCatch2");
}
@TestMetadata("tryCatchFinally")
public void testTryCatchFinally() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/tryCatchFinally");
}
@TestMetadata("use")
public void testUse() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/use");
}
@TestMetadata("vararg")
public void testVararg() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/vararg");
}
@TestMetadata("with")
public void testWith() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/with");
}
@TestMetadata("withoutInline")
public void testWithoutInline() throws Exception {
doTestMultiFile("compiler/testData/codegen/boxInline/withoutInline");
}
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
@@ -27,18 +28,23 @@ import org.jetbrains.jet.OutputFileCollection;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.ClassFileFactory;
import org.jetbrains.jet.codegen.GenerationUtils;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.test.TestCaseWithTmpdir;
import org.jetbrains.jet.utils.UtilsPackage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
private File aDir;
@@ -59,6 +65,39 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
invokeMain();
}
public void doBoxTest(@NotNull String folderName) throws Exception {
final List<String> files = new ArrayList<String>(2);
FileUtil.processFilesRecursively(new File(folderName), new Processor<File>() {
@Override
public boolean process(File file) {
if (file.getName().endsWith(".kt")) {
files.add(file.getPath());
}
return true;
}
});
Collections.sort(files);
ClassFileFactory factory1 = null;
ClassFileFactory factory2 = null;
try {
factory1 = (ClassFileFactory) compileA(new File(files.get(1)));
factory2 = (ClassFileFactory) compileB(new File(files.get(0)));
invokeBox();
} catch (Throwable e) {
String result = "";
if (factory1 != null) {
result += "FIRST: \n\n" + factory1.createText();
}
if (factory2 != null) {
result += "\n\nSECOND: \n\n" + factory2.createText();
}
System.out.println(result);
throw UtilsPackage.rethrow(e);
}
}
private void invokeMain() throws Exception {
URLClassLoader classLoader = new URLClassLoader(
new URL[]{ aDir.toURI().toURL(), bDir.toURI().toURL() },
@@ -69,20 +108,32 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
}
private void compileA(@NotNull File ktAFile) throws IOException {
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(),
ConfigurationKind.JDK_ONLY);
compileKotlin(ktAFile, aDir, jetCoreEnvironment, getTestRootDisposable());
private void invokeBox() throws Exception {
URLClassLoader classLoader = new URLClassLoader(
new URL[]{ bDir.toURI().toURL(), aDir.toURI().toURL() },
AbstractCompileKotlinAgainstKotlinTest.class.getClassLoader()
);
Class<?> clazz = classLoader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
Method box = clazz.getMethod("box", new Class[] {});
String result = (String) box.invoke(null);
assertEquals("OK", result);
}
private void compileB(@NotNull File ktBFile) throws IOException {
private OutputFileCollection compileA(@NotNull File ktAFile) throws IOException {
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(),
ConfigurationKind.JDK_ONLY);
return compileKotlin(ktAFile, aDir, jetCoreEnvironment, getTestRootDisposable());
}
private OutputFileCollection compileB(@NotNull File ktBFile) throws IOException {
CompilerConfiguration configurationWithADirInClasspath = JetTestUtils
.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
compileKotlin(ktBFile, bDir, JetCoreEnvironment.createForTests(getTestRootDisposable(), configurationWithADirInClasspath),
return compileKotlin(ktBFile, bDir, JetCoreEnvironment.createForTests(getTestRootDisposable(), configurationWithADirInClasspath),
getTestRootDisposable());
}
private static void compileKotlin(
private static OutputFileCollection compileKotlin(
@NotNull File file, @NotNull File outputDir, @NotNull JetCoreEnvironment jetCoreEnvironment,
@NotNull Disposable disposable
) throws IOException {
@@ -96,5 +147,6 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
OutputUtilsPackage.writeAllTo(outputFiles, outputDir);
Disposer.dispose(disposable);
return outputFiles;
}
}
@@ -0,0 +1,259 @@
/*
* Copyright 2010-2014 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 java.util.regex.Pattern;
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.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/boxInline")
public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompileKotlinAgainstKotlinTest {
public void testAllFilesPresentInBoxInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxInline"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("builders")
public void testBuilders() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/builders");
}
@TestMetadata("captureInlinable")
public void testCaptureInlinable() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/captureInlinable");
}
@TestMetadata("captureInlinableAndOther")
public void testCaptureInlinableAndOther() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/captureInlinableAndOther");
}
@TestMetadata("captureThisAndReceiver")
public void testCaptureThisAndReceiver() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/captureThisAndReceiver");
}
@TestMetadata("classObject")
public void testClassObject() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/classObject");
}
@TestMetadata("closureChain")
public void testClosureChain() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/closureChain");
}
@TestMetadata("extension")
public void testExtension() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/extension");
}
@TestMetadata("forEachLine")
public void testForEachLine() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/forEachLine");
}
@TestMetadata("generics")
public void testGenerics() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/generics");
}
@TestMetadata("identityCheck")
public void testIdentityCheck() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/identityCheck");
}
@TestMetadata("ifBranches")
public void testIfBranches() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/ifBranches");
}
@TestMetadata("iinc")
public void testIinc() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/iinc");
}
@TestMetadata("inlineChain")
public void testInlineChain() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/inlineChain");
}
@TestMetadata("lambdaClassClash")
public void testLambdaClassClash() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/lambdaClassClash");
}
@TestMetadata("lambdaCloning")
public void testLambdaCloning() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/lambdaCloning");
}
@TestMetadata("lambdaInLambda")
public void testLambdaInLambda() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/lambdaInLambda");
}
@TestMetadata("lambdaInLambda2")
public void testLambdaInLambda2() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/lambdaInLambda2");
}
@TestMetadata("lambdaInLambdaNoInline")
public void testLambdaInLambdaNoInline() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/lambdaInLambdaNoInline");
}
@TestMetadata("localFunInLambda")
public void testLocalFunInLambda() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/localFunInLambda");
}
@TestMetadata("noInline")
public void testNoInline() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/noInline");
}
@TestMetadata("noInlineLambdaX2")
public void testNoInlineLambdaX2() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/noInlineLambdaX2");
}
@TestMetadata("params")
public void testParams() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/params");
}
@TestMetadata("plusAssign")
public void testPlusAssign() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/plusAssign");
}
@TestMetadata("regeneratedLambdaName")
public void testRegeneratedLambdaName() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/regeneratedLambdaName");
}
@TestMetadata("rootConstructor")
public void testRootConstructor() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/rootConstructor");
}
@TestMetadata("severalClosures")
public void testSeveralClosures() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/severalClosures");
}
@TestMetadata("severalUsage")
public void testSeveralUsage() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/severalUsage");
}
@TestMetadata("simpleCapturingInClass")
public void testSimpleCapturingInClass() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleCapturingInClass");
}
@TestMetadata("simpleCapturingInPackage")
public void testSimpleCapturingInPackage() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleCapturingInPackage");
}
@TestMetadata("simpleDouble")
public void testSimpleDouble() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleDouble");
}
@TestMetadata("simpleEnum")
public void testSimpleEnum() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleEnum");
}
@TestMetadata("simpleGenerics")
public void testSimpleGenerics() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleGenerics");
}
@TestMetadata("simpleInt")
public void testSimpleInt() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleInt");
}
@TestMetadata("simpleLambda")
public void testSimpleLambda() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleLambda");
}
@TestMetadata("simpleObject")
public void testSimpleObject() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/simpleObject");
}
@TestMetadata("stackHeightBug")
public void testStackHeightBug() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/stackHeightBug");
}
@TestMetadata("trait")
public void testTrait() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/trait");
}
@TestMetadata("tryCatch")
public void testTryCatch() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/tryCatch");
}
@TestMetadata("tryCatch2")
public void testTryCatch2() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/tryCatch2");
}
@TestMetadata("tryCatchFinally")
public void testTryCatchFinally() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/tryCatchFinally");
}
@TestMetadata("use")
public void testUse() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/use");
}
@TestMetadata("vararg")
public void testVararg() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/vararg");
}
@TestMetadata("with")
public void testWith() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/with");
}
@TestMetadata("withoutInline")
public void testWithoutInline() throws Exception {
doBoxTest("compiler/testData/codegen/boxInline/withoutInline");
}
}