Add tests for lookup tracker with JS KLIB compiler

This commit is contained in:
Alexey Tsvetkov
2020-03-10 06:25:02 +03:00
parent 1c38466a22
commit 6acf9385bd
38 changed files with 625 additions and 3 deletions
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.jps.incremental.createTestingCompilerEnvironment
import org.jetbrains.kotlin.jps.incremental.runJSCompiler
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.utils.JsMetadataVersion
import org.jetbrains.kotlin.utils.PathUtil
import java.io.*
import java.util.*
@@ -109,21 +110,40 @@ abstract class AbstractJvmLookupTrackerTest : AbstractLookupTrackerTest() {
}
}
abstract class AbstractJsKlibLookupTrackerTest : AbstractJsLookupTrackerTest() {
override val jsStdlibFile: File
get() = File("build/js-ir-runtime/full-runtime.klib")
override fun configureAdditionalArgs(args: K2JSCompilerArguments) {
args.irProduceKlibDir = true
args.irOnly = true
args.outputFile = outDir.resolve("out.klib").absolutePath
}
}
abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
private var header: ByteArray? = null
private val packageParts: MutableMap<File, TranslationResultValue> = hashMapOf()
private val serializedIrFiles: MutableMap<File, IrTranslationResultValue> = hashMapOf()
override fun setUp() {
super.setUp()
header = null
packageParts.clear()
serializedIrFiles.clear()
}
override fun Services.Builder.registerAdditionalServices() {
if (header != null) {
register(
IncrementalDataProvider::class.java,
IncrementalDataProviderImpl(header!!, packageParts, JsMetadataVersion.INSTANCE.toArray(), emptyMap(), emptyMap()) // TODO pass correct metadata
IncrementalDataProviderImpl(
headerMetadata = header!!,
compiledPackageParts = packageParts,
metadataVersion = JsMetadataVersion.INSTANCE.toArray(),
packageMetadata = emptyMap(), // TODO pass correct metadata
serializedIrFiles = serializedIrFiles
)
)
}
@@ -131,21 +151,34 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
}
override fun markDirty(removedAndModifiedSources: Iterable<File>) {
removedAndModifiedSources.forEach { packageParts.remove(it) }
removedAndModifiedSources.forEach {
packageParts.remove(it)
serializedIrFiles.remove(it)
}
}
override fun processCompilationResults(outputItemsCollector: OutputItemsCollectorImpl, services: Services) {
val incrementalResults = services.get(IncrementalResultsConsumer::class.java) as IncrementalResultsConsumerImpl
header = incrementalResults.headerMetadata
packageParts.putAll(incrementalResults.packageParts)
serializedIrFiles.putAll(incrementalResults.irFileData)
}
protected open val jsStdlibFile: File
get() = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath
protected open fun configureAdditionalArgs(args: K2JSCompilerArguments) {
args.outputFile = File(outDir, "out.js").canonicalPath
}
override fun runCompiler(filesToCompile: Iterable<File>, env: JpsCompilerEnvironment): Any? {
val args = K2JSCompilerArguments().apply {
outputFile = File(outDir, "out.js").canonicalPath
val libPaths = arrayListOf(jsStdlibFile.absolutePath) + (libraries ?: "").split(File.pathSeparator)
libraries = libPaths.joinToString(File.pathSeparator)
reportOutputFiles = true
freeArgs = filesToCompile.map { it.canonicalPath }
}
configureAdditionalArgs(args)
return runJSCompiler(args, env)
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.jps.build;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("jps-plugin/testData/incremental/lookupTracker/jsKlib")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class JsKlibLookupTrackerTestGenerated extends AbstractJsKlibLookupTrackerTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInJsKlib() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps-plugin/testData/incremental/lookupTracker/jsKlib"), Pattern.compile("^([^\\.]+)$"), null, false);
}
@TestMetadata("classifierMembers")
public void testClassifierMembers() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/classifierMembers/");
}
@TestMetadata("conventions")
public void testConventions() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/conventions/");
}
@TestMetadata("expressionType")
public void testExpressionType() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/expressionType/");
}
@TestMetadata("localDeclarations")
public void testLocalDeclarations() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/localDeclarations/");
}
@TestMetadata("packageDeclarations")
public void testPackageDeclarations() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/packageDeclarations/");
}
@TestMetadata("simple")
public void testSimple() throws Exception {
runTest("jps-plugin/testData/incremental/lookupTracker/jsKlib/simple/");
}
}