Fix exception catch

This commit is contained in:
Karlatemp 2021-12-19 00:45:13 +08:00
parent 8d6b4b4970
commit dda61f5a5d
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
3 changed files with 42 additions and 3 deletions

View File

@ -46,15 +46,30 @@ public abstract class AbstractTestPointAsPlugin : AbstractTestPoint() {
) : this(impl.kotlin.objectInstance ?: impl.newInstance())
override fun onDisable() {
impl.apply { onDisable0() }
try {
impl.apply { onDisable0() }
} catch (e: Throwable) {
IntegrationTestBootstrapContext.failures.add(impl.javaClass)
throw e
}
}
override fun onEnable() {
impl.apply { onEnable0() }
try {
impl.apply { onEnable0() }
} catch (e: Throwable) {
IntegrationTestBootstrapContext.failures.add(impl.javaClass)
throw e
}
}
override fun PluginComponentStorage.onLoad() {
impl.apply { onLoad0(this@onLoad) }
try {
impl.apply { onLoad0(this@onLoad) }
} catch (e: Throwable) {
IntegrationTestBootstrapContext.failures.add(impl.javaClass)
throw e
}
}
}

View File

@ -25,10 +25,15 @@ import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import java.io.File
import java.io.FileOutputStream
import java.util.concurrent.ConcurrentLinkedDeque
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import kotlin.system.exitProcess
internal object IntegrationTestBootstrapContext {
val failures = ConcurrentLinkedDeque<Class<*>>()
}
/**
* 入口点为 /test/MiraiConsoleIntegrationTestBootstrap.kt 并非此函数(文件),
* 不要直接执行此函数
@ -70,6 +75,14 @@ internal fun main() {
if (!MiraiConsole.isActive) {
error("Failed to start console")
}
if (IntegrationTestBootstrapContext.failures.isNotEmpty()) {
val logger = MiraiConsole.mainLogger
logger.error("Failed tests: ")
IntegrationTestBootstrapContext.failures.toSet().forEach {
logger.error(" `- $it")
}
error("Failed tests: ${IntegrationTestBootstrapContext.failures.toSet()}")
}
// I/main: mirai-console started successfully.

View File

@ -9,6 +9,9 @@
package net.mamoe.console.integrationtest
import org.junit.jupiter.api.fail
import java.io.File
internal fun readStringListFromEnv(key: String): MutableList<String> {
val size = System.getenv(key)!!.toInt()
val rsp = mutableListOf<String>()
@ -24,3 +27,11 @@ internal fun saveStringListToEnv(key: String, value: Collection<String>, env: Mu
env["${key}_$index"] = v
}
}
// region assertion kits
public fun File.assertNotExists() {
if (exists()) {
fail { "Except ${this.absolutePath} not exists but this file exists in disk" }
}
}
// endregion