mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-06 08:00:10 +08:00
Introduce base class for tests AbstractTest
This commit is contained in:
parent
63ae9b276f
commit
5dcccd1402
10
mirai-core/src/androidTest/kotlin/package.kt
Normal file
10
mirai-core/src/androidTest/kotlin/package.kt
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
|
||||
internal actual fun initPlatform() {
|
||||
init
|
||||
}
|
||||
|
||||
private val init by lazy {
|
||||
MiraiLogger.setDefaultLoggerCreator {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
net.mamoe.mirai.internal.utils.StdoutLogger(it)
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ import net.mamoe.mirai.internal.MiraiImpl
|
||||
import net.mamoe.mirai.internal.asQQAndroidBot
|
||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgTransmit
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.utils.cast
|
||||
import net.mamoe.mirai.utils.safeCast
|
||||
|
||||
// internal runtime value, not serializable
|
||||
@ -79,7 +78,7 @@ internal data class ForwardMessageInternal(
|
||||
brief = brief,
|
||||
source = source,
|
||||
summary = summary.trim(),
|
||||
nodeList = Mirai.cast<MiraiImpl>().run { transmits.toForwardMessageNodes(bot, refineContext) }
|
||||
nodeList = MiraiImpl.run { transmits.toForwardMessageNodes(bot, refineContext) }
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -10,11 +10,12 @@
|
||||
package net.mamoe.mirai.internal
|
||||
|
||||
import kotlinx.io.core.toByteArray
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import net.mamoe.mirai.utils.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class PlatformUtilsTest {
|
||||
internal class PlatformUtilsTest : AbstractTest() {
|
||||
|
||||
@Test
|
||||
fun testZip() {
|
||||
|
@ -12,13 +12,14 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import net.mamoe.mirai.internal.utils.ScheduledJob
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.time.seconds
|
||||
|
||||
internal class ScheduledJobTest {
|
||||
internal class ScheduledJobTest : AbstractTest() {
|
||||
@Test
|
||||
fun testScheduledJob() {
|
||||
runBlocking {
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
package net.mamoe.mirai.internal
|
||||
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import net.mamoe.mirai.utils.hexToBytes
|
||||
import net.mamoe.mirai.utils.toByteArray
|
||||
import net.mamoe.mirai.utils.toUHexString
|
||||
@ -16,7 +17,7 @@ import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class TypeConversionTest {
|
||||
internal class TypeConversionTest : AbstractTest() {
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@Test
|
||||
|
@ -10,11 +10,12 @@
|
||||
|
||||
package net.mamoe.mirai.internal.utils
|
||||
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
internal class FileSystemTest {
|
||||
internal class FileSystemTest : AbstractTest() {
|
||||
|
||||
private val fs = FileSystem
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
package net.mamoe.mirai.internal.message.code
|
||||
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import net.mamoe.mirai.message.code.MiraiCode.deserializeMiraiCode
|
||||
import net.mamoe.mirai.message.code.internal.MiraiCodeParser
|
||||
import net.mamoe.mirai.message.data.*
|
||||
@ -18,7 +19,7 @@ import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class TestMiraiCode {
|
||||
class TestMiraiCode : AbstractTest() {
|
||||
@Test
|
||||
fun testDynamicMiraiCodeParser() {
|
||||
fun runTest(args: Int, code: String, parse: (args: Array<String>) -> Unit) {
|
||||
|
21
mirai-core/src/commonTest/kotlin/test/initPlatform.common.kt
Normal file
21
mirai-core/src/commonTest/kotlin/test/initPlatform.common.kt
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
internal expect fun initPlatform()
|
||||
|
||||
/**
|
||||
* All test classes should inherit from [AbstractTest]
|
||||
*/
|
||||
abstract class AbstractTest {
|
||||
init {
|
||||
initPlatform()
|
||||
}
|
||||
}
|
@ -10,11 +10,13 @@
|
||||
|
||||
package net.mamoe.mirai.internal
|
||||
|
||||
import net.mamoe.mirai.IMirai
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
internal abstract class AbstractTestWithMiraiImpl : MiraiImpl() {
|
||||
internal abstract class AbstractTestWithMiraiImpl : IMirai by MiraiImpl(), AbstractTest() {
|
||||
private val originalImpl = Mirai
|
||||
|
||||
@BeforeEach
|
||||
|
@ -13,7 +13,6 @@ package net.mamoe.mirai.internal.message.data
|
||||
import kotlinx.serialization.decodeFromHexString
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.internal.AbstractTestWithMiraiImpl
|
||||
import net.mamoe.mirai.internal.MiraiImpl
|
||||
import net.mamoe.mirai.internal.MockBot
|
||||
@ -32,7 +31,6 @@ import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.message.data.MessageChain.Companion.serializeToJsonString
|
||||
import net.mamoe.mirai.utils.PlatformLogger
|
||||
import net.mamoe.mirai.utils.autoHexToBytes
|
||||
import net.mamoe.mirai.utils.cast
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.assertEquals
|
||||
@ -275,7 +273,7 @@ internal class MessageRefineTest : AbstractTestWithMiraiImpl() {
|
||||
|
||||
@Test
|
||||
fun `test nested forward refinement`() = runBlockingUnit {
|
||||
val redefined = Mirai.cast<MiraiImpl>().run { testCases.nestedForward.toForwardMessageNodes(bot) }
|
||||
val redefined = MiraiImpl.run { testCases.nestedForward.toForwardMessageNodes(bot) }
|
||||
assertNodesEquals(
|
||||
listOf(
|
||||
ForwardMessage.Node(
|
||||
|
14
mirai-core/src/jvmTest/kotlin/test/initPlatform.kt
Normal file
14
mirai-core/src/jvmTest/kotlin/test/initPlatform.kt
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.internal.test
|
||||
|
||||
internal actual fun initPlatform() {
|
||||
// nothing to do
|
||||
}
|
Loading…
Reference in New Issue
Block a user