From 538dd66e7263311def3749063a5696baaff8ac39 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 18 Nov 2021 00:15:53 +0000 Subject: [PATCH] Rewrite tests for mirai-console-gradle with Kotlin --- .../console/gradle/TestBuildPlugin.groovy | 22 ------- .../console/gradle/TestPluginApply.groovy | 22 ------- .../AbstractTest.kt} | 59 ++++++++++--------- ...inTransitiveDependenciesIntegrationTest.kt | 2 +- .../src/integTest/kotlin/TestBuildPlugin.kt | 23 ++++++++ .../src/integTest/kotlin/TestPluginApply.kt | 22 +++++++ 6 files changed, 78 insertions(+), 72 deletions(-) delete mode 100644 tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestBuildPlugin.groovy delete mode 100644 tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy rename tools/gradle-plugin/src/integTest/{groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy => kotlin/AbstractTest.kt} (52%) create mode 100644 tools/gradle-plugin/src/integTest/kotlin/TestBuildPlugin.kt create mode 100644 tools/gradle-plugin/src/integTest/kotlin/TestPluginApply.kt diff --git a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestBuildPlugin.groovy b/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestBuildPlugin.groovy deleted file mode 100644 index 8d4a2366f..000000000 --- a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestBuildPlugin.groovy +++ /dev/null @@ -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() - } -} diff --git a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy b/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy deleted file mode 100644 index 85b39def1..000000000 --- a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy +++ /dev/null @@ -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() - } -} diff --git a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy b/tools/gradle-plugin/src/integTest/kotlin/AbstractTest.kt similarity index 52% rename from tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy rename to tools/gradle-plugin/src/integTest/kotlin/AbstractTest.kt index 64a93da67..dae21a33b 100644 --- a/tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy +++ b/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 - GradleRunner gradleRunner() { + val tempDir: File get() = tempDirField!! + + lateinit var buildFile: File + lateinit var settingsFile: File + lateinit var propertiesFile: File + + + 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() } -} +} \ No newline at end of file diff --git a/tools/gradle-plugin/src/integTest/kotlin/KotlinTransitiveDependenciesIntegrationTest.kt b/tools/gradle-plugin/src/integTest/kotlin/KotlinTransitiveDependenciesIntegrationTest.kt index 13eade941..eb17c7f1a 100644 --- a/tools/gradle-plugin/src/integTest/kotlin/KotlinTransitiveDependenciesIntegrationTest.kt +++ b/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)) diff --git a/tools/gradle-plugin/src/integTest/kotlin/TestBuildPlugin.kt b/tools/gradle-plugin/src/integTest/kotlin/TestBuildPlugin.kt new file mode 100644 index 000000000..7d0b392b2 --- /dev/null +++ b/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() + } + +} \ No newline at end of file diff --git a/tools/gradle-plugin/src/integTest/kotlin/TestPluginApply.kt b/tools/gradle-plugin/src/integTest/kotlin/TestPluginApply.kt new file mode 100644 index 000000000..6c9e41cb5 --- /dev/null +++ b/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() + } +} \ No newline at end of file