CoreShadowRelocationTest.kt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2019-2022 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.mirai.deps.test
  10. import org.junit.jupiter.api.Test
  11. import org.junit.jupiter.api.condition.EnabledIf
  12. class CoreShadowRelocationTest : AbstractTest() {
  13. @Test
  14. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  15. fun `test OkHttp filtered out`() {
  16. testDir.resolve("test.kt").writeText(
  17. """
  18. package test
  19. import org.junit.jupiter.api.*
  20. class MyTest {
  21. @Test
  22. fun `test base dependency`() {
  23. assertThrows<ClassNotFoundException> {
  24. Class.forName("io.ktor.client.engine.okhttp.OkHttp")
  25. }
  26. }
  27. @Test
  28. fun `test transitive dependency`() {
  29. assertThrows<ClassNotFoundException> {
  30. Class.forName("okhttp3.OkHttpClient")
  31. }
  32. }
  33. }
  34. """.trimIndent()
  35. )
  36. buildFile.appendText(
  37. """
  38. dependencies {
  39. implementation("net.mamoe:mirai-core:$miraiLocalVersion")
  40. }
  41. """.trimIndent()
  42. )
  43. runGradle("check")
  44. }
  45. // https://github.com/mamoe/mirai/issues/2291
  46. @Test
  47. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  48. fun `no duplicated class when dependency shared across modules`() {
  49. testDir.resolve("test.kt").writeText(
  50. """
  51. package test
  52. import org.junit.jupiter.api.*
  53. class MyTest {
  54. @Test
  55. fun `test base dependency`() {
  56. assertThrows<ClassNotFoundException> {
  57. Class.forName("net.mamoe.mirai.internal.deps.io.ktor.utils.io.ByteBufferChannel") // should only present in mirai-core-utils
  58. }
  59. }
  60. }
  61. """.trimIndent()
  62. )
  63. buildFile.appendText(
  64. """
  65. dependencies {
  66. implementation("net.mamoe:mirai-core:$miraiLocalVersion") {
  67. exclude("net.mamoe", "mirai-core-api")
  68. exclude("net.mamoe", "mirai-core-utils")
  69. }
  70. }
  71. """.trimIndent()
  72. )
  73. runGradle("check")
  74. }
  75. @Test
  76. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  77. fun `relocated ktor presents in mirai-core-utils`() {
  78. testDir.resolve("test.kt").writeText(
  79. """
  80. package test
  81. import org.junit.jupiter.api.*
  82. class MyTest {
  83. @Test
  84. fun `test base dependency`() {
  85. Class.forName("net.mamoe.mirai.internal.deps.io.ktor.utils.io.ByteBufferChannel")
  86. }
  87. }
  88. """.trimIndent()
  89. )
  90. buildFile.appendText(
  91. """
  92. dependencies {
  93. implementation("net.mamoe:mirai-core-utils:$miraiLocalVersion")
  94. }
  95. """.trimIndent()
  96. )
  97. runGradle("check")
  98. }
  99. @Test
  100. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  101. fun `relocated ktor presents transitively in mirai-core`() {
  102. testDir.resolve("test.kt").writeText(
  103. """
  104. package test
  105. import org.junit.jupiter.api.*
  106. class MyTest {
  107. @Test
  108. fun `test base dependency`() {
  109. Class.forName("net.mamoe.mirai.internal.deps.io.ktor.utils.io.ByteBufferChannel")
  110. }
  111. }
  112. """.trimIndent()
  113. )
  114. buildFile.appendText(
  115. """
  116. dependencies {
  117. implementation("net.mamoe:mirai-core:$miraiLocalVersion")
  118. }
  119. """.trimIndent()
  120. )
  121. runGradle("check")
  122. }
  123. }