mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-17 15:05:47 +08:00
Auto finding testing points
This commit is contained in:
parent
894b8a9c2e
commit
bb489601b7
@ -9,16 +9,20 @@
|
|||||||
|
|
||||||
package net.mamoe.console.integrationtest
|
package net.mamoe.console.integrationtest
|
||||||
|
|
||||||
import net.mamoe.console.integrationtest.testpoints.DoNothingPoint
|
|
||||||
import net.mamoe.console.integrationtest.testpoints.MCITBSelfAssertions
|
import net.mamoe.console.integrationtest.testpoints.MCITBSelfAssertions
|
||||||
import net.mamoe.console.integrationtest.testpoints.PluginSharedLibraries
|
|
||||||
import net.mamoe.console.integrationtest.testpoints.plugin.PluginDataRenameToIdTest
|
|
||||||
import net.mamoe.console.integrationtest.testpoints.terminal.TestTerminalLogging
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.objectweb.asm.ClassReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
|
import kotlin.io.path.isDirectory
|
||||||
|
import kotlin.io.path.name
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.streams.toList
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
|
||||||
class MiraiConsoleIntegrationTestBootstrap {
|
class MiraiConsoleIntegrationTestBootstrap {
|
||||||
@ -32,22 +36,24 @@ class MiraiConsoleIntegrationTestBootstrap {
|
|||||||
val launcher = MiraiConsoleIntegrationTestLauncher()
|
val launcher = MiraiConsoleIntegrationTestLauncher()
|
||||||
launcher.workingDir = workingDir
|
launcher.workingDir = workingDir
|
||||||
launcher.plugins = readStringListFromEnv("IT_PLUGINS")
|
launcher.plugins = readStringListFromEnv("IT_PLUGINS")
|
||||||
launcher.points = listOf<Any>(
|
launcher.points = resolveTestPoints().also { points ->
|
||||||
DoNothingPoint,
|
// Avoid error in resolving points
|
||||||
MCITBSelfAssertions,
|
assertTrue { points.contains("net.mamoe.console.integrationtest.testpoints.MCITBSelfAssertions") }
|
||||||
PluginDataRenameToIdTest,
|
assertTrue { points.contains("net.mamoe.console.integrationtest.testpoints.DoNothingPoint") }
|
||||||
TestTerminalLogging,
|
assertTrue { points.contains("net.mamoe.console.integrationtest.testpoints.terminal.TestTerminalLogging") }
|
||||||
PluginSharedLibraries,
|
}.asSequence().map { v ->
|
||||||
).asSequence().map { v ->
|
|
||||||
when (v) {
|
when (v) {
|
||||||
is Class<*> -> v
|
is Class<*> -> v.name
|
||||||
is KClass<*> -> v.java
|
is KClass<*> -> v.java.name
|
||||||
else -> v.javaClass
|
is String -> v
|
||||||
|
else -> v.javaClass.name
|
||||||
}
|
}
|
||||||
}.map { it.name }.toMutableList()
|
}.map { it.replace('/', '.') }.toMutableList()
|
||||||
launcher.vmoptions = mutableListOf(
|
launcher.vmoptions = mutableListOf(
|
||||||
*ManagementFactory.getRuntimeMXBean().inputArguments.filterNot {
|
*ManagementFactory.getRuntimeMXBean().inputArguments.filterNot {
|
||||||
it.startsWith("-Djava.security.manager=")
|
it.startsWith("-Djava.security.manager=")
|
||||||
|
}.filterNot {
|
||||||
|
it.startsWith("-Xmx")
|
||||||
}.toTypedArray(),
|
}.toTypedArray(),
|
||||||
*System.getenv("IT_ARGS")!!.splitToSequence(",").map {
|
*System.getenv("IT_ARGS")!!.splitToSequence(",").map {
|
||||||
Base64.getDecoder().decode(it).decodeToString()
|
Base64.getDecoder().decode(it).decodeToString()
|
||||||
@ -55,4 +61,21 @@ class MiraiConsoleIntegrationTestBootstrap {
|
|||||||
)
|
)
|
||||||
launcher.launch()
|
launcher.launch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resolveTestPoints(): Collection<Any> {
|
||||||
|
val ptloc = MCITBSelfAssertions.javaClass.getResource(MCITBSelfAssertions.javaClass.simpleName + ".class")
|
||||||
|
ptloc ?: error("Failed to resolve test points")
|
||||||
|
val path = Paths.get(ptloc.toURI()).parent
|
||||||
|
return Files.walk(path)
|
||||||
|
.filter { !it.isDirectory() }
|
||||||
|
.filter { it.name.endsWith(".class") }
|
||||||
|
.map { pt ->
|
||||||
|
pt.inputStream().use {
|
||||||
|
ClassReader(it).className
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.map { it.replace('/', '.') }
|
||||||
|
.filter { AbstractTestPoint::class.java.isAssignableFrom(Class.forName(it)) }
|
||||||
|
.use { it.toList() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user