Introduce base class for tests AbstractTest

This commit is contained in:
Him188 2021-04-20 12:47:27 +08:00
parent 63ae9b276f
commit 5dcccd1402
12 changed files with 83 additions and 11 deletions

View 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

View File

@ -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)
}
}

View File

@ -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) }
)
}

View File

@ -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() {

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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) {

View 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()
}
}

View File

@ -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

View File

@ -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(

View 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
}