New test framework

This commit is contained in:
Michael Bogdanov
2015-02-16 17:10:36 +03:00
parent 7f788f86fe
commit 57cf4ac6c0
9 changed files with 267 additions and 111 deletions
@@ -193,4 +193,9 @@ public class ClassFileFactory implements OutputFileCollection {
generators.remove(classInternalName + ".class");
}
}
@TestOnly
public List<JetFile> getInputFiles() {
return state.getFiles();
}
}
@@ -83,29 +83,13 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
doTestMultiFile(files);
}
private void doTestMultiFile(@NotNull List<String> files) {
protected void doTestMultiFile(@NotNull List<String> files) {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
Collections.sort(files);
loadFiles(ArrayUtil.toStringArray(files));
blackBox();
}
public void doTestMultiFileWithInlineCheck(@NotNull String firstFileName) {
firstFileName = relativePath(new File(firstFileName));
List<String> inputFiles = new ArrayList<String>(2);
inputFiles.add(firstFileName);
inputFiles.add(firstFileName.substring(0, firstFileName.length() - "1.kt".length()) + "2.kt");
doTestMultiFile(inputFiles);
try {
InlineTestUtil.checkNoCallsToInline(initializedClassLoader.getAllGeneratedFiles());
}
catch (Throwable e) {
System.out.println(generateToText());
throw UtilsPackage.rethrow(e);
}
}
private void blackBoxFileAgainstJavaByFullPath(@NotNull String ktFileFullPath) {
String ktFile = relativePath(new File(ktFileFullPath));
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2015 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.kotlin.codegen.generated
import org.jetbrains.kotlin.codegen.InlineTestUtil
import org.jetbrains.kotlin.jvm.compiler.AbstractSMAPBaseTest
import java.io.File
public abstract class AbstractBlackBoxInlineCodegenTest : AbstractBlackBoxCodegenTest(), AbstractSMAPBaseTest {
public fun doTestMultiFileWithInlineCheck(firstFileName: String) {
val fileName = relativePath(File(firstFileName))
val inputFiles = listOf(fileName, fileName.substringBeforeLast("1.kt") + "2.kt")
doTestMultiFile(inputFiles)
try {
InlineTestUtil.checkNoCallsToInline(initializedClassLoader.getAllGeneratedFiles())
checkSMAP(myFiles.getPsiFiles(), generateClassesInFile().asList())
}
catch (e: Throwable) {
System.out.println(generateToText())
throw e
}
}
}
@@ -48,7 +48,7 @@ import java.util.regex.Pattern;
BlackBoxInlineCodegenTestGenerated.TryCatchFinally.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInBoxInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -56,7 +56,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class AnonymousObject extends AbstractBlackBoxCodegenTest {
public static class AnonymousObject extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInAnonymousObject() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -89,7 +89,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/builders")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Builders extends AbstractBlackBoxCodegenTest {
public static class Builders extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInBuilders() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/builders"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -110,7 +110,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/capture")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Capture extends AbstractBlackBoxCodegenTest {
public static class Capture extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInCapture() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/capture"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -155,7 +155,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/complex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Complex extends AbstractBlackBoxCodegenTest {
public static class Complex extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInComplex() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/complex"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -194,7 +194,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/defaultValues")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DefaultValues extends AbstractBlackBoxCodegenTest {
public static class DefaultValues extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInDefaultValues() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -239,7 +239,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LambdaClassClash extends AbstractBlackBoxCodegenTest {
public static class LambdaClassClash extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInLambdaClassClash() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/lambdaClassClash"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -260,7 +260,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/lambdaTransformation")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LambdaTransformation extends AbstractBlackBoxCodegenTest {
public static class LambdaTransformation extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInLambdaTransformation() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/lambdaTransformation"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -299,7 +299,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/localFunInLambda")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LocalFunInLambda extends AbstractBlackBoxCodegenTest {
public static class LocalFunInLambda extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInLocalFunInLambda() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/localFunInLambda"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -314,7 +314,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NoInline extends AbstractBlackBoxCodegenTest {
public static class NoInline extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInNoInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/noInline"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -351,7 +351,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
NonLocalReturns.TryFinally.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public static class NonLocalReturns extends AbstractBlackBoxCodegenTest {
public static class NonLocalReturns extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInNonLocalReturns() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -401,7 +401,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/deparenthesize")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Deparenthesize extends AbstractBlackBoxCodegenTest {
public static class Deparenthesize extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInDeparenthesize() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/deparenthesize"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -427,7 +427,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
TryFinally.ExceptionTable.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public static class TryFinally extends AbstractBlackBoxCodegenTest {
public static class TryFinally extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInTryFinally() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -435,7 +435,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class CallSite extends AbstractBlackBoxCodegenTest {
public static class CallSite extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInCallSite() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -462,7 +462,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DeclSite extends AbstractBlackBoxCodegenTest {
public static class DeclSite extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInDeclSite() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -525,7 +525,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ExceptionTable extends AbstractBlackBoxCodegenTest {
public static class ExceptionTable extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInExceptionTable() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -632,7 +632,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/reified")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Reified extends AbstractBlackBoxCodegenTest {
public static class Reified extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInReified() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/reified"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -647,7 +647,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/simple")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Simple extends AbstractBlackBoxCodegenTest {
public static class Simple extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInSimple() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/simple"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -740,7 +740,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/special")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Special extends AbstractBlackBoxCodegenTest {
public static class Special extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInSpecial() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/special"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -785,7 +785,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/trait")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Trait extends AbstractBlackBoxCodegenTest {
public static class Trait extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInTrait() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/trait"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -800,7 +800,7 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT
@TestMetadata("compiler/testData/codegen/boxInline/tryCatchFinally")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class TryCatchFinally extends AbstractBlackBoxCodegenTest {
public static class TryCatchFinally extends AbstractBlackBoxInlineCodegenTest {
public void testAllFilesPresentInTryCatchFinally() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/tryCatchFinally"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2015 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.kotlin.jvm.compiler
import org.jetbrains.kotlin.codegen.ClassFileFactory
import org.jetbrains.kotlin.codegen.InlineTestUtil
import java.io.File
import java.util.Collections
public abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCompileKotlinAgainstKotlinTest(), AbstractSMAPBaseTest {
public fun doBoxTestWithInlineCheck(firstFileName: String) {
val inputFiles = listOf(firstFileName, firstFileName.substringBeforeLast("1.kt") + "2.kt")
val (factory1, factory2) = doBoxTest(inputFiles)
val allGeneratedFiles = factory1.asList() + factory2.asList()
InlineTestUtil.checkNoCallsToInline(allGeneratedFiles)
val sourceFiles = factory1.getInputFiles() + factory2.getInputFiles()
checkSMAP(sourceFiles, allGeneratedFiles)
}
private fun doBoxTest(files: List<String>): Pair<ClassFileFactory, ClassFileFactory> {
Collections.sort(files)
var factory1: ClassFileFactory? = null
var factory2: ClassFileFactory? = null
try {
factory1 = compileA(File(files[1]))
factory2 = compileB(File(files[0]))
invokeBox()
}
catch (e: Throwable) {
var 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 e
}
return Pair(factory1!!, factory2!!)
}
}
@@ -21,14 +21,12 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.kotlin.codegen.ClassFileFactory;
import org.jetbrains.kotlin.codegen.GenerationUtils;
import org.jetbrains.kotlin.codegen.InlineTestUtil;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
@@ -38,16 +36,12 @@ import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
import org.jetbrains.kotlin.test.TestJdkKind;
import org.jetbrains.kotlin.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;
@@ -68,48 +62,13 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
invokeMain();
}
public void doBoxTestWithInlineCheck(@NotNull String firstFileName) throws Exception {
List<String> inputFiles = new ArrayList<String>(2);
inputFiles.add(firstFileName);
inputFiles.add(firstFileName.substring(0, firstFileName.length() - "1.kt".length()) + "2.kt");
List<OutputFile> files = doBoxTest(inputFiles);
InlineTestUtil.checkNoCallsToInline(files);
}
@NotNull
private List<OutputFile> doBoxTest(@NotNull List<String> files) throws Exception {
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);
}
List<OutputFile> allGeneratedFiles = new ArrayList<OutputFile>(factory1.asList());
allGeneratedFiles.addAll(factory2.asList());
return allGeneratedFiles;
}
private void invokeMain() throws Exception {
Method main = generatedClass().getMethod("main", String[].class);
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
}
private void invokeBox() throws Exception {
protected void invokeBox() throws Exception {
Method box = generatedClass().getMethod("box");
String result = (String) box.invoke(null);
assertEquals("OK", result);
@@ -124,13 +83,13 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
return classLoader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
}
private OutputFileCollection compileA(@NotNull File ktAFile) throws IOException {
protected ClassFileFactory compileA(@NotNull File ktAFile) throws IOException {
JetCoreEnvironment jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(),
ConfigurationKind.ALL);
return compileKotlin(ktAFile, aDir, jetCoreEnvironment, getTestRootDisposable());
}
private OutputFileCollection compileB(@NotNull File ktBFile) throws IOException {
protected ClassFileFactory compileB(@NotNull File ktBFile) throws IOException {
CompilerConfiguration configurationWithADirInClasspath = JetTestUtils
.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), aDir);
@@ -140,7 +99,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
return compileKotlin(ktBFile, bDir, environment, getTestRootDisposable());
}
private static OutputFileCollection compileKotlin(
private static ClassFileFactory compileKotlin(
@NotNull File file, @NotNull File outputDir, @NotNull JetCoreEnvironment jetCoreEnvironment,
@NotNull Disposable disposable
) throws IOException {
@@ -149,7 +108,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
JetFile psiFile = JetTestUtils.createFile(file.getName(), text, jetCoreEnvironment.getProject());
OutputFileCollection outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
ClassFileFactory outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
OutputUtilsPackage.writeAllTo(outputFiles, outputDir);
@@ -0,0 +1,109 @@
/*
* Copyright 2010-2015 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.kotlin.jvm.compiler
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.backend.common.output.OutputFile
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.JetTestUtils
import org.jetbrains.org.objectweb.asm.ClassReader
import org.jetbrains.org.objectweb.asm.ClassVisitor
import org.jetbrains.org.objectweb.asm.Opcodes
import org.junit.Assert
import java.io.File
public trait AbstractSMAPBaseTest {
private fun extractSMAPFromClasses(outputFiles: List<OutputFile>): List<SMAPAndFile> {
return outputFiles.map { outputFile ->
if (PackageClassUtils.isPackageClassFqName(FqName(FileUtil.getNameWithoutExtension(outputFile.relativePath).replace('/', '.')))) {
// Don't test line numbers in *Package facade classes
null
}
else {
var debugInfo: String? = null
ClassReader(outputFile.asByteArray()).accept(object : ClassVisitor(Opcodes.ASM5) {
override fun visitSource(source: String?, debug: String?) {
debugInfo = debug
}
}, 0)
SMAPAndFile.SMAPAndFile(debugInfo, outputFile.sourceFiles.single())
}
}.filterNotNull()
}
private fun extractSmapFromSource(file: JetFile): SMAPAndFile? {
val fileContent = file.getText()
val smapPrefix = "//SMAP"
if (InTextDirectivesUtils.isDirectiveDefined(fileContent, smapPrefix)) {
InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileContent, smapPrefix)
var smapData = fileContent.substring(fileContent.indexOf(smapPrefix))
smapData = smapData.replaceAll("//", "").trim()
return SMAPAndFile(if (smapData.startsWith("SMAP ABSENT")) null else smapData,
SMAPAndFile.getPath(file.getVirtualFile().getCanonicalPath()!!))
}
return null;
}
fun checkSMAP(inputFiles: List<JetFile>, outputFiles: List<OutputFile>) {
val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull()
val compiledData = extractSMAPFromClasses(outputFiles).groupBy {
it.sourceFile
}.map {
val smap = it.getValue().map { replaceHash(it.smap) }.filterNotNull().join("\n")
SMAPAndFile(if (smap.isNotEmpty()) smap else null, it.key)
}.toMap { it.sourceFile }
for (source in sourceData) {
val data = compiledData[source.sourceFile]
Assert.assertEquals("Smap data differs for ${source.sourceFile}", source.smap, data?.smap?.trim())
}
}
fun replaceHash(data: String?): String? {
if (data == null) return null
val fileSectionStart = data.indexOf("*F") + 3
val lineSection = data.indexOf("*L") - 1
val files = data.substring(fileSectionStart, lineSection).split("\n")
val cleaned = files.map { JetTestUtils.replaceHashWithStar(it).replace("*", "HASH") }.join("\n")
return data.substring(0, fileSectionStart) + cleaned + data.substring(lineSection)
}
class SMAPAndFile(val smap: String?, val sourceFile: String) {
default object {
fun SMAPAndFile(smap: String?, sourceFile: File) = SMAPAndFile(smap, getPath(sourceFile))
public fun getPath(file: File): String {
return getPath(file.getCanonicalPath())
}
public fun getPath(canonicalPath: String): String {
//There are some problems with disk name on windows cause LightVirtualFile return it without disk name
return FileUtil.toSystemIndependentName(canonicalPath).substringAfter(":")
}
}
}
}
@@ -48,7 +48,7 @@ import java.util.regex.Pattern;
CompileKotlinAgainstInlineKotlinTestGenerated.TryCatchFinally.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompileKotlinAgainstKotlinTest {
public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInBoxInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -56,7 +56,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class AnonymousObject extends AbstractCompileKotlinAgainstKotlinTest {
public static class AnonymousObject extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInAnonymousObject() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -89,7 +89,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/builders")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Builders extends AbstractCompileKotlinAgainstKotlinTest {
public static class Builders extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInBuilders() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/builders"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -110,7 +110,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/capture")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Capture extends AbstractCompileKotlinAgainstKotlinTest {
public static class Capture extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInCapture() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/capture"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -155,7 +155,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/complex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Complex extends AbstractCompileKotlinAgainstKotlinTest {
public static class Complex extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInComplex() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/complex"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -194,7 +194,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/defaultValues")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DefaultValues extends AbstractCompileKotlinAgainstKotlinTest {
public static class DefaultValues extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInDefaultValues() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/defaultValues"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -239,7 +239,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LambdaClassClash extends AbstractCompileKotlinAgainstKotlinTest {
public static class LambdaClassClash extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInLambdaClassClash() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/lambdaClassClash"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -260,7 +260,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/lambdaTransformation")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LambdaTransformation extends AbstractCompileKotlinAgainstKotlinTest {
public static class LambdaTransformation extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInLambdaTransformation() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/lambdaTransformation"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -299,7 +299,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/localFunInLambda")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LocalFunInLambda extends AbstractCompileKotlinAgainstKotlinTest {
public static class LocalFunInLambda extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInLocalFunInLambda() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/localFunInLambda"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -314,7 +314,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class NoInline extends AbstractCompileKotlinAgainstKotlinTest {
public static class NoInline extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInNoInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/noInline"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -351,7 +351,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
NonLocalReturns.TryFinally.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public static class NonLocalReturns extends AbstractCompileKotlinAgainstKotlinTest {
public static class NonLocalReturns extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInNonLocalReturns() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -401,7 +401,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/deparenthesize")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Deparenthesize extends AbstractCompileKotlinAgainstKotlinTest {
public static class Deparenthesize extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInDeparenthesize() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/deparenthesize"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -427,7 +427,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
TryFinally.ExceptionTable.class,
})
@RunWith(JUnit3RunnerWithInners.class)
public static class TryFinally extends AbstractCompileKotlinAgainstKotlinTest {
public static class TryFinally extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInTryFinally() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -435,7 +435,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class CallSite extends AbstractCompileKotlinAgainstKotlinTest {
public static class CallSite extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInCallSite() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -462,7 +462,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DeclSite extends AbstractCompileKotlinAgainstKotlinTest {
public static class DeclSite extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInDeclSite() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -525,7 +525,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ExceptionTable extends AbstractCompileKotlinAgainstKotlinTest {
public static class ExceptionTable extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInExceptionTable() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -632,7 +632,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/reified")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Reified extends AbstractCompileKotlinAgainstKotlinTest {
public static class Reified extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInReified() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/reified"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -647,7 +647,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/simple")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Simple extends AbstractCompileKotlinAgainstKotlinTest {
public static class Simple extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInSimple() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/simple"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -740,7 +740,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/special")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Special extends AbstractCompileKotlinAgainstKotlinTest {
public static class Special extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInSpecial() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/special"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -785,7 +785,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/trait")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Trait extends AbstractCompileKotlinAgainstKotlinTest {
public static class Trait extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInTrait() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/trait"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -800,7 +800,7 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
@TestMetadata("compiler/testData/codegen/boxInline/tryCatchFinally")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class TryCatchFinally extends AbstractCompileKotlinAgainstKotlinTest {
public static class TryCatchFinally extends AbstractCompileKotlinAgainstInlineKotlinTest {
public void testAllFilesPresentInTryCatchFinally() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/tryCatchFinally"), Pattern.compile("^(.+)\\.1.kt$"), true);
}
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.defaultConstructor.AbstractDefaultArgumentsReflectionTest
import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest
import org.jetbrains.kotlin.codegen.generated.AbstractBlackBoxCodegenTest
import org.jetbrains.kotlin.codegen.generated.AbstractBlackBoxInlineCodegenTest
import org.jetbrains.kotlin.completion.*
import org.jetbrains.kotlin.completion.handlers.AbstractBasicCompletionHandlerTest
import org.jetbrains.kotlin.completion.handlers.AbstractCompletionCharFilterTest
@@ -90,10 +91,7 @@ import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
import org.jetbrains.kotlin.jps.build.AbstractIncrementalJpsTest
import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase
import org.jetbrains.kotlin.js.test.semantics.*
import org.jetbrains.kotlin.jvm.compiler.AbstractCompileJavaAgainstKotlinTest
import org.jetbrains.kotlin.jvm.compiler.AbstractCompileKotlinAgainstKotlinTest
import org.jetbrains.kotlin.jvm.compiler.AbstractLoadJavaTest
import org.jetbrains.kotlin.jvm.compiler.AbstractWriteSignatureTest
import org.jetbrains.kotlin.jvm.compiler.*
import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBoxTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBytecodeShapeTest
@@ -165,11 +163,11 @@ fun main(args: Array<String>) {
model("codegen/box")
}
testClass(javaClass<AbstractBlackBoxCodegenTest>(), "BlackBoxInlineCodegenTestGenerated") {
testClass(javaClass<AbstractBlackBoxInlineCodegenTest>(), "BlackBoxInlineCodegenTestGenerated") {
model("codegen/boxInline", extension = "1.kt", testMethod = "doTestMultiFileWithInlineCheck")
}
testClass(javaClass<AbstractCompileKotlinAgainstKotlinTest>(), "CompileKotlinAgainstInlineKotlinTestGenerated") {
testClass(javaClass<AbstractCompileKotlinAgainstInlineKotlinTest>(), "CompileKotlinAgainstInlineKotlinTestGenerated") {
model("codegen/boxInline", extension = "1.kt", testMethod = "doBoxTestWithInlineCheck")
}