PluginDependOnErrorPlugin.kt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 org.junit.jupiter.api.Assertions.assertFalse
  19. import kotlin.test.fail
  20. @ConsoleJvmPluginFuncCallbackStatusExcept.OnEnable(ConsoleJvmPluginFuncCallbackStatus.FAILED)
  21. internal object PluginDependOnErrorPlugin : AbstractTestPointAsPlugin() {
  22. private var isOnEnabledExecuted: Boolean = false
  23. override fun newPluginDescription(): JvmPluginDescription {
  24. return JvmPluginDescription(
  25. id = "net.mamoe.testpoint.plugin-depend-on-error-plugin",
  26. version = "1.0.0",
  27. name = "PluginDependOnErrorPlugin",
  28. ) {
  29. dependsOn("net.mamoe.testpoint.plugin-with-exception-test")
  30. }
  31. }
  32. override fun beforeConsoleStartup() {
  33. isOnEnabledExecuted = false
  34. }
  35. override fun KotlinPlugin.onLoad0(storage: PluginComponentStorage) {
  36. }
  37. override fun KotlinPlugin.onEnable0() {
  38. // unreachable
  39. isOnEnabledExecuted = true
  40. fail("net.mamoe.testpoint.plugin-depend-on-error-plugin enabled")
  41. }
  42. override fun onConsoleStartSuccessfully() {
  43. assertFalse { isOnEnabledExecuted }
  44. assertFalse {
  45. PluginManager
  46. .plugins
  47. .first { it.id == "net.mamoe.testpoint.plugin-with-exception-test" }
  48. .isEnabled
  49. }
  50. assertFalse {
  51. PluginManager
  52. .plugins
  53. .first { it.id == "net.mamoe.testpoint.plugin-depend-on-error-plugin" }
  54. .isEnabled
  55. }
  56. }
  57. }