[K/N] Mark unit testing API with ExperimentalNativeApi
As a part of efforts to stabilize Native stdlib #KT-55765.
This commit is contained in:
committed by
Space Team
parent
8c748bfea4
commit
e7225d29ff
@@ -5,6 +5,9 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal class GTestLogger : TestLoggerWithStatistics() {
|
||||
|
||||
private val Collection<TestSuite>.totalTestsNotIgnored: Int
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
import kotlin.system.exitProcess
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@@ -15,21 +16,24 @@ import kotlin.native.concurrent.*
|
||||
// So we keep this object public but protect it with @ExperimentalStdlibApi
|
||||
// to stress that it is not a part of the stable API.
|
||||
// Related YT issue: KT-47915.
|
||||
@ExperimentalStdlibApi
|
||||
@ExperimentalNativeApi
|
||||
@ThreadLocal
|
||||
public object GeneratedSuites {
|
||||
val suites = mutableListOf<TestSuite>()
|
||||
fun add(suite: TestSuite) = suites.add(suite)
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public fun registerSuite(suite: TestSuite): Unit {
|
||||
GeneratedSuites.add(suite)
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
fun testLauncherEntryPoint(args: Array<String>): Int {
|
||||
return TestRunner(GeneratedSuites.suites, args).run()
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
fun main(args: Array<String>) {
|
||||
val exitCode = testLauncherEntryPoint(args)
|
||||
if (exitCode != 0) {
|
||||
@@ -38,6 +42,7 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
@OptIn(FreezingIsDeprecated::class)
|
||||
@ExperimentalNativeApi
|
||||
fun worker(args: Array<String>) {
|
||||
val worker = Worker.start()
|
||||
val exitCode = worker.execute(TransferMode.SAFE, { args.freeze() }) {
|
||||
@@ -49,6 +54,7 @@ fun worker(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
fun mainNoExit(args: Array<String>) {
|
||||
testLauncherEntryPoint(args)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
import kotlin.text.StringBuilder
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal class TeamCityLogger : BaseTestLogger() {
|
||||
|
||||
private fun String.escapeForTC(): String = StringBuilder(length).apply {
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal interface TestListener {
|
||||
fun startTesting(runner: TestRunner)
|
||||
fun finishTesting(runner: TestRunner, timeMillis: Long)
|
||||
@@ -22,6 +25,7 @@ internal interface TestListener {
|
||||
fun ignore(testCase: TestCase)
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal open class BaseTestListener: TestListener {
|
||||
override fun startTesting(runner: TestRunner) {}
|
||||
override fun finishTesting(runner: TestRunner, timeMillis: Long) {}
|
||||
|
||||
@@ -5,11 +5,15 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal interface TestLogger: TestListener {
|
||||
fun logTestList(runner: TestRunner, suites: Collection<TestSuite>)
|
||||
fun log(message: String)
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal open class BaseTestLogger: BaseTestListener(), TestLogger {
|
||||
override fun log(message: String) = println(message)
|
||||
override fun logTestList(runner: TestRunner, suites: Collection<TestSuite>) {
|
||||
@@ -22,6 +26,7 @@ internal open class BaseTestLogger: BaseTestListener(), TestLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal open class TestLoggerWithStatistics: BaseTestLogger() {
|
||||
|
||||
protected val statistics = MutableTestStatistics()
|
||||
@@ -36,12 +41,14 @@ internal open class TestLoggerWithStatistics: BaseTestLogger() {
|
||||
override fun ignore(testCase: TestCase) = statistics.registerIgnore(testCase)
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal class SilentTestLogger: BaseTestLogger() {
|
||||
override fun logTestList(runner: TestRunner, suites: Collection<TestSuite>) {}
|
||||
override fun log(message: String) {}
|
||||
override fun fail(testCase: TestCase, e: Throwable, timeMillis: Long) = e.printStackTrace()
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal class SimpleTestLogger: BaseTestLogger() {
|
||||
override fun startTesting(runner: TestRunner) = println("Starting testing")
|
||||
override fun finishTesting(runner: TestRunner, timeMillis: Long) = println("Testing finished")
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
import kotlin.IllegalArgumentException
|
||||
import kotlin.text.StringBuilder
|
||||
import kotlin.time.TimeSource
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@OptIn(kotlin.time.ExperimentalTime::class)
|
||||
@ExperimentalNativeApi
|
||||
internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
private val filters = mutableListOf<(TestCase) -> Boolean>()
|
||||
private val listeners = mutableSetOf<TestListener>()
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal interface TestStatistics {
|
||||
val total: Int
|
||||
val passed: Int
|
||||
@@ -17,6 +20,7 @@ internal interface TestStatistics {
|
||||
val hasFailedTests: Boolean
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal class MutableTestStatistics: TestStatistics {
|
||||
|
||||
override var total: Int = 0; private set
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.experimental.ExperimentalNativeApi
|
||||
import kotlin.IllegalArgumentException
|
||||
import kotlin.system.getTimeMillis
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public interface TestCase {
|
||||
val name: String
|
||||
val ignored: Boolean
|
||||
@@ -17,8 +19,10 @@ public interface TestCase {
|
||||
fun run()
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
internal val TestCase.prettyName get() = "${suite.name}.$name"
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public interface TestSuite {
|
||||
val name: String
|
||||
val ignored: Boolean
|
||||
@@ -29,6 +33,7 @@ public interface TestSuite {
|
||||
fun doAfterClass()
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public enum class TestFunctionKind {
|
||||
BEFORE_TEST,
|
||||
AFTER_TEST,
|
||||
@@ -36,6 +41,7 @@ public enum class TestFunctionKind {
|
||||
AFTER_CLASS
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public abstract class AbstractTestSuite<F: Function<Unit>>(override val name: String, override val ignored: Boolean)
|
||||
: TestSuite {
|
||||
override fun toString(): String = name
|
||||
@@ -69,6 +75,7 @@ public abstract class AbstractTestSuite<F: Function<Unit>>(override val name: St
|
||||
get() = testCases.size
|
||||
}
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public abstract class BaseClassSuite<INSTANCE, COMPANION>(name: String, ignored: Boolean)
|
||||
: AbstractTestSuite<INSTANCE.() -> Unit>(name, ignored) {
|
||||
|
||||
@@ -134,6 +141,7 @@ public abstract class BaseClassSuite<INSTANCE, COMPANION>(name: String, ignored:
|
||||
|
||||
private typealias TopLevelFun = () -> Unit
|
||||
|
||||
@ExperimentalNativeApi
|
||||
public class TopLevelSuite(name: String): AbstractTestSuite<TopLevelFun>(name, false) {
|
||||
|
||||
class TestCase(name: String, override val suite: TopLevelSuite, testFunction: TopLevelFun, ignored: Boolean)
|
||||
|
||||
Reference in New Issue
Block a user