Rewrite tests for mirai-console-gradle with Kotlin

This commit is contained in:
Him188 2021-11-18 00:15:53 +00:00
parent 309a712102
commit 538dd66e72
6 changed files with 78 additions and 72 deletions

View File

@ -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()
}
}

View File

@ -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()
}
}

View File

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

View File

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

View File

@ -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()
}
}

View File

@ -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()
}
}