2
0

CoreDependencyResolutionTest.kt 5.4 KB

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