2
0

CoreDependencyResolutionTest.kt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 CoreDependencyResolutionTest : AbstractTest() {
  13. private val testCode = """
  14. package test
  15. @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "EXPERIMENTAL_API_USAGE")
  16. fun main () {
  17. println(net.mamoe.mirai.BotFactory)
  18. println(net.mamoe.mirai.Mirai)
  19. println(net.mamoe.mirai.internal.testHttpClient())
  20. }
  21. """.trimIndent()
  22. @Test
  23. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  24. fun `test resolve JVM root from Kotlin JVM`() {
  25. mainSrcDir.resolve("main.kt").writeText(testCode)
  26. buildFile.writeText(
  27. """
  28. plugins {
  29. id("org.jetbrains.kotlin.jvm") version "$kotlinVersion"
  30. }
  31. repositories {
  32. mavenCentral()
  33. mavenLocal()
  34. }
  35. dependencies {
  36. implementation("net.mamoe:mirai-core:$miraiLocalVersion")
  37. }
  38. kotlin.sourceSets.all {
  39. languageSettings.optIn("net.mamoe.mirai.utils.TestOnly")
  40. }
  41. """.trimIndent()
  42. )
  43. runGradle("build")
  44. }
  45. @Test
  46. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  47. fun `test resolve JVM from Kotlin JVM`() {
  48. mainSrcDir.resolve("main.kt").writeText(testCode)
  49. buildFile.writeText(
  50. """
  51. plugins {
  52. id("org.jetbrains.kotlin.jvm") version "$kotlinVersion"
  53. }
  54. repositories {
  55. mavenCentral()
  56. mavenLocal()
  57. }
  58. dependencies {
  59. implementation("net.mamoe:mirai-core-jvm:$miraiLocalVersion")
  60. }
  61. kotlin.sourceSets.all {
  62. languageSettings.optIn("net.mamoe.mirai.utils.TestOnly")
  63. }
  64. """.trimIndent()
  65. )
  66. runGradle("build")
  67. }
  68. @Test
  69. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  70. fun `test resolve JVM and Native from common`() {
  71. commonMainSrcDir.resolve("main.kt").writeText(testCode)
  72. buildFile.writeText(
  73. """
  74. |import org.apache.tools.ant.taskdefs.condition.Os
  75. |import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
  76. |
  77. |plugins {
  78. | id("org.jetbrains.kotlin.multiplatform") version "$kotlinVersion"
  79. |}
  80. |repositories {
  81. | mavenCentral()
  82. | mavenLocal()
  83. |}
  84. |kotlin {
  85. | targets {
  86. | jvm()
  87. | val nativeMainSets = mutableListOf<KotlinSourceSet>()
  88. | val nativeTestSets = mutableListOf<KotlinSourceSet>()
  89. | when {
  90. | Os.isFamily(Os.FAMILY_MAC) -> if (Os.isArch("aarch64")) macosArm64("native") else macosX64("native")
  91. | Os.isFamily(Os.FAMILY_WINDOWS) -> mingwX64("native")
  92. | else -> linuxX64("native")
  93. | }
  94. | }
  95. | sourceSets {
  96. | val commonMain by getting {
  97. | dependencies {
  98. | api("net.mamoe:mirai-core:$miraiLocalVersion")
  99. | }
  100. | }
  101. | }
  102. |}
  103. |kotlin.sourceSets.all {
  104. | languageSettings.optIn("net.mamoe.mirai.utils.TestOnly")
  105. |}
  106. """.trimMargin()
  107. )
  108. runGradle("build")
  109. }
  110. @Test
  111. @EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
  112. fun `test resolve Native from common`() {
  113. nativeMainSrcDir.resolve("main.kt").writeText(testCode)
  114. buildFile.writeText(
  115. """
  116. |import org.apache.tools.ant.taskdefs.condition.Os
  117. |import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
  118. |
  119. |plugins {
  120. | id("org.jetbrains.kotlin.multiplatform") version "$kotlinVersion"
  121. |}
  122. |repositories {
  123. | mavenCentral()
  124. | mavenLocal()
  125. |}
  126. |kotlin {
  127. | targets {
  128. | jvm()
  129. | val nativeMainSets = mutableListOf<KotlinSourceSet>()
  130. | val nativeTestSets = mutableListOf<KotlinSourceSet>()
  131. | when {
  132. | Os.isFamily(Os.FAMILY_MAC) -> if (Os.isArch("aarch64")) macosArm64("native") else macosX64("native")
  133. | Os.isFamily(Os.FAMILY_WINDOWS) -> mingwX64("native")
  134. | else -> linuxX64("native")
  135. | }
  136. | }
  137. | sourceSets {
  138. | val nativeMain by getting {
  139. | dependencies {
  140. | api("net.mamoe:mirai-core:$miraiLocalVersion")
  141. | }
  142. | }
  143. | }
  144. |}
  145. |kotlin.sourceSets.all {
  146. | languageSettings.optIn("net.mamoe.mirai.utils.TestOnly")
  147. |}
  148. """.trimMargin()
  149. )
  150. runGradle("build")
  151. }
  152. }