[BTA tests] Introduce BaseTest providing CompilationService instance
^KT-61860 In Progress
This commit is contained in:
committed by
Space Team
parent
cf8e65b3c5
commit
3f6b5ae86d
+1
-1
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.io.TempDir
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
@TestDataPath("\$CONTENT_ROOT/../main/resources/modules")
|
@TestDataPath("\$CONTENT_ROOT/../main/resources/modules")
|
||||||
abstract class BaseCompilationTest {
|
abstract class BaseCompilationTest : BaseTest() {
|
||||||
@TempDir
|
@TempDir
|
||||||
lateinit var workingDirectory: Path
|
lateinit var workingDirectory: Path
|
||||||
}
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2024 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.buildtools.api.tests.compilation.model
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.buildtools.api.CompilationService
|
||||||
|
|
||||||
|
abstract class BaseTest {
|
||||||
|
companion object {
|
||||||
|
val compilationService: CompilationService by lazy {
|
||||||
|
CompilationService.loadImplementation(BaseTest::class.java.classLoader)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-3
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation.model
|
package org.jetbrains.kotlin.buildtools.api.tests.compilation.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.buildtools.api.CompilationService
|
|
||||||
import org.junit.jupiter.api.Named.named
|
import org.junit.jupiter.api.Named.named
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext
|
import org.junit.jupiter.api.extension.ExtensionContext
|
||||||
import org.junit.jupiter.params.provider.Arguments
|
import org.junit.jupiter.params.provider.Arguments
|
||||||
@@ -14,9 +13,8 @@ import java.util.stream.Stream
|
|||||||
import kotlin.streams.asStream
|
import kotlin.streams.asStream
|
||||||
|
|
||||||
class DefaultStrategyAgnosticCompilationTestArgumentProvider : ArgumentsProvider {
|
class DefaultStrategyAgnosticCompilationTestArgumentProvider : ArgumentsProvider {
|
||||||
private val compilationService = CompilationService.loadImplementation(this.javaClass.classLoader)
|
|
||||||
|
|
||||||
override fun provideArguments(context: ExtensionContext): Stream<out Arguments> {
|
override fun provideArguments(context: ExtensionContext): Stream<out Arguments> {
|
||||||
|
val compilationService = BaseTest.compilationService
|
||||||
return sequenceOf(
|
return sequenceOf(
|
||||||
named("in-process", compilationService.makeCompilerExecutionStrategyConfiguration().useInProcessStrategy()),
|
named("in-process", compilationService.makeCompilerExecutionStrategyConfiguration().useInProcessStrategy()),
|
||||||
named("within daemon", compilationService.makeCompilerExecutionStrategyConfiguration().useDaemonStrategy(emptyList())),
|
named("within daemon", compilationService.makeCompilerExecutionStrategyConfiguration().useDaemonStrategy(emptyList())),
|
||||||
|
|||||||
+6
-4
@@ -40,7 +40,7 @@ class JvmModule(
|
|||||||
val stdlibLocation =
|
val stdlibLocation =
|
||||||
KotlinVersion::class.java.protectionDomain.codeSource.location.toURI().toPath() // compile against the provided stdlib
|
KotlinVersion::class.java.protectionDomain.codeSource.location.toURI().toPath() // compile against the provided stdlib
|
||||||
val dependencyFiles = dependencies.map { it.location }.plusElement(stdlibLocation)
|
val dependencyFiles = dependencies.map { it.location }.plusElement(stdlibLocation)
|
||||||
val compilationConfig = project.compilationService.makeJvmCompilationConfiguration()
|
val compilationConfig = BaseTest.compilationService.makeJvmCompilationConfiguration()
|
||||||
compilationConfigAction(compilationConfig)
|
compilationConfigAction(compilationConfig)
|
||||||
compilationConfig.useLogger(kotlinLogger)
|
compilationConfig.useLogger(kotlinLogger)
|
||||||
val defaultCompilationArguments = listOf(
|
val defaultCompilationArguments = listOf(
|
||||||
@@ -50,7 +50,7 @@ class JvmModule(
|
|||||||
"-cp", dependencyFiles.joinToString(File.pathSeparator),
|
"-cp", dependencyFiles.joinToString(File.pathSeparator),
|
||||||
"-module-name", moduleName,
|
"-module-name", moduleName,
|
||||||
)
|
)
|
||||||
return project.compilationService.compileJvm(
|
return BaseTest.compilationService.compileJvm(
|
||||||
project.projectId,
|
project.projectId,
|
||||||
strategyConfig,
|
strategyConfig,
|
||||||
compilationConfig,
|
compilationConfig,
|
||||||
@@ -60,8 +60,10 @@ class JvmModule(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateClasspathSnapshot(dependency: Dependency): Path {
|
private fun generateClasspathSnapshot(dependency: Dependency): Path {
|
||||||
val snapshot =
|
val snapshot = BaseTest.compilationService.calculateClasspathSnapshot(
|
||||||
project.compilationService.calculateClasspathSnapshot(dependency.location.toFile(), ClassSnapshotGranularity.CLASS_MEMBER_LEVEL)
|
dependency.location.toFile(),
|
||||||
|
ClassSnapshotGranularity.CLASS_MEMBER_LEVEL
|
||||||
|
)
|
||||||
val hash = snapshot.classSnapshots.values
|
val hash = snapshot.classSnapshots.values
|
||||||
.filterIsInstance<AccessibleClassSnapshot>()
|
.filterIsInstance<AccessibleClassSnapshot>()
|
||||||
.withIndex()
|
.withIndex()
|
||||||
|
|||||||
+1
-3
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.buildtools.api.tests.compilation.model
|
package org.jetbrains.kotlin.buildtools.api.tests.compilation.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.buildtools.api.CompilationService
|
|
||||||
import org.jetbrains.kotlin.buildtools.api.ProjectId
|
import org.jetbrains.kotlin.buildtools.api.ProjectId
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@@ -18,7 +17,6 @@ class Project(
|
|||||||
val projectDirectory: Path,
|
val projectDirectory: Path,
|
||||||
) {
|
) {
|
||||||
val projectId = ProjectId.ProjectUUID(UUID.randomUUID())
|
val projectId = ProjectId.ProjectUUID(UUID.randomUUID())
|
||||||
val compilationService = CompilationService.loadImplementation(this.javaClass.classLoader)
|
|
||||||
|
|
||||||
fun module(
|
fun module(
|
||||||
moduleName: String,
|
moduleName: String,
|
||||||
@@ -37,7 +35,7 @@ class Project(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun endCompilationRound() {
|
fun endCompilationRound() {
|
||||||
compilationService.finishProjectCompilation(projectId)
|
BaseTest.compilationService.finishProjectCompilation(projectId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -5,16 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.buildtools.api.tests
|
package org.jetbrains.kotlin.buildtools.api.tests
|
||||||
|
|
||||||
import org.jetbrains.kotlin.buildtools.api.CompilationService
|
import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.BaseTest
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Disabled
|
import org.junit.jupiter.api.Disabled
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
@Disabled("Example tests for evaluation purposes of the DSL")
|
@Disabled("Example tests for evaluation purposes of the DSL")
|
||||||
class ExampleCompatibilityTest {
|
class ExampleCompatibilityTest : BaseTest() {
|
||||||
private val compilationService = CompilationService.loadImplementation(ExampleCompatibilityTest::class.java.classLoader)
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Sample compatibility test that is run as part of each test suit")
|
@DisplayName("Sample compatibility test that is run as part of each test suit")
|
||||||
fun testDefaultNonIncrementalSettings() {
|
fun testDefaultNonIncrementalSettings() {
|
||||||
|
|||||||
Reference in New Issue
Block a user