Bläddra i källkod

Rearrange and include plugin tests

Him188 4 år sedan
förälder
incheckning
038123f202
21 ändrade filer med 180 tillägg och 91 borttagningar
  1. 1 1
      backend/mirai-console/sandbox-tester/auto-end/build.gradle.kts
  2. 19 0
      backend/mirai-console/sandbox-tester/auto-end/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  3. 3 1
      backend/mirai-console/sandbox-tester/auto-end/src/Main.kt
  4. 21 0
      backend/mirai-console/sandbox-tester/build.gradle.kts
  5. 1 1
      backend/mirai-console/sandbox-tester/p1/build.gradle.kts
  6. 10 0
      backend/mirai-console/sandbox-tester/p1/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  7. 0 0
      backend/mirai-console/sandbox-tester/p1/src/p/Shadowed.kt
  8. 1 1
      backend/mirai-console/sandbox-tester/p1/src/p/s1/P.kt
  9. 1 1
      backend/mirai-console/sandbox-tester/p2/build.gradle.kts
  10. 10 0
      backend/mirai-console/sandbox-tester/p2/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  11. 0 0
      backend/mirai-console/sandbox-tester/p2/src/p/Shadowed.kt
  12. 1 1
      backend/mirai-console/sandbox-tester/p2/src/p/s2/P.kt
  13. 0 79
      backend/mirai-console/tester-common/build.gradle.kts
  14. 30 0
      backend/mirai-console/tester-plugin-common/build.gradle.kts
  15. 1 1
      backend/mirai-console/tester-plugin-common/src/BaseTestingPlugin.kt
  16. 0 1
      backend/mirai-console/tester-plugins/AutoEnd/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  17. 0 1
      backend/mirai-console/tester-plugins/p1/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  18. 0 1
      backend/mirai-console/tester-plugins/p2/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
  19. 73 0
      buildSrc/src/main/kotlin/PluginTestRunner.kt
  20. 6 0
      settings.gradle.kts
  21. 2 2
      tools/gradle-plugin/src/main/kotlin/VersionConstants.kt

+ 1 - 1
backend/mirai-console/tester-plugins/p2/build.gradle.kts → backend/mirai-console/sandbox-tester/auto-end/build.gradle.kts

@@ -17,5 +17,5 @@ kotlin {
 }
 
 dependencies {
-    implementation(project(":mirai-console-plugin-tester-common"))
+    implementation(project(":mirai-console:tester-plugin-common"))
 }

+ 19 - 0
backend/mirai-console/sandbox-tester/auto-end/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -0,0 +1,19 @@
+#
+# 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
+#
+
+#
+# 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
+#
+
+autoend.Main

+ 3 - 1
backend/mirai-console/tester-plugins/AutoEnd/src/Main.kt → backend/mirai-console/sandbox-tester/auto-end/src/Main.kt

@@ -12,11 +12,13 @@ package autoend
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import net.mamoe.mirai.console.command.ConsoleCommandSender
+import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
 import net.mamoe.mirai.console.command.executeCommand
 import net.mamoe.mirai.console.extension.PluginComponentStorage
-import net.mamoe.mirai.console.testing.BaseTestingPlugin
+import p.BaseTestingPlugin
 
 public object Main : BaseTestingPlugin("AutoEnd") {
+    @OptIn(ExperimentalCommandDescriptors::class)
     override fun PluginComponentStorage.onLoad() {
         contributePostStartupExtension {
             launch {

+ 21 - 0
backend/mirai-console/sandbox-tester/build.gradle.kts

@@ -0,0 +1,21 @@
+/*
+ * 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
+ */
+
+plugins {
+    kotlin("jvm")
+    kotlin("plugin.serialization")
+}
+
+kotlin {
+    explicitApiWarning()
+}
+
+afterEvaluate {
+    PluginTestRunner.registerPluginTestRunnerTask(project, "p1", "p2", "auto-end")
+}

+ 1 - 1
backend/mirai-console/tester-plugins/AutoEnd/build.gradle.kts → backend/mirai-console/sandbox-tester/p1/build.gradle.kts

@@ -17,5 +17,5 @@ kotlin {
 }
 
 dependencies {
-    implementation(project(":mirai-console-plugin-tester-common"))
+    implementation(project(":mirai-console:tester-plugin-common"))
 }

+ 10 - 0
backend/mirai-console/sandbox-tester/p1/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -0,0 +1,10 @@
+#
+# 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
+#
+
+p.s1.P

+ 0 - 0
backend/mirai-console/tester-plugins/p1/src/p/Shadowed.kt → backend/mirai-console/sandbox-tester/p1/src/p/Shadowed.kt


+ 1 - 1
backend/mirai-console/tester-plugins/p1/src/p/s1/P.kt → backend/mirai-console/sandbox-tester/p1/src/p/s1/P.kt

@@ -9,7 +9,7 @@
 
 package p.s1
 
-import net.mamoe.mirai.console.testing.BaseTestingPlugin
+import p.BaseTestingPlugin
 import p.Shadowed
 import kotlin.test.assertEquals
 

+ 1 - 1
backend/mirai-console/tester-plugins/p1/build.gradle.kts → backend/mirai-console/sandbox-tester/p2/build.gradle.kts

@@ -17,5 +17,5 @@ kotlin {
 }
 
 dependencies {
-    implementation(project(":mirai-console-plugin-tester-common"))
+    implementation(project(":mirai-console:tester-plugin-common"))
 }

+ 10 - 0
backend/mirai-console/sandbox-tester/p2/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -0,0 +1,10 @@
+#
+# 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
+#
+
+p.s2.P

+ 0 - 0
backend/mirai-console/tester-plugins/p2/src/p/Shadowed.kt → backend/mirai-console/sandbox-tester/p2/src/p/Shadowed.kt


+ 1 - 1
backend/mirai-console/tester-plugins/p2/src/p/s2/P.kt → backend/mirai-console/sandbox-tester/p2/src/p/s2/P.kt

@@ -9,7 +9,7 @@
 
 package p.s2
 
-import net.mamoe.mirai.console.testing.BaseTestingPlugin
+import p.BaseTestingPlugin
 import p.Shadowed
 import kotlin.test.assertEquals
 

+ 0 - 79
backend/mirai-console/tester-common/build.gradle.kts

@@ -1,79 +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/dev/LICENSE
- */
-
-import java.time.Duration
-import java.time.Instant
-
-plugins {
-    kotlin("jvm")
-    kotlin("plugin.serialization")
-}
-
-kotlin {
-    explicitApiWarning()
-}
-
-dependencies {
-    api(project(":mirai-console"))
-    api(`mirai-core-api`)
-    api(`mirai-core-utils`)
-    api(`kotlin-stdlib-jdk8`)
-    api(`kotlinx-coroutines-core`)
-    api(`kotlin-reflect`)
-    api(`jetbrains-annotations`)
-    api(`caller-finder`)
-    api(kotlin("test-junit5"))
-    api("org.junit.jupiter:junit-jupiter-api:${Versions.junit}")
-}
-
-val testers = mutableListOf<Project>()
-val currentProject = project
-
-tasks.register("runTerminalDaemon", JavaExec::class.java) {
-
-    val terminal = project(":mirai-console-terminal")
-    val console = project(":mirai-console")
-    classpath = terminal.configurations["testRuntimeClasspath"]
-    classpath += console.configurations["testRuntimeClasspath"]
-    classpath += console.sourceSets.getByName("main").output // console
-    classpath += console.sourceSets.getByName("test").output // console
-    classpath += terminal.sourceSets.getByName("main").output
-    classpath += currentProject.tasks.getByName("jar").outputs.files
-    mainClass.set("net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader")
-
-    val sandbox = project.buildDir.resolve("runTerminalDaemon")
-    this.workingDir = sandbox
-
-    doFirst {
-        sandbox.mkdirs()
-        val plugins = sandbox.resolve("plugins")
-        plugins.deleteRecursively()
-        plugins.mkdirs()
-        testers.forEach { testerProject ->
-            val jarTask = testerProject.tasks.getByName("jar")
-            jarTask.outputs.files.forEach { it.copyTo(plugins.resolve(it.name), true) }
-        }
-    }
-    timeout.set(Duration.ofMinutes(5))
-}
-
-tasks.getByName("check").dependsOn("runTerminalDaemon")
-
-rootProject.allprojects {
-    val proj = this@allprojects
-    if (proj.name.removePrefix(":").startsWith("mirai-console-plugin-tester-")) {
-        if (proj != currentProject) {
-            testers.add(proj)
-            currentProject.tasks.named("runTerminalDaemon") {
-                dependsOn(":" + proj.name.removePrefix(":") + ":jar")
-            }
-        }
-    }
-}
-

+ 30 - 0
backend/mirai-console/tester-plugin-common/build.gradle.kts

@@ -0,0 +1,30 @@
+/*
+ * 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
+ */
+
+plugins {
+    kotlin("jvm")
+    kotlin("plugin.serialization")
+}
+
+kotlin {
+    explicitApiWarning()
+}
+
+dependencies {
+    api(project(":mirai-console"))
+    api(`mirai-core-api`)
+    api(`mirai-core-utils`)
+    api(`kotlin-stdlib-jdk8`)
+    api(`kotlinx-coroutines-core`)
+    api(`kotlin-reflect`)
+    api(`jetbrains-annotations`)
+    api(`caller-finder`)
+    api(kotlin("test-junit5"))
+    api("org.junit.jupiter:junit-jupiter-api:${Versions.junit}")
+}

+ 1 - 1
backend/mirai-console/tester-common/src/testing/BaseTestingPlugin.kt → backend/mirai-console/tester-plugin-common/src/BaseTestingPlugin.kt

@@ -7,7 +7,7 @@
  *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
-package net.mamoe.mirai.console.testing
+package p
 
 import io.github.karlatemp.caller.CallerFinder
 import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription

+ 0 - 1
backend/mirai-console/tester-plugins/AutoEnd/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -1 +0,0 @@
-autoend.Main

+ 0 - 1
backend/mirai-console/tester-plugins/p1/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -1 +0,0 @@
-p.s1.P

+ 0 - 1
backend/mirai-console/tester-plugins/p2/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.KotlinPlugin

@@ -1 +0,0 @@
-p.s2.P

+ 73 - 0
buildSrc/src/main/kotlin/PluginTestRunner.kt

@@ -0,0 +1,73 @@
+/*
+ * 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
+ */
+
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.get
+import java.time.Duration
+
+/*
+ * 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
+ */
+
+object PluginTestRunner {
+    fun registerPluginTestRunnerTask(
+        project: Project,
+        vararg pluginProjectPaths: String
+    ) = project.registerPluginTestRunnerTask0(*pluginProjectPaths)
+
+    private fun Project.registerPluginTestRunnerTask0(
+        vararg pluginProjectPaths: String
+    ) {
+        val pluginProjects = pluginProjectPaths.map { project(it) }
+
+        val currentProject = project
+
+        tasks.register("runTerminalDaemon") {
+            for (plugin in pluginProjects) {
+                dependsOn(plugin.tasks.getByName("jar"))
+            }
+            group = "verification"
+
+            timeout.set(Duration.ofMinutes(5))
+            doFirst {
+                javaexec {
+                    val terminal = project(":mirai-console-terminal")
+                    val console = project(":mirai-console")
+                    classpath = terminal.configurations["testRuntimeClasspath"]
+                    classpath += console.configurations["testRuntimeClasspath"]
+                    classpath += console.sourceSets.getByName("main").output // console
+                    classpath += console.sourceSets.getByName("test").output // console
+                    classpath += terminal.sourceSets.getByName("main").output
+                    classpath += currentProject.tasks.getByName("jar").outputs.files
+                    mainClass.set("net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader")
+
+                    val sandbox = project.buildDir.resolve("runTerminalDaemon")
+                    this.workingDir = sandbox
+
+
+                    sandbox.mkdirs()
+                    val plugins = sandbox.resolve("plugins")
+                    plugins.deleteRecursively()
+                    plugins.mkdirs()
+                    pluginProjects.forEach { testerProject ->
+                        val jarTask = testerProject.tasks.getByName("jar")
+                        jarTask.outputs.files.forEach { it.copyTo(plugins.resolve(it.name), true) }
+                    }
+                }
+            }
+        }
+
+        tasks.getByName("check").dependsOn("runTerminalDaemon")
+    }
+}

+ 6 - 0
settings.gradle.kts

@@ -34,6 +34,12 @@ includeProject(":mirai-console-compiler-common", "tools/compiler-common")
 includeProject(":mirai-console-intellij", "tools/intellij-plugin")
 includeProject(":mirai-console-gradle", "tools/gradle-plugin")
 
+includeProject(":mirai-console:tester-plugin-common", "backend/mirai-console/tester-plugin-common")
+includeProject(":mirai-console:sandbox-tester:p1", "backend/mirai-console/sandbox-tester/p1")
+includeProject(":mirai-console:sandbox-tester:p2", "backend/mirai-console/sandbox-tester/p2")
+includeProject(":mirai-console:sandbox-tester:auto-end", "backend/mirai-console/sandbox-tester/auto-end")
+includeProject(":mirai-console:sandbox-tester", "backend/mirai-console/sandbox-tester")
+
 @Suppress("ConstantConditionIf")
 if (!disableOldFrontEnds) {
     includeProject(":mirai-console-terminal", "frontend/mirai-console-terminal")

+ 2 - 2
tools/gradle-plugin/src/main/kotlin/VersionConstants.kt

@@ -10,6 +10,6 @@
 package net.mamoe.mirai.console.gradle
 
 internal object VersionConstants {
-    const val CONSOLE_VERSION = "2.7-M2-dev-1" // value is written here automatically during build
-    const val CORE_VERSION = "2.7-M2-dev-1" // value is written here automatically during build
+    const val CONSOLE_VERSION = "2.7-RC" // value is written here automatically during build
+    const val CORE_VERSION = "2.7-RC" // value is written here automatically during build
 }