PluginWithExceptionTest.kt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. package net.mamoe.console.integrationtest.testpoints.plugin
  10. import net.mamoe.console.integrationtest.AbstractTestPointAsPlugin
  11. import net.mamoe.mirai.console.extension.PluginComponentStorage
  12. import net.mamoe.mirai.console.internal.plugin.ConsoleJvmPluginFuncCallbackStatus
  13. import net.mamoe.mirai.console.internal.plugin.ConsoleJvmPluginFuncCallbackStatusExcept
  14. import net.mamoe.mirai.console.plugin.PluginManager
  15. import net.mamoe.mirai.console.plugin.id
  16. import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
  17. import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  18. import net.mamoe.mirai.utils.debug
  19. import org.junit.jupiter.api.Assertions.assertFalse
  20. import kotlin.test.assertEquals
  21. import kotlin.test.assertIs
  22. @ConsoleJvmPluginFuncCallbackStatusExcept.OnEnable(ConsoleJvmPluginFuncCallbackStatus.FAILED)
  23. internal object PluginWithExceptionTest : AbstractTestPointAsPlugin() {
  24. override fun newPluginDescription(): JvmPluginDescription {
  25. return JvmPluginDescription(
  26. id = "net.mamoe.testpoint.plugin-with-exception-test",
  27. version = "1.0.0",
  28. name = "PluginWithExceptionTest",
  29. )
  30. }
  31. override fun exceptionHandler(exception: Throwable, step: JvmPluginExecutionStep, instance: KotlinPlugin) {
  32. instance.logger.debug { "PluginWithExceptionTestExceptionTest" }
  33. assertIs<Exception>(exception)
  34. assertEquals("PluginWithExceptionTestExceptionTest", exception.message)
  35. }
  36. override fun KotlinPlugin.onLoad0(storage: PluginComponentStorage) {
  37. }
  38. override fun KotlinPlugin.onEnable0() {
  39. throw Exception("PluginWithExceptionTestExceptionTest")
  40. }
  41. override fun onConsoleStartSuccessfully() {
  42. assertFalse {
  43. PluginManager
  44. .plugins
  45. .first { it.id == "net.mamoe.testpoint.plugin-with-exception-test" }
  46. .isEnabled
  47. }
  48. }
  49. }