Commit b78d9ad3 authored by Him188's avatar Him188

Rearrange tests

parent 9ae02b5a
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
package net.mamoe.mirai.test package net.mamoe.mirai.test
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertNotEquals import kotlin.test.assertNotEquals
...@@ -32,9 +29,4 @@ fun Boolean.shouldBeFalse() = assertFalse { this } ...@@ -32,9 +29,4 @@ fun Boolean.shouldBeFalse() = assertFalse { this }
infix fun <E> E.shouldBeEqualTo(another: E) = assertEquals(another, this) infix fun <E> E.shouldBeEqualTo(another: E) = assertEquals(another, this)
@TestDSL @TestDSL
infix fun <E> E.shouldNotBeEqualTo(another: E) = assertNotEquals(another, this) infix fun <E> E.shouldNotBeEqualTo(another: E) = assertNotEquals(another, this)
\ No newline at end of file
internal expect fun <R> runBlocking(
context: CoroutineContext = EmptyCoroutineContext,
block: suspend CoroutineScope.() -> R
): R
\ No newline at end of file
...@@ -11,7 +11,7 @@ package net.mamoe.mirai.event ...@@ -11,7 +11,7 @@ package net.mamoe.mirai.event
import kotlinx.coroutines.CompletableJob import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import net.mamoe.mirai.test.runBlocking import net.mamoe.mirai.utils.internal.runBlocking
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
......
...@@ -13,7 +13,6 @@ import kotlinx.coroutines.* ...@@ -13,7 +13,6 @@ import kotlinx.coroutines.*
import net.mamoe.mirai.event.TestEvent import net.mamoe.mirai.event.TestEvent
import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.syncFromEvent import net.mamoe.mirai.event.syncFromEvent
import net.mamoe.mirai.test.runBlocking
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.resume import kotlin.coroutines.resume
...@@ -23,16 +22,16 @@ import kotlin.test.assertFailsWith ...@@ -23,16 +22,16 @@ import kotlin.test.assertFailsWith
internal class SubscribingGetTest { internal class SubscribingGetTest {
@Test @Test
fun testSyncFromEvent(): Unit = runBlocking { fun testSyncFromEvent() {
withTimeout(500) { runBlockingWithTimeout(1000) {
suspendCancellableCoroutine<Unit> { cont -> suspendCancellableCoroutine<Unit> { cont ->
launch { launch {
syncFromEvent(5000) { _: TestEvent -> syncFromEvent(500) { _: TestEvent ->
cont.resume(Unit) cont.resume(Unit)
} }
} }
delay(200)
launch { launch {
delay(200)
TestEvent().broadcast() TestEvent().broadcast()
} }
} }
......
package net.mamoe.mirai.test
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
internal actual fun <R> runBlocking(
context: CoroutineContext,
block: suspend CoroutineScope.() -> R
): R = kotlinx.coroutines.runBlocking(context, block)
\ No newline at end of file
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
package net.mamoe.mirai.utils package net.mamoe.mirai.utils
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.mamoe.mirai.test.runBlocking
import net.mamoe.mirai.test.shouldBeEqualTo import net.mamoe.mirai.test.shouldBeEqualTo
import net.mamoe.mirai.test.shouldBeTrue import net.mamoe.mirai.test.shouldBeTrue
import kotlin.test.Test import kotlin.test.Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment