[Test] Inject info about test (class and method names, tags) to TestServices
This commit is contained in:
committed by
TeamCityServer
parent
84eb74e194
commit
ce44a2a7e4
+14
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.test.services
|
||||||
|
|
||||||
|
data class KotlinTestInfo(
|
||||||
|
val className: String,
|
||||||
|
val methodName: String,
|
||||||
|
val tags: Set<String>
|
||||||
|
) : TestService
|
||||||
|
|
||||||
|
val TestServices.testInfo: KotlinTestInfo by TestServices.testServiceAccessor()
|
||||||
+12
@@ -36,6 +36,17 @@ class TestConfigurationBuilder {
|
|||||||
val defaultRegisteredDirectivesBuilder: RegisteredDirectivesBuilder = RegisteredDirectivesBuilder()
|
val defaultRegisteredDirectivesBuilder: RegisteredDirectivesBuilder = RegisteredDirectivesBuilder()
|
||||||
|
|
||||||
private val configurationsByTestDataCondition: MutableList<Pair<Regex, TestConfigurationBuilder.() -> Unit>> = mutableListOf()
|
private val configurationsByTestDataCondition: MutableList<Pair<Regex, TestConfigurationBuilder.() -> Unit>> = mutableListOf()
|
||||||
|
private val additionalServices: MutableList<ServiceRegistrationData> = mutableListOf()
|
||||||
|
|
||||||
|
lateinit var testInfo: KotlinTestInfo
|
||||||
|
|
||||||
|
inline fun <reified T : TestService> useAdditionalService(noinline serviceConstructor: (TestServices) -> T) {
|
||||||
|
useAdditionalService(service(serviceConstructor))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun useAdditionalService(serviceRegistrationData: ServiceRegistrationData) {
|
||||||
|
additionalServices += serviceRegistrationData
|
||||||
|
}
|
||||||
|
|
||||||
fun forTestsMatching(pattern: String, configuration: TestConfigurationBuilder.() -> Unit) {
|
fun forTestsMatching(pattern: String, configuration: TestConfigurationBuilder.() -> Unit) {
|
||||||
val regex = pattern.toMatchingRegexString().toRegex()
|
val regex = pattern.toMatchingRegexString().toRegex()
|
||||||
@@ -127,6 +138,7 @@ class TestConfigurationBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TestConfigurationImpl(
|
return TestConfigurationImpl(
|
||||||
|
testInfo,
|
||||||
defaultsProviderBuilder.build(),
|
defaultsProviderBuilder.build(),
|
||||||
assertions,
|
assertions,
|
||||||
facades,
|
facades,
|
||||||
|
|||||||
+2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.test.runners.AbstractFirDiagnosticTest
|
|||||||
import org.jetbrains.kotlin.test.services.TestServices
|
import org.jetbrains.kotlin.test.services.TestServices
|
||||||
import org.jetbrains.kotlin.test.services.assertions
|
import org.jetbrains.kotlin.test.services.assertions
|
||||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||||
|
import org.jetbrains.kotlin.test.services.testInfo
|
||||||
import org.jetbrains.kotlin.test.utils.firTestDataFile
|
import org.jetbrains.kotlin.test.utils.firTestDataFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class FirTestDataConsistencyHandler(testServices: TestServices) : AfterAnalysisC
|
|||||||
private fun runFirTestAndGeneratedTestData(testData: File, firTestData: File) {
|
private fun runFirTestAndGeneratedTestData(testData: File, firTestData: File) {
|
||||||
firTestData.writeText(clearTextFromDiagnosticMarkup(testData.readText()))
|
firTestData.writeText(clearTextFromDiagnosticMarkup(testData.readText()))
|
||||||
val test = object : AbstractFirDiagnosticTest() {}
|
val test = object : AbstractFirDiagnosticTest() {}
|
||||||
|
test.initTestInfo(testServices.testInfo.copy(className = "${testServices.testInfo.className}_fir_anonymous"))
|
||||||
test.runTest(firTestData.absolutePath)
|
test.runTest(firTestData.absolutePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.test.services.impl.ModuleStructureExtractorImpl
|
|||||||
import org.jetbrains.kotlin.test.utils.TestDisposable
|
import org.jetbrains.kotlin.test.utils.TestDisposable
|
||||||
|
|
||||||
class TestConfigurationImpl(
|
class TestConfigurationImpl(
|
||||||
|
testInfo: KotlinTestInfo,
|
||||||
|
|
||||||
defaultsProvider: DefaultsProvider,
|
defaultsProvider: DefaultsProvider,
|
||||||
assertions: AssertionsService,
|
assertions: AssertionsService,
|
||||||
|
|
||||||
@@ -35,11 +37,17 @@ class TestConfigurationImpl(
|
|||||||
override val metaInfoHandlerEnabled: Boolean,
|
override val metaInfoHandlerEnabled: Boolean,
|
||||||
|
|
||||||
directives: List<DirectivesContainer>,
|
directives: List<DirectivesContainer>,
|
||||||
override val defaultRegisteredDirectives: RegisteredDirectives
|
override val defaultRegisteredDirectives: RegisteredDirectives,
|
||||||
|
additionalServices: List<ServiceRegistrationData>
|
||||||
) : TestConfiguration() {
|
) : TestConfiguration() {
|
||||||
override val rootDisposable: Disposable = TestDisposable()
|
override val rootDisposable: Disposable = TestDisposable()
|
||||||
override val testServices: TestServices = TestServices()
|
override val testServices: TestServices = TestServices()
|
||||||
|
|
||||||
|
init {
|
||||||
|
testServices.register(KotlinTestInfo::class, testInfo)
|
||||||
|
additionalServices.forEach { testServices.register(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private val allDirectives = directives.toMutableSet()
|
private val allDirectives = directives.toMutableSet()
|
||||||
override val directives: DirectivesContainer by lazy {
|
override val directives: DirectivesContainer by lazy {
|
||||||
when (allDirectives.size) {
|
when (allDirectives.size) {
|
||||||
@@ -81,7 +89,7 @@ class TestConfigurationImpl(
|
|||||||
testServices.apply {
|
testServices.apply {
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) }
|
val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) }
|
||||||
val sourceFileProvider = SourceFileProviderImpl(sourceFilePreprocessors)
|
val sourceFileProvider = SourceFileProviderImpl(this, sourceFilePreprocessors)
|
||||||
register(SourceFileProvider::class, sourceFileProvider)
|
register(SourceFileProvider::class, sourceFileProvider)
|
||||||
|
|
||||||
val environmentProvider = CompilerConfigurationProviderImpl(rootDisposable, this@TestConfigurationImpl.environmentConfigurators)
|
val environmentProvider = CompilerConfigurationProviderImpl(rootDisposable, this@TestConfigurationImpl.environmentConfigurators)
|
||||||
|
|||||||
+22
@@ -14,8 +14,11 @@ import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives
|
|||||||
import org.jetbrains.kotlin.test.preprocessors.MetaInfosCleanupPreprocessor
|
import org.jetbrains.kotlin.test.preprocessors.MetaInfosCleanupPreprocessor
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
||||||
import org.jetbrains.kotlin.test.services.SourceFilePreprocessor
|
import org.jetbrains.kotlin.test.services.SourceFilePreprocessor
|
||||||
|
import org.jetbrains.kotlin.test.services.KotlinTestInfo
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||||
import org.jetbrains.kotlin.types.FlexibleTypeImpl
|
import org.jetbrains.kotlin.types.FlexibleTypeImpl
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.TestInfo
|
||||||
|
|
||||||
abstract class AbstractKotlinCompilerTest {
|
abstract class AbstractKotlinCompilerTest {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -43,8 +46,27 @@ abstract class AbstractKotlinCompilerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract fun TestConfigurationBuilder.configuration()
|
abstract fun TestConfigurationBuilder.configuration()
|
||||||
|
private lateinit var testInfo: KotlinTestInfo
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun initTestInfo(testInfo: TestInfo) {
|
||||||
|
initTestInfo(
|
||||||
|
KotlinTestInfo(
|
||||||
|
className = testInfo.testClass.orElseGet(null)?.name ?: "_undefined_",
|
||||||
|
methodName = testInfo.testMethod.orElseGet(null)?.name ?: "_testUndefined_",
|
||||||
|
tags = testInfo.tags
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun initTestInfo(testInfo: KotlinTestInfo) {
|
||||||
|
this.testInfo = testInfo
|
||||||
|
}
|
||||||
|
|
||||||
open fun configure(builder: TestConfigurationBuilder) {
|
open fun configure(builder: TestConfigurationBuilder) {
|
||||||
|
with(builder) {
|
||||||
|
testInfo = this@AbstractKotlinCompilerTest.testInfo
|
||||||
|
}
|
||||||
builder.configuration()
|
builder.configuration()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user