mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +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.asQQAndroidBot
|
||||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgTransmit
|
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgTransmit
|
||||||
import net.mamoe.mirai.message.data.*
|
import net.mamoe.mirai.message.data.*
|
||||||
import net.mamoe.mirai.utils.cast
|
|
||||||
import net.mamoe.mirai.utils.safeCast
|
import net.mamoe.mirai.utils.safeCast
|
||||||
|
|
||||||
// internal runtime value, not serializable
|
// internal runtime value, not serializable
|
||||||
@ -79,7 +78,7 @@ internal data class ForwardMessageInternal(
|
|||||||
brief = brief,
|
brief = brief,
|
||||||
source = source,
|
source = source,
|
||||||
summary = summary.trim(),
|
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
|
package net.mamoe.mirai.internal
|
||||||
|
|
||||||
import kotlinx.io.core.toByteArray
|
import kotlinx.io.core.toByteArray
|
||||||
|
import net.mamoe.mirai.internal.test.AbstractTest
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
internal class PlatformUtilsTest {
|
internal class PlatformUtilsTest : AbstractTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testZip() {
|
fun testZip() {
|
||||||
|
@ -12,13 +12,14 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import net.mamoe.mirai.internal.test.AbstractTest
|
||||||
import net.mamoe.mirai.internal.utils.ScheduledJob
|
import net.mamoe.mirai.internal.utils.ScheduledJob
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.time.seconds
|
import kotlin.time.seconds
|
||||||
|
|
||||||
internal class ScheduledJobTest {
|
internal class ScheduledJobTest : AbstractTest() {
|
||||||
@Test
|
@Test
|
||||||
fun testScheduledJob() {
|
fun testScheduledJob() {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.internal
|
package net.mamoe.mirai.internal
|
||||||
|
|
||||||
|
import net.mamoe.mirai.internal.test.AbstractTest
|
||||||
import net.mamoe.mirai.utils.hexToBytes
|
import net.mamoe.mirai.utils.hexToBytes
|
||||||
import net.mamoe.mirai.utils.toByteArray
|
import net.mamoe.mirai.utils.toByteArray
|
||||||
import net.mamoe.mirai.utils.toUHexString
|
import net.mamoe.mirai.utils.toUHexString
|
||||||
@ -16,7 +17,7 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class TypeConversionTest {
|
internal class TypeConversionTest : AbstractTest() {
|
||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
@Test
|
@Test
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.internal.utils
|
package net.mamoe.mirai.internal.utils
|
||||||
|
|
||||||
|
import net.mamoe.mirai.internal.test.AbstractTest
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
internal class FileSystemTest {
|
internal class FileSystemTest : AbstractTest() {
|
||||||
|
|
||||||
private val fs = FileSystem
|
private val fs = FileSystem
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.internal.message.code
|
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.MiraiCode.deserializeMiraiCode
|
||||||
import net.mamoe.mirai.message.code.internal.MiraiCodeParser
|
import net.mamoe.mirai.message.code.internal.MiraiCodeParser
|
||||||
import net.mamoe.mirai.message.data.*
|
import net.mamoe.mirai.message.data.*
|
||||||
@ -18,7 +19,7 @@ import org.junit.jupiter.api.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class TestMiraiCode {
|
class TestMiraiCode : AbstractTest() {
|
||||||
@Test
|
@Test
|
||||||
fun testDynamicMiraiCodeParser() {
|
fun testDynamicMiraiCodeParser() {
|
||||||
fun runTest(args: Int, code: String, parse: (args: Array<String>) -> Unit) {
|
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
|
package net.mamoe.mirai.internal
|
||||||
|
|
||||||
|
import net.mamoe.mirai.IMirai
|
||||||
import net.mamoe.mirai.Mirai
|
import net.mamoe.mirai.Mirai
|
||||||
|
import net.mamoe.mirai.internal.test.AbstractTest
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
|
||||||
internal abstract class AbstractTestWithMiraiImpl : MiraiImpl() {
|
internal abstract class AbstractTestWithMiraiImpl : IMirai by MiraiImpl(), AbstractTest() {
|
||||||
private val originalImpl = Mirai
|
private val originalImpl = Mirai
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -13,7 +13,6 @@ package net.mamoe.mirai.internal.message.data
|
|||||||
import kotlinx.serialization.decodeFromHexString
|
import kotlinx.serialization.decodeFromHexString
|
||||||
import kotlinx.serialization.protobuf.ProtoBuf
|
import kotlinx.serialization.protobuf.ProtoBuf
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.Mirai
|
|
||||||
import net.mamoe.mirai.internal.AbstractTestWithMiraiImpl
|
import net.mamoe.mirai.internal.AbstractTestWithMiraiImpl
|
||||||
import net.mamoe.mirai.internal.MiraiImpl
|
import net.mamoe.mirai.internal.MiraiImpl
|
||||||
import net.mamoe.mirai.internal.MockBot
|
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.message.data.MessageChain.Companion.serializeToJsonString
|
||||||
import net.mamoe.mirai.utils.PlatformLogger
|
import net.mamoe.mirai.utils.PlatformLogger
|
||||||
import net.mamoe.mirai.utils.autoHexToBytes
|
import net.mamoe.mirai.utils.autoHexToBytes
|
||||||
import net.mamoe.mirai.utils.cast
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@ -275,7 +273,7 @@ internal class MessageRefineTest : AbstractTestWithMiraiImpl() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test nested forward refinement`() = runBlockingUnit {
|
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(
|
assertNodesEquals(
|
||||||
listOf(
|
listOf(
|
||||||
ForwardMessage.Node(
|
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