diff --git a/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts b/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts index 06681c1ee2..4ca9ccd4d2 100644 --- a/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts @@ -35,6 +35,7 @@ configure(subprojects) { "kotlinx.cinterop.ExperimentalForeignApi", "kotlinx.cinterop.UnsafeNumber", "kotlin.experimental.ExperimentalNativeApi", + "kotlin.native.concurrent.ObsoleteWorkersApi", ) } addExtraCompilerFlags(project) diff --git a/kotlinx-coroutines-core/common/test/AsyncLazyTest.kt b/kotlinx-coroutines-core/common/test/AsyncLazyTest.kt index e87e46158a..79034862c0 100644 --- a/kotlinx-coroutines-core/common/test/AsyncLazyTest.kt +++ b/kotlinx-coroutines-core/common/test/AsyncLazyTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -109,7 +107,7 @@ class AsyncLazyTest : TestBase() { assertTrue(!d.isActive && !d.isCompleted) try { d.await() // will throw IOException - } catch (e: TestException) { + } catch (_: TestException) { assertTrue(!d.isActive && d.isCompleted && d.isCancelled) expect(4) } diff --git a/kotlinx-coroutines-core/common/test/AsyncTest.kt b/kotlinx-coroutines-core/common/test/AsyncTest.kt index b9c4797508..7e5932fbff 100644 --- a/kotlinx-coroutines-core/common/test/AsyncTest.kt +++ b/kotlinx-coroutines-core/common/test/AsyncTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "UNREACHABLE_CODE", "USELESS_IS_CHECK") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -82,11 +80,10 @@ class AsyncTest : TestBase() { val deferred = async(NonCancellable) { val decomposed = async(NonCancellable) { throw TestException() - 1 } try { decomposed.await() - } catch (e: TestException) { + } catch (_: TestException) { 42 } } @@ -101,11 +98,10 @@ class AsyncTest : TestBase() { val decomposed = async { // inherits parent job! expect(3) throw TestException() - 1 } try { decomposed.await() - } catch (e: TestException) { + } catch (_: TestException) { expect(4) // Should catch this exception, but parent is already cancelled 42 } @@ -113,17 +109,16 @@ class AsyncTest : TestBase() { try { // This will fail assertEquals(42, deferred.await()) - } catch (e: TestException) { + } catch (_: TestException) { finish(5) } } @Test fun testParallelDecompositionUncaughtExceptionWithInheritedParent() = runTest(expected = { it is TestException }) { - val deferred = async(NonCancellable) { + val deferred = async(NonCancellable) { val decomposed = async { throw TestException() - 1 } decomposed.await() @@ -135,10 +130,9 @@ class AsyncTest : TestBase() { @Test fun testParallelDecompositionUncaughtException() = runTest(expected = { it is TestException }) { - val deferred = async(NonCancellable) { + val deferred = async(NonCancellable) { val decomposed = async { throw TestException() - 1 } decomposed.await() @@ -158,7 +152,7 @@ class AsyncTest : TestBase() { deferred.cancel() try { deferred.await() - } catch (e: TestException) { + } catch (_: TestException) { finish(3) } } @@ -229,7 +223,7 @@ class AsyncTest : TestBase() { try { expect(1) deferred.await() - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(3) } } diff --git a/kotlinx-coroutines-core/common/test/AtomicCancellationCommonTest.kt b/kotlinx-coroutines-core/common/test/AtomicCancellationCommonTest.kt index 52d3b8e3a9..02ea045271 100644 --- a/kotlinx-coroutines-core/common/test/AtomicCancellationCommonTest.kt +++ b/kotlinx-coroutines-core/common/test/AtomicCancellationCommonTest.kt @@ -131,13 +131,14 @@ class AtomicCancellationCommonTest : TestBase() { finish(4) } + @Suppress("DEPRECATION") @Test fun testSelectLockCancellable() = runTest { expect(1) val mutex = Mutex(true) // locked mutex val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) - select { // suspends + select { // suspends mutex.onLock { expect(4) "OK" diff --git a/kotlinx-coroutines-core/common/test/CancellableContinuationHandlersTest.kt b/kotlinx-coroutines-core/common/test/CancellableContinuationHandlersTest.kt index f005c93e5e..e9e7e065ed 100644 --- a/kotlinx-coroutines-core/common/test/CancellableContinuationHandlersTest.kt +++ b/kotlinx-coroutines-core/common/test/CancellableContinuationHandlersTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -11,7 +9,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscription() = runTest({ it is IllegalStateException }) { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.invokeOnCancellation { finish(1) } c.invokeOnCancellation { expectUnreached() } } @@ -19,7 +17,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscriptionAfterCompletion() = runTest { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.resume(Unit) // First invokeOnCancellation is Ok c.invokeOnCancellation { expectUnreached() } @@ -31,7 +29,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscriptionAfterCompletionWithException() = runTest { assertFailsWith { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.resumeWithException(TestException()) // First invokeOnCancellation is Ok c.invokeOnCancellation { expectUnreached() } @@ -44,7 +42,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscriptionAfterCancellation() = runTest { try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.cancel() c.invokeOnCancellation { assertIs(it) @@ -52,7 +50,7 @@ class CancellableContinuationHandlersTest : TestBase() { } assertFailsWith { c.invokeOnCancellation { expectUnreached() } } } - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(2) } } @@ -60,7 +58,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testSecondSubscriptionAfterCancellation() = runTest { try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> // Set IOC first c.invokeOnCancellation { assertNull(it) @@ -72,7 +70,7 @@ class CancellableContinuationHandlersTest : TestBase() { // then try to install another one assertFailsWith { c.invokeOnCancellation { expectUnreached() } } } - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(3) } } @@ -83,7 +81,7 @@ class CancellableContinuationHandlersTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { // will be cancelled during dispatch assertFailsWith { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> cont = c // Set IOC first -- not called (completed) c.invokeOnCancellation { @@ -105,7 +103,7 @@ class CancellableContinuationHandlersTest : TestBase() { expect(6) // then try to install another one after we've done dispatching it assertFailsWith { - cont!!.invokeOnCancellation { expectUnreached() } + cont.invokeOnCancellation { expectUnreached() } } finish(7) } @@ -113,7 +111,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscriptionAfterCancellationWithCause() = runTest { try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.cancel(AssertionError()) c.invokeOnCancellation { require(it is AssertionError) @@ -121,7 +119,7 @@ class CancellableContinuationHandlersTest : TestBase() { } assertFailsWith { c.invokeOnCancellation { expectUnreached() } } } - } catch (e: AssertionError) { + } catch (_: AssertionError) { finish(2) } } @@ -129,7 +127,7 @@ class CancellableContinuationHandlersTest : TestBase() { @Test fun testDoubleSubscriptionMixed() = runTest { try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.invokeOnCancellation { require(it is IndexOutOfBoundsException) expect(1) @@ -137,7 +135,7 @@ class CancellableContinuationHandlersTest : TestBase() { c.cancel(IndexOutOfBoundsException()) assertFailsWith { c.invokeOnCancellation { expectUnreached() } } } - } catch (e: IndexOutOfBoundsException) { + } catch (_: IndexOutOfBoundsException) { finish(2) } } @@ -148,11 +146,11 @@ class CancellableContinuationHandlersTest : TestBase() { ) { expect(1) try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> c.invokeOnCancellation { throw AssertionError() } c.cancel() } - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(2) } finish(3) @@ -171,13 +169,13 @@ class CancellableContinuationHandlersTest : TestBase() { val s = MySegment() expect(1) try { - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> expect(2) c as CancellableContinuationImpl<*> c.invokeOnCancellation(s, 0) c.cancel() } - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) } expect(4) diff --git a/kotlinx-coroutines-core/common/test/CancellableContinuationTest.kt b/kotlinx-coroutines-core/common/test/CancellableContinuationTest.kt index 43ad996b70..a47a889431 100644 --- a/kotlinx-coroutines-core/common/test/CancellableContinuationTest.kt +++ b/kotlinx-coroutines-core/common/test/CancellableContinuationTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -13,10 +11,10 @@ class CancellableContinuationTest : TestBase() { val job = launch { try { expect(2) - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> continuation = c } - } catch (e: TestException) { + } catch (_: TestException) { expect(3) } } @@ -24,7 +22,7 @@ class CancellableContinuationTest : TestBase() { yield() continuation!!.resumeWithException(TestException()) yield() - assertFailsWith { continuation!!.resumeWithException(TestException()) } + assertFailsWith { continuation.resumeWithException(TestException()) } job.join() finish(4) } @@ -34,7 +32,7 @@ class CancellableContinuationTest : TestBase() { var continuation: Continuation? = null val job = launch { expect(2) - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> continuation = c } expect(3) @@ -43,7 +41,7 @@ class CancellableContinuationTest : TestBase() { yield() continuation!!.resume(Unit) job.join() - assertFailsWith { continuation!!.resumeWithException(TestException()) } + assertFailsWith { continuation.resumeWithException(TestException()) } finish(4) } @@ -52,7 +50,7 @@ class CancellableContinuationTest : TestBase() { var continuation: Continuation? = null val job = launch { expect(2) - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> continuation = c } expect(3) @@ -61,12 +59,12 @@ class CancellableContinuationTest : TestBase() { yield() continuation!!.resume(Unit) job.join() - assertFailsWith { continuation!!.resume(Unit) } + assertFailsWith { continuation.resume(Unit) } finish(4) } /** - * Cancelling outer job may, in practise, race with attempt to resume continuation and resumes + * Cancelling the outer job may, in practice, race with an attempt to resume continuation and resumes * should be ignored. Here suspended coroutine is cancelled but then resumed with exception. */ @Test @@ -75,10 +73,10 @@ class CancellableContinuationTest : TestBase() { val job = launch { try { expect(2) - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> continuation = c } - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) } } @@ -100,10 +98,10 @@ class CancellableContinuationTest : TestBase() { val job = launch { try { expect(2) - suspendCancellableCoroutine { c -> + suspendCancellableCoroutine { c -> continuation = c } - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) } } diff --git a/kotlinx-coroutines-core/common/test/CancellableResumeOldTest.kt b/kotlinx-coroutines-core/common/test/CancellableResumeOldTest.kt index 501d033111..ab285fb695 100644 --- a/kotlinx-coroutines-core/common/test/CancellableResumeOldTest.kt +++ b/kotlinx-coroutines-core/common/test/CancellableResumeOldTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -13,7 +11,7 @@ class CancellableResumeOldTest : TestBase() { @Test fun testResumeImmediateNormally() = runTest { expect(1) - val ok = suspendCancellableCoroutine { cont -> + val ok = suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expectUnreached() } cont.resume("OK") { expectUnreached() } @@ -28,7 +26,7 @@ class CancellableResumeOldTest : TestBase() { expected = { it is TestException } ) { expect(1) - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) } cont.cancel(TestException("FAIL")) @@ -51,7 +49,7 @@ class CancellableResumeOldTest : TestBase() { ) ) { expect(1) - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) @@ -75,7 +73,7 @@ class CancellableResumeOldTest : TestBase() { ) { expect(1) val ctx = coroutineContext - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) } ctx.cancel() @@ -98,7 +96,7 @@ class CancellableResumeOldTest : TestBase() { ) { expect(1) val ctx = coroutineContext - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) @@ -121,7 +119,7 @@ class CancellableResumeOldTest : TestBase() { lateinit var cc: CancellableContinuation launch(start = CoroutineStart.UNDISPATCHED) { expect(2) - val ok = suspendCancellableCoroutine { cont -> + val ok = suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expectUnreached() } cc = cont @@ -141,13 +139,13 @@ class CancellableResumeOldTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expect(5) } cc = cont } expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(9) } } @@ -173,7 +171,7 @@ class CancellableResumeOldTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expect(5) @@ -182,7 +180,7 @@ class CancellableResumeOldTest : TestBase() { cc = cont } expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(9) } } @@ -204,7 +202,7 @@ class CancellableResumeOldTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) // resumed first, dispatched, then cancelled, but still got invokeOnCancellation call cont.invokeOnCancellation { cause -> @@ -215,7 +213,7 @@ class CancellableResumeOldTest : TestBase() { cc = cont } expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(9) } } @@ -244,7 +242,7 @@ class CancellableResumeOldTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) // resumed first, dispatched, then cancelled, but still got invokeOnCancellation call cont.invokeOnCancellation { cause -> @@ -256,7 +254,7 @@ class CancellableResumeOldTest : TestBase() { cc = cont } expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(9) } } @@ -278,7 +276,7 @@ class CancellableResumeOldTest : TestBase() { fun testResumeUnconfined() = runTest { val outerScope = this withContext(Dispatchers.Unconfined) { - val result = suspendCancellableCoroutine { + val result = suspendCancellableCoroutine { outerScope.launch { it.resume("OK") { expectUnreached() diff --git a/kotlinx-coroutines-core/common/test/CancellableResumeTest.kt b/kotlinx-coroutines-core/common/test/CancellableResumeTest.kt index c048a8dddf..54ba60886c 100644 --- a/kotlinx-coroutines-core/common/test/CancellableResumeTest.kt +++ b/kotlinx-coroutines-core/common/test/CancellableResumeTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -12,7 +10,7 @@ class CancellableResumeTest : TestBase() { @Test fun testResumeImmediateNormally() = runTest { expect(1) - val ok = suspendCancellableCoroutine { cont -> + val ok = suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expectUnreached() } cont.resume("OK") { _, _, _ -> expectUnreached() } @@ -27,7 +25,7 @@ class CancellableResumeTest : TestBase() { expected = { it is TestException } ) { expect(1) - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) } cont.cancel(TestException("FAIL")) @@ -53,7 +51,7 @@ class CancellableResumeTest : TestBase() { ) ) { expect(1) - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) @@ -80,7 +78,7 @@ class CancellableResumeTest : TestBase() { ) { expect(1) val ctx = coroutineContext - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) } ctx.cancel() @@ -107,7 +105,7 @@ class CancellableResumeTest : TestBase() { ) { expect(1) val ctx = coroutineContext - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(2) cont.invokeOnCancellation { expect(3) @@ -134,7 +132,7 @@ class CancellableResumeTest : TestBase() { lateinit var cc: CancellableContinuation launch(start = CoroutineStart.UNDISPATCHED) { expect(2) - val ok = suspendCancellableCoroutine { cont -> + val ok = suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expectUnreached() } cc = cont @@ -154,7 +152,7 @@ class CancellableResumeTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expect(5) } cc = cont @@ -189,7 +187,7 @@ class CancellableResumeTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) cont.invokeOnCancellation { expect(5) @@ -223,7 +221,7 @@ class CancellableResumeTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) // resumed first, dispatched, then cancelled, but still got invokeOnCancellation call cont.invokeOnCancellation { cause -> @@ -266,7 +264,7 @@ class CancellableResumeTest : TestBase() { val job = launch(start = CoroutineStart.UNDISPATCHED) { expect(2) try { - suspendCancellableCoroutine { cont -> + suspendCancellableCoroutine { cont -> expect(3) // resumed first, dispatched, then cancelled, but still got invokeOnCancellation call cont.invokeOnCancellation { cause -> @@ -303,7 +301,7 @@ class CancellableResumeTest : TestBase() { fun testResumeUnconfined() = runTest { val outerScope = this withContext(Dispatchers.Unconfined) { - val result = suspendCancellableCoroutine { + val result = suspendCancellableCoroutine { outerScope.launch { it.resume("OK") { _, _, _ -> expectUnreached() diff --git a/kotlinx-coroutines-core/common/test/CompletableDeferredTest.kt b/kotlinx-coroutines-core/common/test/CompletableDeferredTest.kt index b2a39218eb..9379b239f8 100644 --- a/kotlinx-coroutines-core/common/test/CompletableDeferredTest.kt +++ b/kotlinx-coroutines-core/common/test/CompletableDeferredTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -180,7 +178,7 @@ class CompletableDeferredTest : TestBase() { expect(4) try { parent.await() - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(6) } } diff --git a/kotlinx-coroutines-core/common/test/CoroutinesTest.kt b/kotlinx-coroutines-core/common/test/CoroutinesTest.kt index 8cd149ef23..de1dc9baf4 100644 --- a/kotlinx-coroutines-core/common/test/CoroutinesTest.kt +++ b/kotlinx-coroutines-core/common/test/CoroutinesTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/DelayDurationTest.kt b/kotlinx-coroutines-core/common/test/DelayDurationTest.kt index dad01eb285..1b56616b94 100644 --- a/kotlinx-coroutines-core/common/test/DelayDurationTest.kt +++ b/kotlinx-coroutines-core/common/test/DelayDurationTest.kt @@ -1,7 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") - -// KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/DelayTest.kt b/kotlinx-coroutines-core/common/test/DelayTest.kt index 007a272f4f..e101ef0cf8 100644 --- a/kotlinx-coroutines-core/common/test/DelayTest.kt +++ b/kotlinx-coroutines-core/common/test/DelayTest.kt @@ -1,6 +1,3 @@ - -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/FailedJobTest.kt b/kotlinx-coroutines-core/common/test/FailedJobTest.kt index 77656ee6ae..504434f152 100644 --- a/kotlinx-coroutines-core/common/test/FailedJobTest.kt +++ b/kotlinx-coroutines-core/common/test/FailedJobTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/JobStatesTest.kt b/kotlinx-coroutines-core/common/test/JobStatesTest.kt index 6f18afd326..ae97f5b1c2 100644 --- a/kotlinx-coroutines-core/common/test/JobStatesTest.kt +++ b/kotlinx-coroutines-core/common/test/JobStatesTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -11,7 +9,7 @@ import kotlin.test.* */ class JobStatesTest : TestBase() { @Test - public fun testNormalCompletion() = runTest { + fun testNormalCompletion() = runTest { expect(1) val parent = coroutineContext.job val job = launch(start = CoroutineStart.LAZY) { @@ -50,7 +48,7 @@ class JobStatesTest : TestBase() { } @Test - public fun testCompletingFailed() = runTest( + fun testCompletingFailed() = runTest( unhandled = listOf({ it -> it is TestException }) ) { expect(1) @@ -87,7 +85,7 @@ class JobStatesTest : TestBase() { } @Test - public fun testFailed() = runTest( + fun testFailed() = runTest( unhandled = listOf({ it -> it is TestException }) ) { expect(1) @@ -124,7 +122,7 @@ class JobStatesTest : TestBase() { } @Test - public fun testCancelling() = runTest { + fun testCancelling() = runTest { expect(1) val job = launch(NonCancellable, start = CoroutineStart.LAZY) { expect(2) diff --git a/kotlinx-coroutines-core/common/test/ParentCancellationTest.kt b/kotlinx-coroutines-core/common/test/ParentCancellationTest.kt index 30a53209d7..6442a3afc5 100644 --- a/kotlinx-coroutines-core/common/test/ParentCancellationTest.kt +++ b/kotlinx-coroutines-core/common/test/ParentCancellationTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/WithContextTest.kt b/kotlinx-coroutines-core/common/test/WithContextTest.kt index 9e9fd35fd5..85e0437f99 100644 --- a/kotlinx-coroutines-core/common/test/WithContextTest.kt +++ b/kotlinx-coroutines-core/common/test/WithContextTest.kt @@ -1,6 +1,3 @@ - -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-22237 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -16,7 +13,7 @@ class WithContextTest : TestBase() { expect(2) throw AssertionError() } - } catch (e: AssertionError) { + } catch (_: AssertionError) { expect(3) } @@ -32,7 +29,7 @@ class WithContextTest : TestBase() { expect(2) throw AssertionError() } - } catch (e: AssertionError) { + } catch (_: AssertionError) { expect(3) } @@ -89,14 +86,14 @@ class WithContextTest : TestBase() { try { yield() // shall throw CancellationException expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(4) } "OK".wrap() } expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(5) // will wait for the first coroutine } @@ -120,7 +117,7 @@ class WithContextTest : TestBase() { try { yield() // shall throw CancellationException expectUnreached() - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(6) } "OK".wrap() @@ -155,7 +152,7 @@ class WithContextTest : TestBase() { job!!.cancel() // cancel this job _before_ it throws throw TestException() } - } catch (e: TestException) { + } catch (_: TestException) { // must have caught TextException expect(6) } @@ -180,7 +177,7 @@ class WithContextTest : TestBase() { job!!.cancel() // cancel this job _before_ it throws throw TestException() } - } catch (e: TestException) { + } catch (_: TestException) { // must have caught TextException expect(8) } @@ -269,7 +266,7 @@ class WithContextTest : TestBase() { "OK".wrap() } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { // ensure that we can catch exception outside of the scope expect(5) } @@ -329,7 +326,7 @@ class WithContextTest : TestBase() { withContext(job) { expectUnreached() } - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(2) } finish(3) diff --git a/kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt b/kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt index 855b00f2c7..2f5c4fcc1d 100644 --- a/kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt +++ b/kotlinx-coroutines-core/common/test/WithTimeoutDurationTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "UNREACHABLE_CODE") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -137,7 +135,7 @@ class WithTimeoutDurationTest : TestBase() { expect(2) try { delay(1000.milliseconds) - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(3) } "OK" @@ -153,7 +151,7 @@ class WithTimeoutDurationTest : TestBase() { expect(2) try { delay(1000.milliseconds) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) throw TestException() } @@ -161,7 +159,7 @@ class WithTimeoutDurationTest : TestBase() { "OK" } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { finish(4) } } @@ -170,7 +168,7 @@ class WithTimeoutDurationTest : TestBase() { fun testNegativeTimeout() = runTest { expect(1) try { - withTimeout(-1.milliseconds) { + withTimeout((-1).milliseconds) { expectUnreached() "OK" } @@ -183,6 +181,7 @@ class WithTimeoutDurationTest : TestBase() { @Test fun testExceptionFromWithinTimeout() = runTest { expect(1) + @Suppress("UNREACHABLE_CODE") try { expect(2) withTimeout(1.seconds) { @@ -190,7 +189,7 @@ class WithTimeoutDurationTest : TestBase() { throw TestException() } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { finish(4) } } diff --git a/kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt b/kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt index f92a4c2654..d9a13ab721 100644 --- a/kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt +++ b/kotlinx-coroutines-core/common/test/WithTimeoutOrNullDurationTest.kt @@ -1,6 +1,3 @@ - -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -180,7 +177,7 @@ class WithTimeoutOrNullDurationTest : TestBase() { expect(2) try { delay(1000.milliseconds) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) } "OK" @@ -197,7 +194,7 @@ class WithTimeoutOrNullDurationTest : TestBase() { expect(2) try { delay(1000.milliseconds) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) throw TestException() } @@ -205,7 +202,7 @@ class WithTimeoutOrNullDurationTest : TestBase() { "OK" } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { // catches TestException finish(4) @@ -215,7 +212,7 @@ class WithTimeoutOrNullDurationTest : TestBase() { @Test fun testNegativeTimeout() = runTest { expect(1) - var result = withTimeoutOrNull(-1.milliseconds) { + var result = withTimeoutOrNull((-1).milliseconds) { expectUnreached() } assertNull(result) @@ -236,7 +233,7 @@ class WithTimeoutOrNullDurationTest : TestBase() { throw TestException() } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { finish(4) } } diff --git a/kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt b/kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt index 51a6a38daf..6725db827a 100644 --- a/kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt +++ b/kotlinx-coroutines-core/common/test/WithTimeoutOrNullTest.kt @@ -1,6 +1,3 @@ - -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -171,7 +168,7 @@ class WithTimeoutOrNullTest : TestBase() { expect(2) try { delay(1000) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) } "OK" @@ -188,7 +185,7 @@ class WithTimeoutOrNullTest : TestBase() { expect(2) try { delay(1000) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) throw TestException() } @@ -196,7 +193,7 @@ class WithTimeoutOrNullTest : TestBase() { "OK" } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { // catches TestException finish(4) @@ -227,7 +224,7 @@ class WithTimeoutOrNullTest : TestBase() { throw TestException() } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { finish(4) } } diff --git a/kotlinx-coroutines-core/common/test/WithTimeoutTest.kt b/kotlinx-coroutines-core/common/test/WithTimeoutTest.kt index 5f2690c198..4cd21b8632 100644 --- a/kotlinx-coroutines-core/common/test/WithTimeoutTest.kt +++ b/kotlinx-coroutines-core/common/test/WithTimeoutTest.kt @@ -1,6 +1,3 @@ - -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "UNREACHABLE_CODE") // KT-21913 - package kotlinx.coroutines import kotlinx.coroutines.testing.* @@ -129,7 +126,7 @@ class WithTimeoutTest : TestBase() { expect(2) try { delay(1000) - } catch (e: CancellationException) { + } catch (_: CancellationException) { finish(3) } "OK" @@ -145,7 +142,7 @@ class WithTimeoutTest : TestBase() { expect(2) try { delay(1000) - } catch (e: CancellationException) { + } catch (_: CancellationException) { expect(3) throw TestException() } @@ -153,7 +150,7 @@ class WithTimeoutTest : TestBase() { "OK" } expectUnreached() - } catch (e: TestException) { + } catch (_: TestException) { finish(4) } } @@ -175,6 +172,7 @@ class WithTimeoutTest : TestBase() { @Test fun testExceptionFromWithinTimeout() = runTest { expect(1) + @Suppress("UNREACHABLE_CODE") try { expect(2) withTimeout(1000) { diff --git a/kotlinx-coroutines-core/common/test/flow/IdFlowTest.kt b/kotlinx-coroutines-core/common/test/flow/IdFlowTest.kt index be3be66780..593231620c 100644 --- a/kotlinx-coroutines-core/common/test/flow/IdFlowTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/IdFlowTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines.flow import kotlinx.coroutines.testing.* @@ -47,7 +45,7 @@ class IdFlowTest : TestBase() { } /** - * This flow should be "identity" function with respect to cancellation. + * This flow should be the "identity" function with respect to cancellation. */ private fun Flow.idScoped(): Flow = flow { coroutineScope { diff --git a/kotlinx-coroutines-core/common/test/flow/NamedDispatchers.kt b/kotlinx-coroutines-core/common/test/flow/NamedDispatchers.kt index 754b3087ba..5c74646188 100644 --- a/kotlinx-coroutines-core/common/test/flow/NamedDispatchers.kt +++ b/kotlinx-coroutines-core/common/test/flow/NamedDispatchers.kt @@ -5,15 +5,15 @@ import kotlin.coroutines.* /** * Test dispatchers that emulate multiplatform context tracking. */ -public object NamedDispatchers { +object NamedDispatchers { private val stack = ArrayStack() - public fun name(): String = stack.peek() ?: error("No names on stack") + fun name(): String = stack.peek() ?: error("No names on stack") - public fun nameOr(defaultValue: String): String = stack.peek() ?: defaultValue + fun nameOr(defaultValue: String): String = stack.peek() ?: defaultValue - public operator fun invoke(name: String) = named(name) + operator fun invoke(name: String) = named(name) private fun named(name: String): CoroutineDispatcher = object : CoroutineDispatcher() { override fun dispatch(context: CoroutineContext, block: Runnable) { @@ -32,14 +32,14 @@ private class ArrayStack { private var elements = arrayOfNulls(16) private var head = 0 - public fun push(value: String) { + fun push(value: String) { if (elements.size == head - 1) ensureCapacity() elements[head++] = value } - public fun peek(): String? = elements.getOrNull(head - 1) + fun peek(): String? = elements.getOrNull(head - 1) - public fun pop(): String? { + fun pop(): String? { if (head == 0) return null return elements[--head] } diff --git a/kotlinx-coroutines-core/common/test/flow/VirtualTime.kt b/kotlinx-coroutines-core/common/test/flow/VirtualTime.kt index 771768e008..7a7a7b25c3 100644 --- a/kotlinx-coroutines-core/common/test/flow/VirtualTime.kt +++ b/kotlinx-coroutines-core/common/test/flow/VirtualTime.kt @@ -89,7 +89,7 @@ internal class VirtualTimeDispatcher(enclosingScope: CoroutineScope) : Coroutine * return from [withVirtualTime] before the test is executed completely. * To decrease the probability of such error, additional `finish` constraint is added. */ -public fun TestBase.withVirtualTime(block: suspend CoroutineScope.() -> Unit) = runTest { +fun TestBase.withVirtualTime(block: suspend CoroutineScope.() -> Unit) = runTest { withContext(Dispatchers.Unconfined) { // Create a platform-independent event loop val dispatcher = VirtualTimeDispatcher(this) diff --git a/kotlinx-coroutines-core/common/test/flow/channels/FlowCallbackTest.kt b/kotlinx-coroutines-core/common/test/flow/channels/FlowCallbackTest.kt index 2b553a5e64..034dfe7f0c 100644 --- a/kotlinx-coroutines-core/common/test/flow/channels/FlowCallbackTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/channels/FlowCallbackTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines.flow import kotlinx.coroutines.testing.* diff --git a/kotlinx-coroutines-core/common/test/flow/operators/FlowOnTest.kt b/kotlinx-coroutines-core/common/test/flow/operators/FlowOnTest.kt index bb0fabb867..01bea0d957 100644 --- a/kotlinx-coroutines-core/common/test/flow/operators/FlowOnTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/operators/FlowOnTest.kt @@ -55,7 +55,7 @@ class FlowOnTest : TestBase() { } @Test - public fun testFlowOnThrowingSource() = runTest { + fun testFlowOnThrowingSource() = runTest { val flow = flow { expect(1) emit(NamedDispatchers.name()) @@ -73,7 +73,7 @@ class FlowOnTest : TestBase() { } @Test - public fun testFlowOnThrowingOperator() = runTest { + fun testFlowOnThrowingOperator() = runTest { val flow = flow { expect(1) emit(NamedDispatchers.name()) @@ -90,7 +90,7 @@ class FlowOnTest : TestBase() { } @Test - public fun testFlowOnDownstreamOperator() = runTest() { + fun testFlowOnDownstreamOperator() = runTest() { val flow = flow { expect(2) emit(NamedDispatchers.name()) @@ -112,7 +112,7 @@ class FlowOnTest : TestBase() { } @Test - public fun testFlowOnThrowingConsumer() = runTest { + fun testFlowOnThrowingConsumer() = runTest { val flow = flow { expect(2) emit(NamedDispatchers.name()) @@ -323,7 +323,7 @@ class FlowOnTest : TestBase() { } private inner class Source(private val value: Int) { - public var contextName: String = "unknown" + var contextName: String = "unknown" fun produce(): Int { contextName = NamedDispatchers.nameOr("main") @@ -332,7 +332,7 @@ class FlowOnTest : TestBase() { } private inner class Consumer(private val expected: Int) { - public var contextName: String = "unknown" + var contextName: String = "unknown" fun consume(value: Int) { contextName = NamedDispatchers.nameOr("main") diff --git a/kotlinx-coroutines-core/common/test/flow/operators/SampleTest.kt b/kotlinx-coroutines-core/common/test/flow/operators/SampleTest.kt index 70c9d245b1..31552bda8a 100644 --- a/kotlinx-coroutines-core/common/test/flow/operators/SampleTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/operators/SampleTest.kt @@ -9,7 +9,7 @@ import kotlin.time.Duration.Companion.milliseconds class SampleTest : TestBase() { @Test - public fun testBasic() = withVirtualTime { + fun testBasic() = withVirtualTime { expect(1) val flow = flow { expect(3) diff --git a/kotlinx-coroutines-core/common/test/flow/sharing/ShareInTest.kt b/kotlinx-coroutines-core/common/test/flow/sharing/ShareInTest.kt index 1df59b91fe..e23a4ae263 100644 --- a/kotlinx-coroutines-core/common/test/flow/sharing/ShareInTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/sharing/ShareInTest.kt @@ -217,7 +217,8 @@ class ShareInTest : TestBase() { }.shareIn(this, SharingStarted.Lazily) expect(1) - flow.onSubscription { throw CancellationException("") } + // Casting so that the non-deprecated `catch` overload is chosen + (flow.onSubscription { throw CancellationException("") } as Flow) .catch { e -> assertTrue { e is CancellationException } } .collect() yield() diff --git a/kotlinx-coroutines-core/common/test/flow/sharing/SharedFlowTest.kt b/kotlinx-coroutines-core/common/test/flow/sharing/SharedFlowTest.kt index eab4b79ab5..1f7c22d9c0 100644 --- a/kotlinx-coroutines-core/common/test/flow/sharing/SharedFlowTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/sharing/SharedFlowTest.kt @@ -558,7 +558,7 @@ class SharedFlowTest : TestBase() { } @Test - public fun testOnSubscription() = runTest { + fun testOnSubscription() = runTest { expect(1) val sh = MutableSharedFlow() fun share(s: String) { launch(start = CoroutineStart.UNDISPATCHED) { sh.emit(s) } } @@ -762,10 +762,10 @@ class SharedFlowTest : TestBase() { } @Test - public fun testReplayCancellability() = testCancellability(fromReplay = true) + fun testReplayCancellability() = testCancellability(fromReplay = true) @Test - public fun testEmitCancellability() = testCancellability(fromReplay = false) + fun testEmitCancellability() = testCancellability(fromReplay = false) private fun testCancellability(fromReplay: Boolean) = runTest { expect(1) diff --git a/kotlinx-coroutines-core/common/test/flow/sharing/StateFlowTest.kt b/kotlinx-coroutines-core/common/test/flow/sharing/StateFlowTest.kt index 4516faac21..4aaef682ba 100644 --- a/kotlinx-coroutines-core/common/test/flow/sharing/StateFlowTest.kt +++ b/kotlinx-coroutines-core/common/test/flow/sharing/StateFlowTest.kt @@ -172,7 +172,7 @@ class StateFlowTest : TestBase() { } @Test - public fun testOnSubscriptionWithException() = runTest { + fun testOnSubscriptionWithException() = runTest { expect(1) val state = MutableStateFlow("A") state diff --git a/kotlinx-coroutines-core/common/test/selects/SelectDeferredTest.kt b/kotlinx-coroutines-core/common/test/selects/SelectDeferredTest.kt index 5b977d992b..f0f3469544 100644 --- a/kotlinx-coroutines-core/common/test/selects/SelectDeferredTest.kt +++ b/kotlinx-coroutines-core/common/test/selects/SelectDeferredTest.kt @@ -1,11 +1,8 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines.selects -import kotlinx.coroutines.testing.* import kotlinx.coroutines.* +import kotlinx.coroutines.testing.* import kotlin.test.* -import kotlin.time.Duration.Companion.seconds class SelectDeferredTest : TestBase() { @Test @@ -16,7 +13,7 @@ class SelectDeferredTest : TestBase() { 42 } expect(2) - val res = select { + val res = select { d1.onAwait { v -> expect(4) assertEquals(42, v) @@ -41,7 +38,7 @@ class SelectDeferredTest : TestBase() { expect(6) } expect(2) - val res = select { + val res = select { d1.onAwait { v -> expect(5) assertEquals(42, v) @@ -63,7 +60,7 @@ class SelectDeferredTest : TestBase() { } launch { expect(3) - val res = select { + val res = select { d1.onAwait { v -> expect(7) assertEquals(42, v) @@ -98,7 +95,7 @@ class SelectDeferredTest : TestBase() { "d2" // returns result } expect(2) - val res = select { + val res = select { d1.onAwait { expectUnreached() "FAIL" @@ -143,7 +140,7 @@ class SelectDeferredTest : TestBase() { d.cancel() // will cancel after select starts } expect(2) - select { + select { d.onAwait { expectUnreached() // will not select } @@ -154,7 +151,7 @@ class SelectDeferredTest : TestBase() { @Test fun testSelectIncomplete() = runTest { val deferred = async { Wrapper("OK") } - val result = select { + val result = select { assertFalse(deferred.isCompleted) assertTrue(deferred.isActive) deferred.onAwait { @@ -168,7 +165,7 @@ class SelectDeferredTest : TestBase() { @Test fun testSelectIncompleteFastPath() = runTest { val deferred = async(Dispatchers.Unconfined) { Wrapper("OK") } - val result = select { + val result = select { assertTrue(deferred.isCompleted) assertFalse(deferred.isActive) deferred.onAwait { diff --git a/kotlinx-coroutines-core/common/test/selects/SelectLoopTest.kt b/kotlinx-coroutines-core/common/test/selects/SelectLoopTest.kt index dd83d4afd8..7ccc471d94 100644 --- a/kotlinx-coroutines-core/common/test/selects/SelectLoopTest.kt +++ b/kotlinx-coroutines-core/common/test/selects/SelectLoopTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines.selects import kotlinx.coroutines.testing.* @@ -23,7 +21,7 @@ class SelectLoopTest : TestBase() { } try { while (true) { - select { + select { channel.onReceiveCatching { expectUnreached() } @@ -32,8 +30,8 @@ class SelectLoopTest : TestBase() { } } } - } catch (e: CancellationException) { - // select will get cancelled because of the failure of job + } catch (_: CancellationException) { + // select will get cancelled because of the failure of the job finish(4) } } diff --git a/kotlinx-coroutines-core/common/test/selects/SelectMutexTest.kt b/kotlinx-coroutines-core/common/test/selects/SelectMutexTest.kt index db3361f3be..be8cd3fca4 100644 --- a/kotlinx-coroutines-core/common/test/selects/SelectMutexTest.kt +++ b/kotlinx-coroutines-core/common/test/selects/SelectMutexTest.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.sync.* import kotlin.test.* +@Suppress("DEPRECATION") class SelectMutexTest : TestBase() { @Test fun testSelectLock() = runTest { @@ -13,7 +14,7 @@ class SelectMutexTest : TestBase() { launch { // ensure that it is not scheduled earlier than needed finish(4) // after main exits } - val res = select { + val res = select { mutex.onLock { assertTrue(mutex.isLocked) expect(2) @@ -31,8 +32,8 @@ class SelectMutexTest : TestBase() { expect(1) launch { expect(3) - val res = select { - // will suspended + val res = select { + // will suspend mutex.onLock { assertTrue(mutex.isLocked) expect(6) @@ -47,7 +48,7 @@ class SelectMutexTest : TestBase() { expect(4) mutex.unlock() expect(5) - yield() // to resumed select + yield() // to the resumed select finish(8) } } \ No newline at end of file diff --git a/kotlinx-coroutines-core/common/test/selects/SelectRendezvousChannelTest.kt b/kotlinx-coroutines-core/common/test/selects/SelectRendezvousChannelTest.kt index ad9ec556a8..065316c015 100644 --- a/kotlinx-coroutines-core/common/test/selects/SelectRendezvousChannelTest.kt +++ b/kotlinx-coroutines-core/common/test/selects/SelectRendezvousChannelTest.kt @@ -1,5 +1,3 @@ -@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913 - package kotlinx.coroutines.selects import kotlinx.coroutines.testing.* @@ -20,7 +18,7 @@ class SelectRendezvousChannelTest : TestBase() { } yield() // to launched coroutine expect(3) - select { + select { channel.onSend("OK") { expect(4) } @@ -39,7 +37,7 @@ class SelectRendezvousChannelTest : TestBase() { } yield() // to launched coroutine expect(3) - select { + select { channel.onSend("OK") { expect(4) } @@ -54,7 +52,7 @@ class SelectRendezvousChannelTest : TestBase() { fun testSelectSendWaitWithDefault() = runTest { expect(1) val channel = Channel(Channel.RENDEZVOUS) - select { + select { channel.onSend("OK") { expectUnreached() } @@ -86,7 +84,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(4) } expect(2) - select { + select { channel.onSend("OK") { expect(5) } @@ -105,7 +103,7 @@ class SelectRendezvousChannelTest : TestBase() { } yield() // to launched coroutine expect(3) - select { + select { channel.onReceive { v -> expect(4) assertEquals("OK", v) @@ -125,7 +123,7 @@ class SelectRendezvousChannelTest : TestBase() { } yield() // to launched coroutine expect(3) - select { + select { channel.onReceive { v -> expect(4) assertEquals("OK", v) @@ -141,7 +139,7 @@ class SelectRendezvousChannelTest : TestBase() { fun testSelectReceiveWaitWithDefault() = runTest { expect(1) val channel = Channel(Channel.RENDEZVOUS) - select { + select { channel.onReceive { expectUnreached() } @@ -173,7 +171,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(4) } expect(2) - select { + select { channel.onReceive { v -> expect(5) assertEquals("OK", v) @@ -188,7 +186,7 @@ class SelectRendezvousChannelTest : TestBase() { val channel = Channel(Channel.RENDEZVOUS) channel.close() finish(2) - select { + select { channel.onReceive { expectUnreached() } @@ -206,7 +204,7 @@ class SelectRendezvousChannelTest : TestBase() { finish(4) } expect(2) - select { + select { channel.onReceive { expectUnreached() } @@ -249,7 +247,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(1) launch { expect(3) - val res = select { + val res = select { c1.onReceive { v1 -> expect(4) assertEquals(42, v1) @@ -279,7 +277,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(1) launch { expect(3) - val res = select { + val res = select { c.onReceive { v -> expect(6) assertEquals(42, v) @@ -312,7 +310,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(4) } expect(2) - select { + select { channel.onReceiveCatching { expect(5) assertTrue(it.isClosed) @@ -349,7 +347,7 @@ class SelectRendezvousChannelTest : TestBase() { val channel = Channel() channel.close() expect(1) - select { + select { expect(2) channel.onReceiveCatching { assertTrue(it.isClosed) @@ -366,7 +364,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(1) val job = launch { repeat(iterations) { - select { + select { channel.onReceiveCatching { v -> expect(4 + it * 2) assertEquals(it, v.getOrThrow()) @@ -392,7 +390,7 @@ class SelectRendezvousChannelTest : TestBase() { expect(1) launch { expect(3) - val res = select { + val res = select { c.onReceiveCatching { v -> expect(6) assertEquals(42, v.getOrThrow()) @@ -444,7 +442,7 @@ class SelectRendezvousChannelTest : TestBase() { fun testSelectSendAndReceive() = runTest { val c = Channel() assertFailsWith { - select { + select { c.onSend(1) { expectUnreached() } c.onReceive { expectUnreached() } } @@ -456,7 +454,7 @@ class SelectRendezvousChannelTest : TestBase() { fun testSelectReceiveAndSend() = runTest { val c = Channel() assertFailsWith { - select { + select { c.onReceive { expectUnreached() } c.onSend(1) { expectUnreached() } } diff --git a/kotlinx-coroutines-core/common/test/sync/MutexTest.kt b/kotlinx-coroutines-core/common/test/sync/MutexTest.kt index c2d555f32b..049d380fdf 100644 --- a/kotlinx-coroutines-core/common/test/sync/MutexTest.kt +++ b/kotlinx-coroutines-core/common/test/sync/MutexTest.kt @@ -66,7 +66,7 @@ class MutexTest : TestBase() { assertTrue(mutex.isLocked) throw TestException() } - } catch (e: TestException) { + } catch (_: TestException) { expect(2) } assertFalse(mutex.isLocked) @@ -174,6 +174,7 @@ class MutexTest : TestBase() { assertTrue(mutex.tryLock(owner)) assertFailsWith { mutex.tryLock(owner) } assertFailsWith { mutex.lock(owner) } + @Suppress("DEPRECATION") assertFailsWith { select { mutex.onLock(owner) {} } } } diff --git a/kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt b/kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt index b7648eb600..4cf229b232 100644 --- a/kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt +++ b/kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt @@ -7,7 +7,7 @@ import kotlin.test.* abstract class AbstractDispatcherConcurrencyTest : TestBase() { - public abstract val dispatcher: CoroutineDispatcher + abstract val dispatcher: CoroutineDispatcher @Test fun testLaunchAndJoin() = runTest { diff --git a/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt b/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt index 67ff03b91e..e18a1f19bf 100644 --- a/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt +++ b/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt @@ -82,6 +82,7 @@ class MutexStressTest : TestBase() { } } + @Suppress("DEPRECATION") @Test fun stressUnlockCancelRaceWithSelect() = runTest { val n = 10_000 * stressTestMultiplier @@ -93,7 +94,7 @@ class MutexStressTest : TestBase() { assertTrue(mutex.isLocked) var job1EnteredCriticalSection = false val job1 = launch(start = CoroutineStart.UNDISPATCHED) { - select { + select { mutex.onLock { job1EnteredCriticalSection = true mutex.unlock() diff --git a/kotlinx-coroutines-core/jvm/test/AwaitJvmTest.kt b/kotlinx-coroutines-core/jvm/test/AwaitJvmTest.kt index e43611e808..149d026bf6 100644 --- a/kotlinx-coroutines-core/jvm/test/AwaitJvmTest.kt +++ b/kotlinx-coroutines-core/jvm/test/AwaitJvmTest.kt @@ -5,7 +5,7 @@ import org.junit.* class AwaitJvmTest : TestBase() { @Test - public fun testSecondLeak() = runTest { + fun testSecondLeak() = runTest { // This test is to make sure that handlers installed on the second deferred do not leak val d1 = CompletableDeferred() val d2 = CompletableDeferred() diff --git a/kotlinx-coroutines-core/jvm/test/AwaitStressTest.kt b/kotlinx-coroutines-core/jvm/test/AwaitStressTest.kt index 8c84e7da3b..2af1c5d045 100644 --- a/kotlinx-coroutines-core/jvm/test/AwaitStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/AwaitStressTest.kt @@ -9,7 +9,7 @@ class AwaitStressTest : TestBase() { private val iterations = 50_000 * stressTestMultiplier @get:Rule - public val pool = ExecutorRule(4) + val pool = ExecutorRule(4) @Test fun testMultipleExceptions() = runTest { diff --git a/kotlinx-coroutines-core/jvm/test/CancellableContinuationJvmTest.kt b/kotlinx-coroutines-core/jvm/test/CancellableContinuationJvmTest.kt index 0ff675af86..3da3151219 100644 --- a/kotlinx-coroutines-core/jvm/test/CancellableContinuationJvmTest.kt +++ b/kotlinx-coroutines-core/jvm/test/CancellableContinuationJvmTest.kt @@ -63,16 +63,16 @@ class CancellableContinuationJvmTest : TestBase() { private var isCancelled = false @Volatile - public var hasSubscriber = false + var hasSubscriber = false - public fun subscribe() { + fun subscribe() { hasSubscriber = true while (!isCancelled) { Thread.sleep(10) } } - public fun cancel() { + fun cancel() { isCancelled = true } } diff --git a/kotlinx-coroutines-core/jvm/test/CancellableContinuationResumeCloseStressTest.kt b/kotlinx-coroutines-core/jvm/test/CancellableContinuationResumeCloseStressTest.kt index fa6030d2c9..7198d14954 100644 --- a/kotlinx-coroutines-core/jvm/test/CancellableContinuationResumeCloseStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/CancellableContinuationResumeCloseStressTest.kt @@ -9,7 +9,7 @@ import kotlin.test.Test class CancellableContinuationResumeCloseStressTest : TestBase() { @get:Rule - public val dispatcher = ExecutorRule(2) + val dispatcher = ExecutorRule(2) private val startBarrier = CyclicBarrier(3) private val doneBarrier = CyclicBarrier(2) @@ -47,7 +47,7 @@ class CancellableContinuationResumeCloseStressTest : TestBase() { private suspend fun resumeClose() = suspendCancellableCoroutine { cont -> dispatcher.executor.execute { startBarrier.await() // (2) resume at the same time - cont.resume("OK") { + cont.resume("OK") { _, _, _ -> close() } doneBarrier.await() diff --git a/kotlinx-coroutines-core/jvm/test/ConcurrentTestUtilities.kt b/kotlinx-coroutines-core/jvm/test/ConcurrentTestUtilities.kt index 6d6bc2127f..bf37a434be 100644 --- a/kotlinx-coroutines-core/jvm/test/ConcurrentTestUtilities.kt +++ b/kotlinx-coroutines-core/jvm/test/ConcurrentTestUtilities.kt @@ -1,5 +1,6 @@ package kotlinx.coroutines.exceptions +@Suppress("NOTHING_TO_INLINE") actual inline fun yieldThread() { Thread.yield() } actual fun currentThreadName(): String = Thread.currentThread().name diff --git a/kotlinx-coroutines-core/jvm/test/ExecutorsTest.kt b/kotlinx-coroutines-core/jvm/test/ExecutorsTest.kt index 3c60407bb9..e4389cda58 100644 --- a/kotlinx-coroutines-core/jvm/test/ExecutorsTest.kt +++ b/kotlinx-coroutines-core/jvm/test/ExecutorsTest.kt @@ -1,7 +1,6 @@ package kotlinx.coroutines import kotlinx.coroutines.testing.* -import org.junit.Test import java.util.concurrent.* import kotlin.coroutines.* import kotlin.test.* diff --git a/kotlinx-coroutines-core/jvm/test/FailFastOnStartTest.kt b/kotlinx-coroutines-core/jvm/test/FailFastOnStartTest.kt index 022fb6b630..2145d79c76 100644 --- a/kotlinx-coroutines-core/jvm/test/FailFastOnStartTest.kt +++ b/kotlinx-coroutines-core/jvm/test/FailFastOnStartTest.kt @@ -19,7 +19,7 @@ class FailFastOnStartTest : TestBase() { @Rule @JvmField - public val timeout: Timeout = Timeout.seconds(5) + val timeout: Timeout = Timeout.seconds(5) @Test fun testLaunch() = runTest(expected = ::mainException) { diff --git a/kotlinx-coroutines-core/jvm/test/MutexCancellationStressTest.kt b/kotlinx-coroutines-core/jvm/test/MutexCancellationStressTest.kt index 3528702a05..fc96716c00 100644 --- a/kotlinx-coroutines-core/jvm/test/MutexCancellationStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/MutexCancellationStressTest.kt @@ -38,6 +38,7 @@ class MutexCancellationStressTest : TestBase() { counterLocal[jobId].incrementAndGet() counter++ } + @Suppress("DEPRECATION") select { mutex.onLock(mutexOwners[jobId]) { counterLocal[jobId].incrementAndGet() diff --git a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt index ea0a8681f8..422d7b64f9 100644 --- a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt +++ b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryCustomExceptionsTest.kt @@ -11,12 +11,12 @@ class StackTraceRecoveryCustomExceptionsTest : TestBase() { internal class NonCopyable(val customData: Int) : Throwable() { // Bait - public constructor(cause: Throwable) : this(42) + constructor(cause: Throwable) : this(42) } internal class Copyable(val customData: Int) : Throwable(), CopyableThrowable { // Bait - public constructor(cause: Throwable) : this(42) + constructor(cause: Throwable) : this(42) override fun createCopy(): Copyable { val copy = Copyable(customData) diff --git a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryTest.kt b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryTest.kt index 169654d1a8..631966b65f 100644 --- a/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryTest.kt +++ b/kotlinx-coroutines-core/jvm/test/exceptions/StackTraceRecoveryTest.kt @@ -137,7 +137,7 @@ class StackTraceRecoveryTest : TestBase() { deferred.join() } - public class TrickyException() : Throwable() { + class TrickyException() : Throwable() { // To be sure ctor is never invoked @Suppress("UNUSED", "UNUSED_PARAMETER") private constructor(message: String, cause: Throwable): this() { diff --git a/kotlinx-coroutines-core/jvm/test/exceptions/Stacktraces.kt b/kotlinx-coroutines-core/jvm/test/exceptions/Stacktraces.kt index 5d85c9c9f2..5f61cc1886 100644 --- a/kotlinx-coroutines-core/jvm/test/exceptions/Stacktraces.kt +++ b/kotlinx-coroutines-core/jvm/test/exceptions/Stacktraces.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.* import java.io.* import kotlin.test.* -public fun verifyStackTrace(e: Throwable, vararg traces: String) { +fun verifyStackTrace(e: Throwable, vararg traces: String) { val stacktrace = toStackTrace(e) val normalizedActual = stacktrace.normalizeStackTrace() traces.forEach { @@ -20,23 +20,23 @@ public fun verifyStackTrace(e: Throwable, vararg traces: String) { assertEquals(traces.map { it.count("Caused by") }.sum(), causes) } -public fun verifyStackTrace(path: String, e: Throwable) { +fun verifyStackTrace(path: String, e: Throwable) { val resource = Job::class.java.classLoader.getResourceAsStream("stacktraces/$path.txt") val lines = resource.reader().readLines() verifyStackTrace(e, *lines.toTypedArray()) } -public fun toStackTrace(t: Throwable): String { +fun toStackTrace(t: Throwable): String { val sw = StringWriter() as Writer t.printStackTrace(PrintWriter(sw)) return sw.toString() } -public fun String.normalizeStackTrace(): String = +fun String.normalizeStackTrace(): String = replace(Regex(":[0-9]+"), "") // remove line numbers .replace("kotlinx_coroutines_core_main", "") // yay source sets .replace("kotlinx_coroutines_core", "") .replace(Regex("@[0-9a-f]+"), "") // remove hex addresses in debug toStrings .lines().joinToString("\n") // normalize line separators -public fun String.count(substring: String): Int = split(substring).size - 1 \ No newline at end of file +fun String.count(substring: String): Int = split(substring).size - 1 \ No newline at end of file diff --git a/kotlinx-coroutines-core/jvm/test/flow/SharingStressTest.kt b/kotlinx-coroutines-core/jvm/test/flow/SharingStressTest.kt index 0d160e6a70..f7e61ab76f 100644 --- a/kotlinx-coroutines-core/jvm/test/flow/SharingStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/flow/SharingStressTest.kt @@ -23,39 +23,39 @@ class SharingStressTest : TestBase() { val subscriberDispatcher = ExecutorRule(nSubscribers) @Test - public fun testNoReplayLazy() = + fun testNoReplayLazy() = testStress(0, started = SharingStarted.Lazily) @Test - public fun testNoReplayWhileSubscribed() = + fun testNoReplayWhileSubscribed() = testStress(0, started = SharingStarted.WhileSubscribed()) @Test - public fun testNoReplayWhileSubscribedTimeout() = + fun testNoReplayWhileSubscribedTimeout() = testStress(0, started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 50L)) @Test - public fun testReplay100WhileSubscribed() = + fun testReplay100WhileSubscribed() = testStress(100, started = SharingStarted.WhileSubscribed()) @Test - public fun testReplay100WhileSubscribedReset() = + fun testReplay100WhileSubscribedReset() = testStress(100, started = SharingStarted.WhileSubscribed(replayExpirationMillis = 0L)) @Test - public fun testReplay100WhileSubscribedTimeout() = + fun testReplay100WhileSubscribedTimeout() = testStress(100, started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 50L)) @Test - public fun testStateLazy() = + fun testStateLazy() = testStress(1, started = SharingStarted.Lazily) @Test - public fun testStateWhileSubscribed() = + fun testStateWhileSubscribed() = testStress(1, started = SharingStarted.WhileSubscribed()) @Test - public fun testStateWhileSubscribedReset() = + fun testStateWhileSubscribedReset() = testStress(1, started = SharingStarted.WhileSubscribed(replayExpirationMillis = 0L)) private fun testStress(replay: Int, started: SharingStarted) = runTest { diff --git a/kotlinx-coroutines-core/jvm/test/flow/StateFlowUpdateStressTest.kt b/kotlinx-coroutines-core/jvm/test/flow/StateFlowUpdateStressTest.kt index adc6610f25..96f7b6e257 100644 --- a/kotlinx-coroutines-core/jvm/test/flow/StateFlowUpdateStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/flow/StateFlowUpdateStressTest.kt @@ -10,7 +10,7 @@ class StateFlowUpdateStressTest : TestBase() { private val iterations = 1_000_000 * stressTestMultiplier @get:Rule - public val executor = ExecutorRule(2) + val executor = ExecutorRule(2) @Test fun testUpdate() = doTest { update { it + 1 } } diff --git a/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapCollectionStressTest.kt b/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapCollectionStressTest.kt index a85b3963bb..c48eb074dd 100644 --- a/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapCollectionStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapCollectionStressTest.kt @@ -1,11 +1,10 @@ package kotlinx.coroutines.internal import kotlinx.coroutines.testing.* -import junit.framework.Assert.* import kotlinx.coroutines.* import kotlinx.coroutines.debug.internal.* -import org.junit.* import kotlin.concurrent.* +import kotlin.test.* class ConcurrentWeakMapCollectionStressTest : TestBase() { private data class Key(val i: Int) @@ -26,4 +25,4 @@ class ConcurrentWeakMapCollectionStressTest : TestBase() { cleaner.interrupt() cleaner.join() } -} \ No newline at end of file +} diff --git a/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapTest.kt b/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapTest.kt index 2394e90d79..c90648672a 100644 --- a/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapTest.kt +++ b/kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapTest.kt @@ -1,10 +1,9 @@ package kotlinx.coroutines.internal import kotlinx.coroutines.testing.* -import junit.framework.Assert.* import kotlinx.coroutines.* import kotlinx.coroutines.debug.internal.* -import org.junit.* +import kotlin.test.* class ConcurrentWeakMapTest : TestBase() { @Test @@ -14,9 +13,9 @@ class ConcurrentWeakMapTest : TestBase() { // repeat adding/removing a few times repeat(5) { assertEquals(0, m.size) - assertEquals(emptySet(), m.keys) + assertEquals(emptySet(), m.keys) assertEquals(emptyList(), m.values.toList()) - assertEquals(emptySet>(), m.entries) + assertEquals(emptySet>(), m.entries) for ((k, v) in expect) { assertNull(m.put(k, v)) } diff --git a/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowDebounceTest.kt b/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowDebounceTest.kt index 7313b1a77e..09ae63993c 100644 --- a/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowDebounceTest.kt +++ b/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowDebounceTest.kt @@ -11,7 +11,7 @@ import kotlin.test.assertEquals class FlowDebounceTest : TestBase() { @Test - public fun testBasic() = withVirtualTime { + fun testBasic() = withVirtualTime { expect(1) val flow = flow { expect(3) diff --git a/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowSampleTest.kt b/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowSampleTest.kt index a19c4b75ec..95fbc195f3 100644 --- a/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowSampleTest.kt +++ b/kotlinx-coroutines-core/jvm/test/jdk8/time/FlowSampleTest.kt @@ -11,7 +11,7 @@ import kotlin.test.assertEquals class FlowSampleTest : TestBase() { @Test - public fun testBasic() = withVirtualTime { + fun testBasic() = withVirtualTime { expect(1) val flow = flow { expect(3) diff --git a/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt b/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt index 37051794b0..d19584bae4 100644 --- a/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt +++ b/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt @@ -22,6 +22,7 @@ class MutexLincheckTest : AbstractLincheckTest() { // TODO: `onLock` with non-null owner is non-linearizable // onLock may suspend in case of clause re-registration. + @Suppress("DEPRECATION") @Operation(allowExtraSuspension = true, promptCancellation = true) suspend fun onLock() = select { mutex.onLock(null) {} } diff --git a/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt b/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt index 423c1a8a55..fe3ae250e0 100644 --- a/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.sync.* import org.junit.Test import kotlin.test.* +@Suppress("DEPRECATION") class SelectPhilosophersStressTest : TestBase() { private val TEST_DURATION = 3000L * stressTestMultiplierSqrt diff --git a/kotlinx-coroutines-core/native/test/ConcurrentTestUtilities.kt b/kotlinx-coroutines-core/native/test/ConcurrentTestUtilities.kt index ff1638fd9a..0f008192a0 100644 --- a/kotlinx-coroutines-core/native/test/ConcurrentTestUtilities.kt +++ b/kotlinx-coroutines-core/native/test/ConcurrentTestUtilities.kt @@ -3,6 +3,7 @@ package kotlinx.coroutines.exceptions import platform.posix.* import kotlin.native.concurrent.* +@Suppress("NOTHING_TO_INLINE") actual inline fun yieldThread() { sched_yield() } actual fun currentThreadName(): String = Worker.current.name diff --git a/kotlinx-coroutines-core/nativeDarwin/test/MainDispatcherTest.kt b/kotlinx-coroutines-core/nativeDarwin/test/MainDispatcherTest.kt index 0094bcd7a1..1b072e5fdd 100644 --- a/kotlinx-coroutines-core/nativeDarwin/test/MainDispatcherTest.kt +++ b/kotlinx-coroutines-core/nativeDarwin/test/MainDispatcherTest.kt @@ -10,11 +10,13 @@ import kotlin.test.* class MainDispatcherTest : MainDispatcherTestBase.WithRealTimeDelay() { + @OptIn(ExperimentalForeignApi::class) override fun isMainThread(): Boolean = CFRunLoopGetCurrent() == CFRunLoopGetMain() // skip if already on the main thread, run blocking doesn't really work well with that override fun shouldSkipTesting(): Boolean = isMainThread() + @OptIn(BetaInteropApi::class) override fun scheduleOnMainQueue(block: () -> Unit) { autoreleasepool { dispatch_async(dispatch_get_main_queue()) { diff --git a/kotlinx-coroutines-core/wasmJs/test/PromiseTest.kt b/kotlinx-coroutines-core/wasmJs/test/PromiseTest.kt index e72e661517..6123a27695 100644 --- a/kotlinx-coroutines-core/wasmJs/test/PromiseTest.kt +++ b/kotlinx-coroutines-core/wasmJs/test/PromiseTest.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.testing.* import kotlin.js.* import kotlin.test.* +@OptIn(ExperimentalWasmJsInterop::class) class PromiseTest : TestBase() { @Test fun testPromiseResolvedAsDeferred() = GlobalScope.promise { diff --git a/kotlinx-coroutines-core/wasmJs/test/PropagateExceptionFinalResortTest.kt b/kotlinx-coroutines-core/wasmJs/test/PropagateExceptionFinalResortTest.kt index 2449b72760..a792ace9e9 100644 --- a/kotlinx-coroutines-core/wasmJs/test/PropagateExceptionFinalResortTest.kt +++ b/kotlinx-coroutines-core/wasmJs/test/PropagateExceptionFinalResortTest.kt @@ -30,6 +30,7 @@ class PropagateExceptionFinalResortTest : TestBase() { } } +@OptIn(ExperimentalWasmJsInterop::class) private fun addUncaughtExceptionHandlerHelper() { js(""" globalThis.exceptionCaught = false; @@ -40,10 +41,12 @@ private fun addUncaughtExceptionHandlerHelper() { """) } +@OptIn(ExperimentalWasmJsInterop::class) private fun removeHandlerHelper() { js(""" process.removeListener('uncaughtException', globalThis.exceptionHandler); """) } +@OptIn(ExperimentalWasmJsInterop::class) private fun exceptionCaught(): Boolean = js("globalThis.exceptionCaught") diff --git a/kotlinx-coroutines-debug/test/RecoveryExample.kt b/kotlinx-coroutines-debug/test/RecoveryExample.kt index eeadcf5618..88ba9cccfe 100644 --- a/kotlinx-coroutines-debug/test/RecoveryExample.kt +++ b/kotlinx-coroutines-debug/test/RecoveryExample.kt @@ -13,7 +13,7 @@ object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName( return doWork() + 1 } - public suspend fun awaitAsynchronousWorkInMainThread() { + suspend fun awaitAsynchronousWorkInMainThread() { val task = async(Dispatchers.Default) { asynchronousWork() } diff --git a/kotlinx-coroutines-debug/test/StacktraceUtils.kt b/kotlinx-coroutines-debug/test/StacktraceUtils.kt index 90ce38907e..8256aa3152 100644 --- a/kotlinx-coroutines-debug/test/StacktraceUtils.kt +++ b/kotlinx-coroutines-debug/test/StacktraceUtils.kt @@ -3,7 +3,7 @@ package kotlinx.coroutines.debug import java.io.* import kotlin.test.* -public fun String.trimStackTrace(): String = +fun String.trimStackTrace(): String = trimIndent() // Remove source line .replace(Regex(":[0-9]+"), "") @@ -14,7 +14,7 @@ public fun String.trimStackTrace(): String = .replace(Regex("\t"), "") .replace("sun.misc.Unsafe.", "jdk.internal.misc.Unsafe.") // JDK8->JDK11 -public fun verifyStackTrace(e: Throwable, traces: List) { +fun verifyStackTrace(e: Throwable, traces: List) { val stacktrace = toStackTrace(e) val trimmedStackTrace = stacktrace.trimStackTrace() traces.forEach { @@ -29,15 +29,15 @@ public fun verifyStackTrace(e: Throwable, traces: List) { assertEquals(causes, traces.map { it.count("Caused by") }.sum()) } -public fun toStackTrace(t: Throwable): String { +fun toStackTrace(t: Throwable): String { val sw = StringWriter() t.printStackTrace(PrintWriter(sw)) return sw.toString() } -public fun String.count(substring: String): Int = split(substring).size - 1 +fun String.count(substring: String): Int = split(substring).size - 1 -public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null, finally: () -> Unit) { +fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null, finally: () -> Unit) { try { verifyDump(*traces, ignoredCoroutine = ignoredCoroutine) } finally { @@ -181,7 +181,7 @@ private data class CoroutineDumpHeader( } } -public fun verifyDump(vararg expectedTraces: String, ignoredCoroutine: String? = null) { +fun verifyDump(vararg expectedTraces: String, ignoredCoroutine: String? = null) { val baos = ByteArrayOutputStream() DebugProbes.dumpCoroutines(PrintStream(baos)) val wholeDump = baos.toString() @@ -210,9 +210,9 @@ public fun verifyDump(vararg expectedTraces: String, ignoredCoroutine: String? = } } -public fun String.trimPackage() = replace("kotlinx.coroutines.debug.", "") +fun String.trimPackage() = replace("kotlinx.coroutines.debug.", "") -public fun verifyPartialDump(createdCoroutinesCount: Int, vararg frames: String) { +fun verifyPartialDump(createdCoroutinesCount: Int, vararg frames: String) { val baos = ByteArrayOutputStream() DebugProbes.dumpCoroutines(PrintStream(baos)) val dump = baos.toString() diff --git a/kotlinx-coroutines-debug/test/TestRuleExample.kt b/kotlinx-coroutines-debug/test/TestRuleExample.kt index df5473e084..1877cf1acc 100644 --- a/kotlinx-coroutines-debug/test/TestRuleExample.kt +++ b/kotlinx-coroutines-debug/test/TestRuleExample.kt @@ -7,7 +7,7 @@ class TestRuleExample { @JvmField @Rule - public val timeout = CoroutinesTimeout.seconds(1) + val timeout = CoroutinesTimeout.seconds(1) private suspend fun someFunctionDeepInTheStack() { withContext(Dispatchers.IO) { diff --git a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutDisabledTracesTest.kt b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutDisabledTracesTest.kt index 8a24313926..d1a38e4ed4 100644 --- a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutDisabledTracesTest.kt +++ b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutDisabledTracesTest.kt @@ -9,7 +9,7 @@ class CoroutinesTimeoutDisabledTracesTest : TestBase(disableOutCheck = true) { @Rule @JvmField - public val validation = TestFailureValidation( + val validation = TestFailureValidation( 500, true, false, TestResultSpec( "hangingTest", expectedOutParts = listOf( diff --git a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutEagerTest.kt b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutEagerTest.kt index 458d0eed8b..61211551f2 100644 --- a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutEagerTest.kt +++ b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutEagerTest.kt @@ -9,7 +9,7 @@ class CoroutinesTimeoutEagerTest : TestBase(disableOutCheck = true) { @Rule @JvmField - public val validation = TestFailureValidation( + val validation = TestFailureValidation( 500, true, true, TestResultSpec( "hangingTest", expectedOutParts = listOf( diff --git a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutTest.kt b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutTest.kt index 9a429d5b3d..4b18729ba4 100644 --- a/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutTest.kt +++ b/kotlinx-coroutines-debug/test/junit4/CoroutinesTimeoutTest.kt @@ -9,7 +9,7 @@ class CoroutinesTimeoutTest : TestBase(disableOutCheck = true) { @Rule @JvmField - public val validation = TestFailureValidation( + val validation = TestFailureValidation( 1000, false, true, TestResultSpec("throwingTest", error = RuntimeException::class.java), TestResultSpec("successfulTest"), diff --git a/kotlinx-coroutines-test/common/src/TestBuilders.kt b/kotlinx-coroutines-test/common/src/TestBuilders.kt index 57ae3e1150..8258777e5b 100644 --- a/kotlinx-coroutines-test/common/src/TestBuilders.kt +++ b/kotlinx-coroutines-test/common/src/TestBuilders.kt @@ -352,7 +352,7 @@ public fun TestScope.runTest( } timeoutError = UncompletedCoroutinesError(message) cancellationException = CancellationException("The test timed out") - (scope as Job).cancel(cancellationException!!) + (scope as Job).cancel(cancellationException) } } scope.join() diff --git a/kotlinx-coroutines-test/common/src/TestDispatcher.kt b/kotlinx-coroutines-test/common/src/TestDispatcher.kt index a4427a1a6f..f9292360ef 100644 --- a/kotlinx-coroutines-test/common/src/TestDispatcher.kt +++ b/kotlinx-coroutines-test/common/src/TestDispatcher.kt @@ -42,7 +42,6 @@ public abstract class TestDispatcher internal constructor() : CoroutineDispatche scheduler.registerEvent(this, timeMillis, block, context) { false } /** @suppress */ - @Suppress("CANNOT_OVERRIDE_INVISIBLE_MEMBER") @Deprecated("Is only needed internally", level = DeprecationLevel.HIDDEN) public override fun timeoutMessage(timeout: Duration): String = "Timed out after $timeout of _virtual_ (kotlinx.coroutines.test) time. " + diff --git a/kotlinx-coroutines-test/common/test/RunTestTest.kt b/kotlinx-coroutines-test/common/test/RunTestTest.kt index a595299121..b2ee48227c 100644 --- a/kotlinx-coroutines-test/common/test/RunTestTest.kt +++ b/kotlinx-coroutines-test/common/test/RunTestTest.kt @@ -9,6 +9,7 @@ import kotlin.test.* import kotlin.test.assertFailsWith import kotlin.time.* import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds class RunTestTest { @@ -50,44 +51,6 @@ class RunTestTest { } } - /** Tests that even the dispatch timeout of `0` is fine if all the dispatches go through the same scheduler. */ - @Test - fun testRunTestWithZeroDispatchTimeoutWithControlledDispatches() = runTest(dispatchTimeoutMs = 0) { - // below is some arbitrary concurrent code where all dispatches go through the same scheduler. - launch { - delay(2000) - } - val deferred = async { - val job = launch(StandardTestDispatcher(testScheduler)) { - launch { - delay(500) - } - delay(1000) - } - job.join() - } - deferred.await() - } - - /** Tests that too low of a dispatch timeout causes crashes. */ - @Test - fun testRunTestWithSmallDispatchTimeout() = testResultMap({ fn -> - try { - fn() - fail("shouldn't be reached") - } catch (e: Throwable) { - assertIs(e) - } - }) { - runTest(dispatchTimeoutMs = 100) { - withContext(Dispatchers.Default) { - delay(10000) - 3 - } - fail("shouldn't be reached") - } - } - /** * Tests that [runTest] times out after the specified time. */ @@ -149,7 +112,7 @@ class RunTestTest { assertFalse((e.message ?: "").contains(name2)) } }) { - runTest(dispatchTimeoutMs = 10) { + runTest(timeout = 10.milliseconds) { launch(CoroutineName(name1)) { CompletableDeferred().await() } @@ -184,17 +147,9 @@ class RunTestTest { } } - /** Tests that real delays can be accounted for with a large enough dispatch timeout. */ - @Test - fun testRunTestWithLargeDispatchTimeout() = runTest(dispatchTimeoutMs = 5000) { - withContext(Dispatchers.Default) { - delay(50) - } - } - /** Tests that delays can be accounted for with a large enough timeout. */ @Test - fun testRunTestWithLargeTimeout() = runTest(timeout = 5000.milliseconds) { + fun testRunTestWithLargeTimeout() = runTest(timeout = 5.seconds) { withContext(Dispatchers.Default) { delay(50) } @@ -388,7 +343,7 @@ class RunTestTest { try { it() fail("should not be reached") - } catch (e: TestException) { + } catch (_: TestException) { // expected } }) { @@ -479,7 +434,7 @@ class RunTestTest { try { it() fail("unreached") - } catch (e: CancellationException) { + } catch (_: CancellationException) { // expected } }) { @@ -487,4 +442,54 @@ class RunTestTest { cancel(CancellationException("Oh no", TestException())) } } + + @Suppress("DEPRECATION") + class RunTestWithDispatchTimeoutTest { + /** Tests that too low of a dispatch timeout causes crashes. */ + @Test + fun testRunTestWithSmallDispatchTimeout() = testResultMap({ fn -> + try { + fn() + fail("shouldn't be reached") + } catch (e: Throwable) { + assertIs(e) + } + }) { + runTest(dispatchTimeoutMs = 100) { + withContext(Dispatchers.Default) { + delay(10.seconds) + 3 + } + fail("shouldn't be reached") + } + } + + /** Tests that even the dispatch timeout of `0` is fine if all the dispatches go through the same scheduler. */ + @Test + fun testRunTestWithZeroDispatchTimeoutWithControlledDispatches() = runTest(dispatchTimeoutMs = 0) { + // below is some arbitrary concurrent code where all dispatches go through the same scheduler. + launch { + delay(2000) + } + val deferred = async { + val job = launch(StandardTestDispatcher(testScheduler)) { + launch { + delay(500) + } + delay(1000) + } + job.join() + } + deferred.await() + } + + /** Tests that real delays can be accounted for with a large enough dispatch timeout. */ + @Test + fun testRunTestWithLargeDispatchTimeout() = runTest(dispatchTimeoutMs = 5000) { + withContext(Dispatchers.Default) { + delay(50) + } + } + + } } diff --git a/kotlinx-coroutines-test/wasmJs/test/Helpers.kt b/kotlinx-coroutines-test/wasmJs/test/Helpers.kt index a394c1f19f..aa28555ef4 100644 --- a/kotlinx-coroutines-test/wasmJs/test/Helpers.kt +++ b/kotlinx-coroutines-test/wasmJs/test/Helpers.kt @@ -1,5 +1,6 @@ package kotlinx.coroutines.test +@OptIn(ExperimentalWasmJsInterop::class) actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult = block().then( { diff --git a/kotlinx-coroutines-test/wasmJs/test/PromiseTest.kt b/kotlinx-coroutines-test/wasmJs/test/PromiseTest.kt index f55517154a..7b5094a5b9 100644 --- a/kotlinx-coroutines-test/wasmJs/test/PromiseTest.kt +++ b/kotlinx-coroutines-test/wasmJs/test/PromiseTest.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.* import kotlin.test.* class PromiseTest { + @OptIn(ExperimentalWasmJsInterop::class) @Test fun testCompletionFromPromise() = runTest { var promiseEntered = false @@ -15,4 +16,4 @@ class PromiseTest { p.await() assertTrue(promiseEntered) } -} \ No newline at end of file +} diff --git a/reactive/kotlinx-coroutines-reactive/test/ReactiveStreamTckTest.kt b/reactive/kotlinx-coroutines-reactive/test/ReactiveStreamTckTest.kt index 9a4fc5230d..7d51c6c00a 100644 --- a/reactive/kotlinx-coroutines-reactive/test/ReactiveStreamTckTest.kt +++ b/reactive/kotlinx-coroutines-reactive/test/ReactiveStreamTckTest.kt @@ -16,10 +16,10 @@ class ReactiveStreamTckTest : TestBase() { } @DataProvider(name = "dispatchers") - public fun dispatchers(): Array> = Dispatcher.values().map { arrayOf(it) }.toTypedArray() + fun dispatchers(): Array> = Dispatcher.values().map { arrayOf(it) }.toTypedArray() - public class ReactiveStreamTckTestSuite( + class ReactiveStreamTckTestSuite( private val dispatcher: Dispatcher ) : PublisherVerification(TestEnvironment(500, 500)) { @@ -34,7 +34,7 @@ class ReactiveStreamTckTest : TestBase() { } @Test - public override fun optional_spec105_emptyStreamMustTerminateBySignallingOnComplete() { + override fun optional_spec105_emptyStreamMustTerminateBySignallingOnComplete() { throw SkipException("Skipped") } diff --git a/reactive/kotlinx-coroutines-reactor/test/Check.kt b/reactive/kotlinx-coroutines-reactor/test/Check.kt index d5a9a57df6..47ddd493ed 100644 --- a/reactive/kotlinx-coroutines-reactor/test/Check.kt +++ b/reactive/kotlinx-coroutines-reactor/test/Check.kt @@ -5,7 +5,7 @@ import reactor.core.publisher.Mono fun checkMonoValue( mono: Mono, - checker: (T) -> Unit + checker: (T?) -> Unit ) { val monoValue = mono.block() checker(monoValue) @@ -33,7 +33,7 @@ fun checkSingleValue( fun checkErroneous( flux: Flux<*>, - checker: (Throwable) -> Unit + checker: (Throwable?) -> Unit ) { val singleNotification = flux.materialize().toIterable().single() checker(singleNotification.throwable) diff --git a/reactive/kotlinx-coroutines-reactor/test/FluxMultiTest.kt b/reactive/kotlinx-coroutines-reactor/test/FluxMultiTest.kt index 562f0a9b0e..3739bed6c6 100644 --- a/reactive/kotlinx-coroutines-reactor/test/FluxMultiTest.kt +++ b/reactive/kotlinx-coroutines-reactor/test/FluxMultiTest.kt @@ -1,10 +1,8 @@ package kotlinx.coroutines.reactor -import kotlinx.coroutines.testing.* import kotlinx.coroutines.* import kotlinx.coroutines.reactive.* -import org.junit.* -import org.junit.Test +import kotlinx.coroutines.testing.* import reactor.core.publisher.* import java.io.* import kotlin.test.* @@ -35,8 +33,8 @@ class FluxMultiTest : TestBase() { jobs.forEach { it.join() } } checkMonoValue(flux.collectList()) { list -> - assertEquals(n, list.size) - assertEquals((0 until n).toList(), list.sorted()) + assertEquals(n, list?.size) + assertEquals((0 until n).toList(), list?.sorted()) } } diff --git a/reactive/kotlinx-coroutines-reactor/test/FluxSingleTest.kt b/reactive/kotlinx-coroutines-reactor/test/FluxSingleTest.kt index 6bc6dc1ec4..5b9ffc2d3b 100644 --- a/reactive/kotlinx-coroutines-reactor/test/FluxSingleTest.kt +++ b/reactive/kotlinx-coroutines-reactor/test/FluxSingleTest.kt @@ -176,7 +176,7 @@ class FluxSingleTest : TestBase() { checkErroneous(flux) { assert(it is IllegalStateException) - assertEquals("OK", it.message) + assertEquals("OK", it?.message) } } diff --git a/reactive/kotlinx-coroutines-reactor/test/ReactorContextTest.kt b/reactive/kotlinx-coroutines-reactor/test/ReactorContextTest.kt index 5bc6d45115..184c8d5037 100644 --- a/reactive/kotlinx-coroutines-reactor/test/ReactorContextTest.kt +++ b/reactive/kotlinx-coroutines-reactor/test/ReactorContextTest.kt @@ -100,9 +100,9 @@ class ReactorContextTest : TestBase() { private fun bar(): Flow = flux { val ctx = reactorContext() - (1..3).forEach { send(ctx.getOrDefault(it, "noValue")) } + (1..3).forEach { send(ctx.getOrDefault(it, "noValue")!!) } }.asFlow() private suspend fun reactorContext() = coroutineContext[ReactorContext]!!.context -} \ No newline at end of file +} diff --git a/test-utils/jvm/src/FieldWalker.kt b/test-utils/jvm/src/FieldWalker.kt index e7303199aa..9815793c13 100644 --- a/test-utils/jvm/src/FieldWalker.kt +++ b/test-utils/jvm/src/FieldWalker.kt @@ -35,9 +35,9 @@ object FieldWalker { * Reflectively starts to walk through object graph and returns identity set of all reachable objects. * Use [walkRefs] if you need a path from root for debugging. */ - public fun walk(root: Any?): Set = walkRefs(root, false).keys + fun walk(root: Any?): Set = walkRefs(root, false).keys - public fun assertReachableCount(expected: Int, root: Any?, rootStatics: Boolean = false, predicate: (Any) -> Boolean) { + fun assertReachableCount(expected: Int, root: Any?, rootStatics: Boolean = false, predicate: (Any) -> Boolean) { val visited = walkRefs(root, rootStatics) val actual = visited.keys.filter(predicate) if (actual.size != expected) { @@ -86,9 +86,6 @@ object FieldWalker { cur = ref.parent path += "[${ref.index}]" } - else -> { - // Nothing, kludge for IDE - } } } path.reverse() @@ -127,7 +124,7 @@ object FieldWalker { element is AtomicLongFieldUpdater<*> -> { /* filter it out here to suppress its subclasses too */ } - element is ExecutorService && type.name == "java.util.concurrent.Executors\$DelegatedExecutorService" -> { + element is ExecutorService && type.name == $$"java.util.concurrent.Executors$DelegatedExecutorService" -> { /* can't access anything in the executor */ } // All the other classes are reflectively scanned diff --git a/test-utils/jvm/src/TestBase.kt b/test-utils/jvm/src/TestBase.kt index 194e71b474..db5a3700b2 100644 --- a/test-utils/jvm/src/TestBase.kt +++ b/test-utils/jvm/src/TestBase.kt @@ -10,7 +10,7 @@ import kotlin.test.* actual val VERBOSE = try { System.getProperty("test.verbose")?.toBoolean() ?: false -} catch (e: SecurityException) { +} catch (_: SecurityException) { false } @@ -28,8 +28,6 @@ private const val SHUTDOWN_TIMEOUT = 1_000L // 1s at most to wait per thread */ actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMultiplierSqrt - -@Suppress("ACTUAL_WITHOUT_EXPECT") actual typealias TestResult = Unit internal actual fun lastResortReportException(error: Throwable) { @@ -118,7 +116,7 @@ actual open class TestBase( expected: ((Throwable) -> Boolean)?, unhandled: List<(Throwable) -> Boolean>, block: suspend CoroutineScope.() -> Unit - ): TestResult { + ) { var exCount = 0 var ex: Throwable? = null try { diff --git a/test-utils/native/src/TestBase.kt b/test-utils/native/src/TestBase.kt index eac3dde9f0..c5720bda42 100644 --- a/test-utils/native/src/TestBase.kt +++ b/test-utils/native/src/TestBase.kt @@ -7,27 +7,26 @@ actual val VERBOSE = false actual typealias NoNative = Ignore -public actual val isStressTest: Boolean = false -public actual val stressTestMultiplier: Int = 1 -public actual val stressTestMultiplierSqrt: Int = 1 +actual val isStressTest: Boolean = false +actual val stressTestMultiplier: Int = 1 +actual val stressTestMultiplierSqrt: Int = 1 -@Suppress("ACTUAL_WITHOUT_EXPECT") -public actual typealias TestResult = Unit +actual typealias TestResult = Unit internal actual fun lastResortReportException(error: Throwable) { println(error) } -public actual open class TestBase actual constructor(): OrderedExecutionTestBase(), ErrorCatching by ErrorCatching.Impl() { +actual open class TestBase actual constructor(): OrderedExecutionTestBase(), ErrorCatching by ErrorCatching.Impl() { actual fun println(message: Any?) { kotlin.io.println(message) } - public actual fun runTest( + actual fun runTest( expected: ((Throwable) -> Boolean)?, unhandled: List<(Throwable) -> Boolean>, block: suspend CoroutineScope.() -> Unit - ): TestResult { + ) { var exCount = 0 var ex: Throwable? = null try { @@ -56,10 +55,10 @@ public actual open class TestBase actual constructor(): OrderedExecutionTestBase } } -public actual val isNative = true +actual val isNative = true -public actual val isBoundByJsTestTimeout = false +actual val isBoundByJsTestTimeout = false -public actual val isJavaAndWindows: Boolean get() = false +actual val isJavaAndWindows: Boolean get() = false actual val usesSharedEventLoop: Boolean = false diff --git a/test-utils/wasmJs/src/TestBase.kt b/test-utils/wasmJs/src/TestBase.kt index 021dc5ee89..d3827287d4 100644 --- a/test-utils/wasmJs/src/TestBase.kt +++ b/test-utils/wasmJs/src/TestBase.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalWasmJsInterop::class) + package kotlinx.coroutines.testing import kotlin.test.* diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/TestComponent.kt b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/TestComponent.kt index fbd6d8135a..85b143ebf5 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/TestComponent.kt +++ b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/TestComponent.kt @@ -2,12 +2,12 @@ package ordered.tests import kotlinx.coroutines.* -public class TestComponent { +class TestComponent { internal lateinit var caughtException: Throwable private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main + CoroutineExceptionHandler { _, e -> caughtException = e}) - public var launchCompleted = false - public var delayedLaunchCompleted = false + var launchCompleted = false + var delayedLaunchCompleted = false fun launchSomething() { scope.launch { diff --git a/ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt b/ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt index 9261b2e1c7..2eb40d0fe3 100644 --- a/ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt +++ b/ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt @@ -22,7 +22,7 @@ public sealed class HandlerDispatcher : MainCoroutineDispatcher(), Delay { * This dispatcher does not use [Handler.post] when current looper is the same as looper of the handler. * * Immediate dispatcher is safe from stack overflows and in case of nested invocations forms event-loop similar to [Dispatchers.Unconfined]. - * The event loop is an advanced topic and its implications can be found in [Dispatchers.Unconfined] documentation. + * The event loop is an advanced topic, and its implications can be found in [Dispatchers.Unconfined] documentation. * * Example of usage: * ``` @@ -193,9 +193,9 @@ private suspend fun awaitFrameSlowPath(): Long = suspendCancellableCoroutine { c if (Looper.myLooper() === Looper.getMainLooper()) { // Check if we are already in the main looper thread updateChoreographerAndPostFrameCallback(cont) } else { // post into looper thread to figure it out - Dispatchers.Main.dispatch(cont.context, Runnable { + Dispatchers.Main.dispatch(cont.context) { updateChoreographerAndPostFrameCallback(cont) - }) + } } } diff --git a/ui/kotlinx-coroutines-android/testdata/r8-test-common.pro b/ui/kotlinx-coroutines-android/testdata/r8-test-common.pro index d29377eb40..38d731eda3 100644 --- a/ui/kotlinx-coroutines-android/testdata/r8-test-common.pro +++ b/ui/kotlinx-coroutines-android/testdata/r8-test-common.pro @@ -15,4 +15,4 @@ } # We are cheating a bit by not having android.jar on R8's library classpath. Ignore those warnings. --ignorewarnings \ No newline at end of file +-dontwarn diff --git a/ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro b/ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro index 63dc24ccd5..c3cba5626c 100644 --- a/ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro +++ b/ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro @@ -6,7 +6,7 @@ -checkdiscard class kotlinx.coroutines.internal.FastServiceLoader -checkdiscard class kotlinx.coroutines.DebugKt -checkdiscard class kotlinx.coroutines.internal.StackTraceRecoveryKt --checkdiscard class kotlinx.coroutines.debug.DebugProbesKt +-checkdiscard class kotlinx.coroutines.debug.internal.DebugProbesKt # Real android projects do not keep this class, but somehow it is kept in this test (R8 bug) # -checkdiscard class kotlinx.coroutines.internal.MissingMainCoroutineDispatcher diff --git a/ui/kotlinx-coroutines-javafx/test/examples/FxAsFlow.kt b/ui/kotlinx-coroutines-javafx/test/examples/FxAsFlow.kt index 00003f7860..2770ff96ee 100644 --- a/ui/kotlinx-coroutines-javafx/test/examples/FxAsFlow.kt +++ b/ui/kotlinx-coroutines-javafx/test/examples/FxAsFlow.kt @@ -33,7 +33,7 @@ class FxAsFlowApp: Application(), CoroutineScope { private val spinner = Spinner() private val spinnerChangesLabel = Label() - public override fun start( primaryStage: Stage) { + override fun start( primaryStage: Stage) { val gridPane = GridPane() gridPane.apply { hgap = 10.0 @@ -53,7 +53,7 @@ class FxAsFlowApp: Application(), CoroutineScope { } } - public override fun stop() { + override fun stop() { super.stop() job.cancel() job = Job()