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