Forráskód Böngészése

Rewrite tests for mirai-console-gradle with Kotlin

Him188 4 éve
szülő
commit
538dd66e72

+ 0 - 22
tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestBuildPlugin.groovy

@@ -1,22 +0,0 @@
-/*
- * Copyright 2019-2021 Mamoe Technologies and contributors.
- *
- *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
- *
- *  https://github.com/mamoe/mirai/blob/master/LICENSE
- */
-
-package net.mamoe.mirai.console.gradle
-
-import org.junit.jupiter.api.Test
-
-class TestBuildPlugin extends AbstractTest {
-
-    @Test
-    void "can build plugin"() {
-        gradleRunner()
-                .withArguments("buildPlugin", "--stacktrace")
-                .build()
-    }
-}

+ 0 - 22
tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy

@@ -1,22 +0,0 @@
-/*
- * Copyright 2019-2021 Mamoe Technologies and contributors.
- *
- *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
- *
- *  https://github.com/mamoe/mirai/blob/master/LICENSE
- */
-
-package net.mamoe.mirai.console.gradle
-
-import org.junit.jupiter.api.Test
-
-class TestPluginApply extends AbstractTest {
-
-    @Test
-    void "can apply plugin"() {
-        gradleRunner()
-                .withArguments("clean", "--stacktrace")
-                .build()
-    }
-}

+ 32 - 27
tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy → tools/gradle-plugin/src/integTest/kotlin/AbstractTest.kt

@@ -1,44 +1,50 @@
 /*
  * Copyright 2019-2021 Mamoe Technologies and contributors.
  *
- *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
 
 package net.mamoe.mirai.console.gradle
 
-
 import org.gradle.testkit.runner.GradleRunner
 import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
-import org.junit.jupiter.api.AfterEach
 import org.junit.jupiter.api.BeforeEach
 import org.junit.jupiter.api.io.TempDir
+import java.io.File
 
 abstract class AbstractTest {
+    @JvmField
     @TempDir
-    public File tempDir
-    File buildFile
-    File settingsFile
-    File propertiesFile
+    var tempDirField: File? = null
+
+    val tempDir: File get() = tempDirField!!
+
+    lateinit var buildFile: File
+    lateinit var settingsFile: File
+    lateinit var propertiesFile: File
 
-    GradleRunner gradleRunner() {
+
+    fun gradleRunner(): GradleRunner {
         println(PluginUnderTestMetadataReading.readImplementationClasspath())
-        GradleRunner.create()
-                .withProjectDir(tempDir)
-                .withPluginClasspath()
-                .forwardOutput()
-                .withEnvironment(System.getenv())
+        return GradleRunner.create()
+            .withProjectDir(tempDir)
+            .withPluginClasspath()
+            .withGradleVersion("7.2")
+            .forwardOutput()
+            .withEnvironment(System.getenv())
     }
 
     @BeforeEach
-    void setup() {
-        println('Temp path is ' + tempDir.absolutePath)
+    fun setup() {
+        println("Temp path is " + tempDir.absolutePath)
 
-        settingsFile = new File(tempDir, "settings.gradle")
+        settingsFile = File(tempDir, "settings.gradle")
         settingsFile.delete()
-        settingsFile << """
+        settingsFile.writeText(
+            """
             pluginManagement {
                 repositories {
                     gradlePluginPortal()
@@ -46,12 +52,14 @@ abstract class AbstractTest {
                 }
             }
         """
+        )
 
-        buildFile = new File(tempDir, "build.gradle")
+        buildFile = File(tempDir, "build.gradle")
         buildFile.delete()
-        buildFile << """
+        buildFile.writeText(
+            """
             plugins {
-                id("org.jetbrains.kotlin.jvm") version "1.5.10"
+                id("org.jetbrains.kotlin.jvm") version "1.6.0"
                 id("net.mamoe.mirai-console")
             }
             
@@ -59,6 +67,7 @@ abstract class AbstractTest {
                 mavenCentral()
             }
         """
+        )
 
 
 //        buildFile = new File(tempDir, "build.gradle.kts")
@@ -72,10 +81,6 @@ abstract class AbstractTest {
 //                mavenCentral()
 //            }
 //        """
-    }
 
-    @AfterEach
-    void cleanup() {
-        tempDir.deleteDir()
     }
-}
+}

+ 1 - 1
tools/gradle-plugin/src/integTest/kotlin/KotlinTransitiveDependenciesIntegrationTest.kt

@@ -38,7 +38,7 @@ class KotlinTransitiveDependenciesIntegrationTest {
 
         GradleRunner.create()
             .withProjectDir(dir)
-            .withGradleVersion("6.8.3")
+            .withGradleVersion("7.2")
             .withPluginClasspath()
             .forwardStdOutput(PrintWriter(stdout))
             .forwardStdError(PrintWriter(stderr))

+ 23 - 0
tools/gradle-plugin/src/integTest/kotlin/TestBuildPlugin.kt

@@ -0,0 +1,23 @@
+/*
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
+ *
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
+ */
+
+package net.mamoe.mirai.console.gradle
+
+import org.junit.jupiter.api.Test
+
+class TestBuildPlugin : AbstractTest() {
+
+    @Test
+    fun `can build plugin`() {
+        gradleRunner()
+            .withArguments("buildPlugin", "--stacktrace")
+            .build()
+    }
+
+}

+ 22 - 0
tools/gradle-plugin/src/integTest/kotlin/TestPluginApply.kt

@@ -0,0 +1,22 @@
+/*
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
+ *
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
+ */
+
+package net.mamoe.mirai.console.gradle
+
+import org.junit.jupiter.api.Test
+
+class TestPluginApply : AbstractTest() {
+
+    @Test
+    fun `can apply plugin`() {
+        gradleRunner()
+            .withArguments("clean", "--stacktrace")
+            .build()
+    }
+}