Get rid of unsafe cast function usages in :native:native.tests
This commit is contained in:
committed by
Space Team
parent
51e337a148
commit
3e1eddcf54
@@ -415,7 +415,6 @@ val projectsWithOptInToUnsafeCastFunctionsFromAddToStdLib by extra {
|
|||||||
":kotlin-scripting-jvm-host-test",
|
":kotlin-scripting-jvm-host-test",
|
||||||
":native:frontend.native",
|
":native:frontend.native",
|
||||||
":native:kotlin-klib-commonizer",
|
":native:kotlin-klib-commonizer",
|
||||||
":native:native.tests",
|
|
||||||
":plugins:android-extensions-compiler",
|
":plugins:android-extensions-compiler",
|
||||||
":plugins:jvm-abi-gen",
|
":plugins:jvm-abi-gen",
|
||||||
":plugins:parcelize:parcelize-compiler:parcelize.k1",
|
":plugins:parcelize:parcelize-compiler:parcelize.k1",
|
||||||
|
|||||||
+1
-2
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.runner.get
|
|||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeHome
|
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeHome
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.SafeEnvVars
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.SafeEnvVars
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.SafeProperties
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.SafeProperties
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.DurationUnit
|
import kotlin.time.DurationUnit
|
||||||
@@ -64,7 +63,7 @@ internal abstract class LoggedData {
|
|||||||
get() = buildList {
|
get() = buildList {
|
||||||
sourceModules.forEach { module ->
|
sourceModules.forEach { module ->
|
||||||
if (module !is TestModule.Exclusive) return@forEach
|
if (module !is TestModule.Exclusive) return@forEach
|
||||||
this += module.testCase.id.safeAs<TestCaseId.TestDataFile>()?.file ?: return@forEach
|
this += (module.testCase.id as? TestCaseId.TestDataFile)?.file ?: return@forEach
|
||||||
}
|
}
|
||||||
sort()
|
sort()
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-8
@@ -22,8 +22,6 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
|||||||
import org.jetbrains.kotlin.test.TestMetadata
|
import org.jetbrains.kotlin.test.TestMetadata
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import org.junit.jupiter.api.extension.BeforeAllCallback
|
import org.junit.jupiter.api.extension.BeforeAllCallback
|
||||||
import org.junit.jupiter.api.extension.BeforeEachCallback
|
import org.junit.jupiter.api.extension.BeforeEachCallback
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext
|
import org.junit.jupiter.api.extension.ExtensionContext
|
||||||
@@ -83,7 +81,7 @@ private object NativeTestSupport {
|
|||||||
computeNativeClassLoader(),
|
computeNativeClassLoader(),
|
||||||
computeBaseDirs()
|
computeBaseDirs()
|
||||||
)
|
)
|
||||||
}.cast()
|
} as TestProcessSettings
|
||||||
|
|
||||||
private fun computeNativeHome(): KotlinNativeHome = KotlinNativeHome(File(ProcessLevelProperty.KOTLIN_NATIVE_HOME.readValue()))
|
private fun computeNativeHome(): KotlinNativeHome = KotlinNativeHome(File(ProcessLevelProperty.KOTLIN_NATIVE_HOME.readValue()))
|
||||||
|
|
||||||
@@ -318,7 +316,7 @@ private object NativeTestSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestClassSettings(parent = testProcessSettings, settings)
|
TestClassSettings(parent = testProcessSettings, settings)
|
||||||
}.cast()
|
} as TestClassSettings
|
||||||
|
|
||||||
private fun computeTestConfiguration(enclosingTestClass: Class<*>): ComputedTestConfiguration {
|
private fun computeTestConfiguration(enclosingTestClass: Class<*>): ComputedTestConfiguration {
|
||||||
val findTestConfiguration: Class<*>.() -> ComputedTestConfiguration? = {
|
val findTestConfiguration: Class<*>.() -> ComputedTestConfiguration? = {
|
||||||
@@ -423,7 +421,7 @@ private object NativeTestSupport {
|
|||||||
parent = getOrCreateTestProcessSettings(),
|
parent = getOrCreateTestProcessSettings(),
|
||||||
buildList { addCommonTestClassSettingsTo(enclosingTestClass, this) }
|
buildList { addCommonTestClassSettingsTo(enclosingTestClass, this) }
|
||||||
)
|
)
|
||||||
}.cast()
|
} as SimpleTestClassSettings
|
||||||
|
|
||||||
/*************** Test run settings (for black box tests only) ***************/
|
/*************** Test run settings (for black box tests only) ***************/
|
||||||
|
|
||||||
@@ -435,7 +433,8 @@ private object NativeTestSupport {
|
|||||||
parent = getOrCreateTestClassSettings(),
|
parent = getOrCreateTestClassSettings(),
|
||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
testInstances,
|
testInstances,
|
||||||
ExternalSourceTransformersProvider::class to testInstances.enclosingTestInstance.safeAs<ExternalSourceTransformersProvider>()
|
(testInstances.enclosingTestInstance as? ExternalSourceTransformersProvider)
|
||||||
|
?.let { ExternalSourceTransformersProvider::class to it }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -478,7 +477,7 @@ private object NativeTestSupport {
|
|||||||
root.getStore(NAMESPACE).getOrComputeIfAbsent(testClassKeyFor<TestRunProvider>()) {
|
root.getStore(NAMESPACE).getOrComputeIfAbsent(testClassKeyFor<TestRunProvider>()) {
|
||||||
val testCaseGroupProvider = createTestCaseGroupProvider(getOrCreateTestClassSettings().get())
|
val testCaseGroupProvider = createTestCaseGroupProvider(getOrCreateTestClassSettings().get())
|
||||||
TestRunProvider(testCaseGroupProvider)
|
TestRunProvider(testCaseGroupProvider)
|
||||||
}.cast()
|
} as TestRunProvider
|
||||||
|
|
||||||
private fun createTestCaseGroupProvider(computedTestConfiguration: ComputedTestConfiguration): TestCaseGroupProvider {
|
private fun createTestCaseGroupProvider(computedTestConfiguration: ComputedTestConfiguration): TestCaseGroupProvider {
|
||||||
val (testConfiguration: TestConfiguration, testConfigurationAnnotation: Annotation) = computedTestConfiguration
|
val (testConfiguration: TestConfiguration, testConfigurationAnnotation: Annotation) = computedTestConfiguration
|
||||||
@@ -498,7 +497,7 @@ private object NativeTestSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return constructor.call(*arguments.toTypedArray()).cast()
|
return constructor.call(*arguments.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KParameter.hasTypeOf(clazz: KClass<*>): Boolean = (type.classifier as? KClass<*>)?.qualifiedName == clazz.qualifiedName
|
private fun KParameter.hasTypeOf(clazz: KClass<*>): Boolean = (type.classifier as? KClass<*>)?.qualifiedName == clazz.qualifiedName
|
||||||
|
|||||||
+10
-2
@@ -8,13 +8,21 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.settings
|
|||||||
import gnu.trove.THashMap
|
import gnu.trove.THashMap
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal abstract class Settings(private val parent: Settings?, settings: Iterable<Any>) {
|
internal abstract class Settings(private val parent: Settings?, settings: Iterable<Any>) {
|
||||||
private val map: Map<KClass<*>, Any> = THashMap<KClass<*>, Any>().apply {
|
private val map: Map<KClass<*>, Any> = THashMap<KClass<*>, Any>().apply {
|
||||||
settings.forEach {
|
settings.forEach {
|
||||||
val (settingClass: KClass<*>, setting: Any) = if (it is Pair<*, *>) it.cast() else it::class to it
|
val settingClass: KClass<*>
|
||||||
|
val setting: Any
|
||||||
|
if (it is Pair<*, *>) {
|
||||||
|
settingClass = it.first as KClass<*>
|
||||||
|
setting = it.second ?: error("Setting $settingClass is null")
|
||||||
|
} else {
|
||||||
|
settingClass = it::class
|
||||||
|
setting = it
|
||||||
|
}
|
||||||
|
|
||||||
val previous = put(settingClass, setting)
|
val previous = put(settingClass, setting)
|
||||||
assertTrue(previous == null) { "Duplicated settings: $settingClass, $previous, $setting" }
|
assertTrue(previous == null) { "Duplicated settings: $settingClass, $previous, $setting" }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.konan.blackboxtest.support.settings
|
package org.jetbrains.kotlin.konan.blackboxtest.support.settings
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeSimpleTest
|
import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeSimpleTest
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +16,7 @@ import java.io.File
|
|||||||
*/
|
*/
|
||||||
internal class SimpleTestInstances(val allInstances: List<Any>) {
|
internal class SimpleTestInstances(val allInstances: List<Any>) {
|
||||||
val enclosingTestInstance: AbstractNativeSimpleTest
|
val enclosingTestInstance: AbstractNativeSimpleTest
|
||||||
get() = allInstances.firstOrNull().cast()
|
get() = allInstances.firstOrNull() as AbstractNativeSimpleTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-2
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.settings
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeBlackBoxTest
|
import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeBlackBoxTest
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.ExternalSourceTransformers
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.ExternalSourceTransformers
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +17,7 @@ import java.io.File
|
|||||||
*/
|
*/
|
||||||
internal class BlackBoxTestInstances(val allInstances: List<Any>) {
|
internal class BlackBoxTestInstances(val allInstances: List<Any>) {
|
||||||
val enclosingTestInstance: AbstractNativeBlackBoxTest
|
val enclosingTestInstance: AbstractNativeBlackBoxTest
|
||||||
get() = allInstances.firstOrNull().cast()
|
get() = allInstances.firstOrNull() as AbstractNativeBlackBoxTest
|
||||||
}
|
}
|
||||||
|
|
||||||
internal interface ExternalSourceTransformersProvider {
|
internal interface ExternalSourceTransformersProvider {
|
||||||
|
|||||||
+1
-3
@@ -7,8 +7,6 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.util
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts [TestName]s from the test listing produced immediately during the compilation (turned on with
|
* Extracts [TestName]s from the test listing produced immediately during the compilation (turned on with
|
||||||
@@ -110,7 +108,7 @@ internal object GTestListing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline val ParseState.testSuite: ParseState.NewTestSuite
|
private inline val ParseState.testSuite: ParseState.NewTestSuite
|
||||||
get() = safeAs<ParseState.NewTestSuite>() ?: cast<ParseState.NewTest>().testSuite
|
get() = this as? ParseState.NewTestSuite ?: (this as ParseState.NewTest).testSuite
|
||||||
|
|
||||||
// The very first line of stdlib test output may contain seed of Random. Such line should be ignored.
|
// The very first line of stdlib test output may contain seed of Random. Such line should be ignored.
|
||||||
private const val STDLIB_TESTS_IGNORED_LINE_PREFIX = "Seed: "
|
private const val STDLIB_TESTS_IGNORED_LINE_PREFIX = "Seed: "
|
||||||
|
|||||||
+2
-4
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.util
|
|||||||
import jetbrains.buildServer.messages.serviceMessages.*
|
import jetbrains.buildServer.messages.serviceMessages.*
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.TCTestReportParseState as State
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.TCTestReportParseState as State
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
|
|
||||||
@@ -160,7 +158,7 @@ private class TCTestMessageParserCallback : ServiceMessageParserCallback {
|
|||||||
|
|
||||||
fun finish() {
|
fun finish() {
|
||||||
// The last test state is "TestStarted" this likely means that the test process terminated during test execution (SIGSEGV, etc).
|
// The last test state is "TestStarted" this likely means that the test process terminated during test execution (SIGSEGV, etc).
|
||||||
state.safeAs<State.TestStarted>()?.let { failedTests += it.testName }
|
(state as? State.TestStarted)?.let { failedTests += it.testName }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +179,6 @@ private sealed interface TCTestReportParseState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline val State.testSuite: State.TestSuiteStarted
|
private inline val State.testSuite: State.TestSuiteStarted
|
||||||
get() = if (this is State.TestSuiteStarted) this else cast<State.TestState>().testSuite
|
get() = if (this is State.TestSuiteStarted) this else (this as State.TestState).testSuite
|
||||||
|
|
||||||
private inline val BaseTestMessage.simpleTestName get() = testName
|
private inline val BaseTestMessage.simpleTestName get() = testName
|
||||||
|
|||||||
Reference in New Issue
Block a user