Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumping to Kotlin 1.8.10 #3403

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/PR.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
target:
- jvmTest
- jsIrTest
- jsTest
- linuxX64Test
- :kotest-framework:kotest-framework-multiplatform-plugin-gradle:test
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
target:
- jvmTest
- jsIrTest
- jsTest
- linuxX64Test
- :kotest-framework:kotest-framework-multiplatform-plugin-gradle:test
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
target:
- jvmTest publishJvmPublicationToDeployRepository publishKotlinMultiplatformPublicationToDeployRepository publishKotestBomPublicationToDeployRepository
- jsIrTest publishJsPublicationToDeployRepository
- jsTest publishJsPublicationToDeployRepository
- linuxX64Test publishLinuxX64PublicationToDeployRepository
steps:
- uses: kotest/kotest-action@master
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kotest-js-conventions.gradle.kts
Expand Up @@ -5,7 +5,7 @@ plugins {
kotlin {
targets {
if (!project.hasProperty(Ci.JVM_ONLY)) {
js(BOTH) {
js(IR) {
browser()
nodejs()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Expand Up @@ -9,7 +9,7 @@ json-path = "2.7.0"
junit4 = "4.13.2"
junit-platform = "1.7.2"
junit-jupiter = "5.8.2"
kotlin = "1.6.21"
kotlin = "1.8.10"
kotlinx-coroutines = "1.6.4"
kotlinx-serialization = "1.3.3"
ktor = "1.6.8"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Expand Up @@ -6,6 +6,7 @@ import kotlin.time.Duration
import kotlin.time.DurationUnit
import io.kotest.common.MonotonicTimeSourceCompat
import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds

/**
* Retry [f] until it's a success or [maxRetry]/[timeout] is reached
Expand All @@ -26,7 +27,7 @@ import kotlinx.coroutines.delay
suspend fun <T> retry(
maxRetry: Int,
timeout: Duration,
delay: Duration = Duration.seconds(1),
delay: Duration = 1.seconds,
multiplier: Int = 1,
f: suspend () -> T
): T = retry(maxRetry, timeout, delay, multiplier, Exception::class, f)
Expand All @@ -51,7 +52,7 @@ suspend fun <T> retry(
suspend fun <T, E : Throwable> retry(
maxRetry: Int,
timeout: Duration,
delay: Duration = Duration.seconds(1),
delay: Duration = 1.seconds,
multiplier: Int = 1,
exceptionClass: KClass<E>,
f: suspend () -> T
Expand Down
Expand Up @@ -2,6 +2,7 @@ package io.kotest.assertions.until

import kotlin.math.pow
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours

/**
* Exponential interval implements a delay where each duration is calculated as a multiplier
Expand All @@ -23,7 +24,7 @@ class ExponentialInterval(private val base: Duration, private val factor: Double
}

companion object {
val defaultMax = Duration.hours(2)
val defaultMax = 2.hours
const val defaultFactor = 2.0
}
}
Expand Down
@@ -1,6 +1,8 @@
package io.kotest.assertions.until

import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.milliseconds

/**
* Fibonacci delay implements a delay where each duration is calculated as a multiplier
Expand All @@ -24,12 +26,12 @@ class FibonacciInterval(private val base: Duration, private val offset: Int, pri
override fun next(count: Int): Duration {
val baseMs = base.inWholeMilliseconds
val total = baseMs * fibonacci(offset + count)
val result = Duration.milliseconds(total)
val result = total.milliseconds
return if (max == null) result else minOf(max, result)
}

companion object {
val defaultMax = Duration.hours(2)
val defaultMax = 2.hours
}
}

Expand Down
Expand Up @@ -4,6 +4,7 @@ import io.kotest.assertions.failure
import kotlin.time.Duration
import io.kotest.common.MonotonicTimeSourceCompat
import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds

fun interface UntilListener<in T> {
fun onEval(t: T)
Expand Down Expand Up @@ -32,7 +33,7 @@ data class PatienceConfig(
* This method supports suspension.
*/
suspend fun until(duration: Duration, f: suspend () -> Boolean) =
until(duration, interval = Duration.seconds(1).fixed(), f = f)
until(duration, interval = 1.seconds.fixed(), f = f)

/**
* Executes a function at a given interval until it returns true, or until a specified duration has elapsed.
Expand Down Expand Up @@ -71,7 +72,7 @@ suspend fun <T> until(
duration: Duration,
predicate: suspend (T) -> Boolean,
f: suspend () -> T
): T = until(duration, interval = Duration.seconds(1).fixed(), predicate = predicate, f = f)
): T = until(duration, interval = 1.seconds.fixed(), predicate = predicate, f = f)

/**
* Executes the function [f] at a given [interval] until it returns a value that passes the given [predicate],
Expand Down Expand Up @@ -108,7 +109,7 @@ suspend fun <T> until(
@Deprecated("Simply move the listener code into the predicate code. Will be removed in 6.0")
suspend fun <T> until(
duration: Duration,
interval: Interval = Duration.seconds(1).fixed(),
interval: Interval = 1.seconds.fixed(),
predicate: suspend (T) -> Boolean,
listener: UntilListener<T>,
f: suspend () -> T
Expand Down
Expand Up @@ -6,22 +6,14 @@ import kotlin.native.concurrent.isFrozen

actual class AtomicReference<T> actual constructor(initialValue: T) {

private val delegate = FreezableAtomicReference(initialValue)
private val delegate = AtomicReference(initialValue)

actual var value: T
get() = delegate.value
set(value) {
delegate.value = value.freezeIfNeeded()
delegate.value = value
}

actual fun compareAndSet(expectedValue: T, newValue: T): Boolean =
delegate.compareAndSet(expectedValue, newValue.freezeIfNeeded())

private fun T.freezeIfNeeded(): T {
if (delegate.isFrozen) {
freeze()
}

return this
}
delegate.compareAndSet(expectedValue, newValue)
}
@@ -1,6 +1,7 @@
package io.kotest.core.test

import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

sealed interface TestResult {

Expand All @@ -9,19 +10,19 @@ sealed interface TestResult {
"Replaced with TestResult.Success. Deprecated since 5.0",
ReplaceWith("TestResult.Success(durationMillis.milliseconds)", "kotlin.time.Duration.Companion.milliseconds")
)
fun success(durationMillis: Long): Success = Success(Duration.milliseconds(durationMillis))
fun success(durationMillis: Long): Success = Success(durationMillis.milliseconds)

@Deprecated(
"Replaced with TestResult.Failure. Deprecated since 5.0",
ReplaceWith("TestResult.Failure(durationMillis.milliseconds, error)", "kotlin.time.Duration.Companion.milliseconds")
)
fun failure(error: AssertionError, durationMillis: Long): Failure = Failure(Duration.milliseconds(durationMillis), error)
fun failure(error: AssertionError, durationMillis: Long): Failure = Failure(durationMillis.milliseconds, error)

@Deprecated(
"Replaced with TestResult.Error. Deprecated since 5.0",
ReplaceWith("TestResult.Error(durationMillis.milliseconds, error)", "kotlin.time.Duration.Companion.milliseconds")
)
fun error(error: Throwable, durationMillis: Long): Error = Error(Duration.milliseconds(durationMillis), error)
fun error(error: Throwable, durationMillis: Long): Error = Error(durationMillis.milliseconds, error)

val Ignored = Ignored(null)
}
Expand Down
Expand Up @@ -5,7 +5,7 @@ import io.kotest.core.test.TestCase
import io.kotest.core.test.TestResult
import io.kotest.engine.listener.TestEngineListener
import io.kotest.mpp.timeInMillis
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

/**
* A [SpecRefInterceptor] that invokes the [specFinished] test engine listener callbacks.
Expand All @@ -22,7 +22,7 @@ internal class SpecFinishedInterceptor(private val listener: TestEngineListener)

// We deliberately use the deprecated method here to maintain backwards compatibility with Kotlin 1.5.
// See https://github.com/kotest/kotest/issues/3059.
val duration = Duration.milliseconds(timeInMillis() - start)
val duration = (timeInMillis() - start).milliseconds
return value
.onSuccess { listener.specFinished(ref.kclass, TestResult.Success(duration)) }
.onFailure { listener.specFinished(ref.kclass, TestResult.Error(duration, it)) }
Expand Down
Expand Up @@ -9,6 +9,7 @@ import io.kotest.core.test.config.ResolvedTestConfig
import io.kotest.core.test.config.UnresolvedTestConfig
import io.kotest.engine.tags.tags
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

/**
* Accepts an [UnresolvedTestConfig] and returns a [ResolvedTestConfig] by completing
Expand Down Expand Up @@ -85,4 +86,4 @@ internal fun resolveConfig(
)
}

fun Long.toMillis(): Duration = Duration.milliseconds(this)
fun Long.toMillis(): Duration = this.milliseconds
Expand Up @@ -4,6 +4,7 @@ import io.kotest.core.test.TestResult
import io.kotest.mpp.bestName
import kotlin.jvm.JvmName
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

/**
* Returns a [TestResult] derived from a throwable.
Expand All @@ -18,7 +19,7 @@ import kotlin.time.Duration
ReplaceWith("createTestResult(duration.milliseconds, error)")
)
fun createTestResult(duration: Long, error: Throwable?): TestResult =
createTestResult(Duration.milliseconds(duration), error)
createTestResult(duration.milliseconds, error)

fun createTestResult(duration: Duration, error: Throwable?): TestResult = when {
error == null -> TestResult.Success(duration)
Expand All @@ -32,7 +33,7 @@ fun createTestResult(duration: Duration, error: Throwable?): TestResult = when {
"Replaced with Throwable.toTestResult(Duration)",
ReplaceWith("createTestResult(duration.milliseconds, this)", "kotlin.time.milliseconds")
)
fun Throwable.toTestResult(duration: Long): TestResult = createTestResult(Duration.milliseconds(duration), this)
fun Throwable.toTestResult(duration: Long): TestResult = createTestResult(duration.milliseconds, this)

@JvmName("throwableToTestResult")
fun Throwable.toTestResult(duration: Duration): TestResult = createTestResult(duration, this)
Expand Down
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.withTimeoutOrNull
import kotlin.math.min
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

/**
* Installs an invocation timeout.
Expand Down Expand Up @@ -41,7 +42,7 @@ internal object InvocationTimeoutInterceptor : TestExecutionInterceptor {
// user level timeouts will throw an exception, ours will return null
withTimeoutOrNull(timeout) {
test(testCase, scope.withCoroutineContext(coroutineContext))
} ?: throw TestTimeoutException(Duration.milliseconds(timeout), testCase.name.testName)
} ?: throw TestTimeoutException(timeout.milliseconds, testCase.name.testName)
} catch (t: TimeoutCancellationException) {
logger.log { Pair(testCase.name.testName, "Caught user timeout $t") }
throw t
Expand Down
Expand Up @@ -4,19 +4,18 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.toLogger
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration

class KotestJsComponentRegistrar : ComponentRegistrar {
@OptIn(ExperimentalCompilerApi::class)
class KotestJsCompilerPluginRegistrar : CompilerPluginRegistrar() {
override val supportsK2 = true

override fun registerProjectComponents(
project: MockProject,
configuration: CompilerConfiguration
) {
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
messageCollector.toLogger().log("Installing Kotest SpecIrGenerationExtension")
IrGenerationExtension.registerExtension(project, SpecIrGenerationExtension(messageCollector))
IrGenerationExtension.registerExtension(SpecIrGenerationExtension(messageCollector))
}
}

Expand Down
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.getSimpleFunction
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name

Expand Down Expand Up @@ -74,7 +75,7 @@ class NativeTransformer(messageCollector: MessageCollector, pluginContext: IrPlu
}

private val eagerAnnotationConstructor by lazy {
val annotationName = FqName("kotlin.native.EagerInitialization")
val annotationName = ClassId.fromString("kotlin.native.EagerInitialization")

val annotation = pluginContext.referenceClass(annotationName)
?: error("Cannot find eager initialisation annotation class $annotationName")
Expand Down
Expand Up @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.getSimpleFunction
import org.jetbrains.kotlin.ir.util.kotlinFqName
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.ClassId
import java.util.concurrent.CopyOnWriteArrayList

abstract class Transformer(protected val messageCollector: MessageCollector, protected val pluginContext: IrPluginContext) : IrElementTransformerVoidWithContext() {
Expand Down Expand Up @@ -56,10 +56,10 @@ abstract class Transformer(protected val messageCollector: MessageCollector, pro
if (specs.isEmpty()) {
return fragment
}

val file = declaration.files.first()
val launcher = generateLauncher(specs, configs, file)
file.addChild(launcher)
//
// val file = declaration.files.first()
// val launcher = generateLauncher(specs, configs, file)
// file.addChild(launcher)

return fragment
}
Expand Down Expand Up @@ -96,7 +96,7 @@ abstract class Transformer(protected val messageCollector: MessageCollector, pro
}

protected val launcherClass by lazy {
pluginContext.referenceClass(FqName(EntryPoint.TestEngineClassName))
pluginContext.referenceClass(ClassId.fromString(EntryPoint.TestEngineClassName))
?: error("Cannot find ${EntryPoint.TestEngineClassName} class reference")
}

Expand Down
@@ -1 +1 @@
io.kotest.framework.multiplatform.embeddablecompiler.KotestJsComponentRegistrar
io.kotest.framework.multiplatform.embeddablecompiler.KotestJsCompilerPluginRegistrar
Expand Up @@ -83,21 +83,16 @@ tasks.withType<Test>().configureEach {
}
}


pluginBundle {
website = "https://kotest.io"
vcsUrl = "https://github.com/kotest"
tags = listOf("kotest", "kotlin", "testing", "integrationTesting", "javascript")
}


gradlePlugin {
website.set("https://kotest.io")
vcsUrl.set("https://github.com/kotest")
plugins {
create("KotestMultiplatformCompilerGradlePlugin") {
id = "io.kotest.multiplatform"
implementationClass = "io.kotest.framework.multiplatform.gradle.KotestMultiplatformCompilerGradlePlugin"
displayName = "Kotest Multiplatform Compiler Plugin"
description = "Adds support for Javascript and Native tests in Kotest"
tags.set(listOf("kotest", "kotlin", "testing", "integrationTesting", "javascript"))
}
}
}
Expand Down