Skip to content

Commit d1dfc21

Browse files
committed
build: Extract functional test handling into testlib subproject
fix some repositories plugin tests
1 parent 2d85d66 commit d1dfc21

File tree

10 files changed

+109
-62
lines changed

10 files changed

+109
-62
lines changed

build.gradle.kts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,45 @@ version = "2.0.2"
1919

2020
subprojects {
2121
plugins.apply {
22-
apply(JavaGradlePluginPlugin::class)
23-
apply("com.gradle.plugin-publish")
2422
apply("net.kyori.indra")
25-
apply("net.kyori.indra.crossdoc")
2623
apply("net.kyori.indra.licenser.spotless")
27-
apply("net.kyori.indra.publishing.gradle-plugin")
2824
apply("net.kyori.indra.git")
2925
}
3026

27+
if (project.name != "spongegradle-testlib") {
28+
plugins.apply {
29+
apply(JavaGradlePluginPlugin::class)
30+
apply("com.gradle.plugin-publish")
31+
apply("net.kyori.indra.publishing.gradle-plugin")
32+
apply("net.kyori.indra.crossdoc")
33+
}
34+
35+
tasks.named("publishPlugins") {
36+
onlyIf { net.kyori.indra.util.Versioning.isRelease(project) }
37+
}
38+
39+
extensions.configure(TestingExtension::class) {
40+
suites.withType(JvmTestSuite::class).configureEach {
41+
useJUnitJupiter("5.9.0")
42+
}
43+
44+
val functionalTest = suites.register("functionalTest", JvmTestSuite::class) {
45+
dependencies {
46+
implementation(project)
47+
implementation(project(":spongegradle-testlib"))
48+
implementation("com.google.code.gson:gson:2.9.1")
49+
}
50+
testType.set(TestSuiteType.FUNCTIONAL_TEST)
51+
}
52+
53+
tasks.named("check") {
54+
dependsOn(functionalTest)
55+
}
56+
57+
extensions.getByType(GradlePluginDevelopmentExtension::class).testSourceSets(functionalTest.get().sources)
58+
}
59+
}
60+
3161
repositories {
3262
maven("https://repo.spongepowered.org/repository/maven-public/") {
3363
name = "sponge"
@@ -51,10 +81,6 @@ subprojects {
5181
)
5282
}
5383

54-
tasks.named("publishPlugins") {
55-
onlyIf { net.kyori.indra.util.Versioning.isRelease(project) }
56-
}
57-
5884
extensions.configure(IndraExtension::class) {
5985
github("SpongePowered", "SpongeGradle") {
6086
ci(true)
@@ -120,7 +146,7 @@ subprojects {
120146
property("url", projectUrl)
121147
}
122148

123-
extensions.configure(SigningExtension::class) {
149+
extensions.findByType(SigningExtension::class)?.apply {
124150
val spongeSigningKey = project.findProperty("spongeSigningKey") as String?
125151
val spongeSigningPassword = project.findProperty("spongeSigningPassword") as String?
126152
if (spongeSigningKey != null && spongeSigningPassword != null) {
@@ -140,7 +166,7 @@ subprojects {
140166
website("https://spongepowered.org/")
141167
}
142168

143-
extensions.configure(CrossdocExtension::class) {
169+
extensions.findByType(CrossdocExtension::class)?.apply {
144170
baseUrl(providers.gradleProperty("javadocLinkRoot"))
145171
nameBasedDocumentationUrlProvider {
146172
projectNamePrefix.set("spongegradle-")

plugin-development/build.gradle.kts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
plugins {
2-
`jvm-test-suite`
3-
}
4-
51
dependencies {
62
implementation("org.spongepowered:plugin-meta:0.8.0")
73
// implementation("org.spongepowered:vanillagradle:0.2-SNAPSHOT")
84
// implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:0.10")
95
}
106

11-
testing.suites.withType(JvmTestSuite::class).configureEach {
12-
useJUnitJupiter("5.9.0")
13-
}
14-
15-
val functionalTest = testing.suites.register("functionalTest", JvmTestSuite::class) {
7+
testing.suites.named("functionalTest", JvmTestSuite::class) {
168
dependencies {
17-
implementation(project)
18-
implementation("net.kyori:mammoth-test:1.2.0")
199
implementation("com.google.code.gson:gson:2.9.1")
2010
}
2111
}
2212

23-
tasks.check {
24-
dependsOn(functionalTest)
25-
}
26-
27-
gradlePlugin.testSourceSets(functionalTest.get().sources)
28-
2913
indraPluginPublishing {
3014
plugin(
3115
"plugin",

plugin-development/src/functionalTest/java/org/spongepowered/gradle/plugin/SpongePluginPluginFunctionalTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.gradle.testkit.runner.UnexpectedBuildSuccess;
3838
import org.junit.jupiter.api.Assertions;
3939
import org.junit.jupiter.api.DisplayName;
40+
import org.spongepowered.gradle.build.SpongeGradleFunctionalTest;
4041

4142
import java.io.IOException;
4243
import java.nio.file.Path;

repository/build.gradle.kts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,3 @@ indraPluginPublishing {
77
listOf("maven", "repository", "project", "settings")
88
)
99
}
10-
11-
testing.suites.withType(JvmTestSuite::class).configureEach {
12-
useJUnitJupiter("5.9.0")
13-
}
14-
15-
val functionalTest = testing.suites.register("functionalTest", JvmTestSuite::class) {
16-
dependencies {
17-
implementation(project)
18-
implementation("net.kyori:mammoth-test:1.2.0")
19-
}
20-
}
21-
22-
tasks.check {
23-
dependsOn(functionalTest)
24-
}
25-
26-
gradlePlugin.testSourceSets(functionalTest.get().sources)

repository/src/functionalTest/java/org/spongepowered/gradle/repository/RepositoriesFunctionalTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,41 @@
2828
import net.kyori.mammoth.test.TestContext;
2929
import org.junit.jupiter.api.Disabled;
3030
import org.junit.jupiter.api.DisplayName;
31+
import org.junit.jupiter.api.DisplayNameGeneration;
32+
import org.spongepowered.gradle.build.FunctionalTestDisplayNameGenerator;
33+
import org.spongepowered.gradle.build.SpongeGradleFunctionalTest;
3134

3235
import java.io.IOException;
3336

3437
// These all essentially just test evaluation of the buildscript
38+
39+
@DisplayNameGeneration(FunctionalTestDisplayNameGenerator.class)
3540
public class RepositoriesFunctionalTest {
3641

37-
@GradleFunctionalTest
38-
@DisplayName("project")
42+
@SpongeGradleFunctionalTest
3943
void testProject(final TestContext ctx) throws IOException {
4044
ctx.copyInput("build.gradle");
4145
ctx.copyInput("settings.gradle");
4246

4347
ctx.build("help");
4448
}
4549

46-
@GradleFunctionalTest
47-
@DisplayName("settings")
50+
@SpongeGradleFunctionalTest
4851
void testSettings(final TestContext ctx) throws IOException {
4952
ctx.copyInput("settings.gradle");
5053

5154
ctx.build("help");
5255
}
5356

54-
@GradleFunctionalTest
55-
@Disabled
56-
@DisplayName("kotlinProject")
57+
@SpongeGradleFunctionalTest
5758
void testKotlinProject(final TestContext ctx) throws IOException {
5859
ctx.copyInput("build.gradle.kts");
5960
ctx.copyInput("settings.gradle.kts");
6061

6162
ctx.build("help");
6263
}
6364

64-
@GradleFunctionalTest
65-
@Disabled
66-
@DisplayName("kotlinSettings")
65+
@SpongeGradleFunctionalTest
6766
void testKotlinSettings(final TestContext ctx) throws IOException {
6867
ctx.copyInput("settings.gradle.kts");
6968

repository/src/functionalTest/resources/org/spongepowered/gradle/repository/kotlinSettings/in/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ plugins {
33
}
44

55
dependencyResolutionManagement {
6-
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
6+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
77
repositories {
8+
val sponge = (this as ExtensionAware).extensions.getByType(org.spongepowered.gradle.repository.SpongeRepositoryExtension::class)
89
sponge.releases()
910
sponge.snapshots()
1011
}

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
rootProject.name = "SpongeGradle"
2020

21-
sequenceOf("convention", "plugin-development", "repository").forEach {
21+
sequenceOf("convention", "plugin-development", "repository", "testlib").forEach {
2222
include(it)
2323
findProject(":$it")?.name = "${rootProject.name.toLowerCase(java.util.Locale.ROOT)}-$it"
2424
}

testlib/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies {
2+
api("net.kyori:mammoth-test:1.2.0")
3+
}
4+
5+
tasks.javadoc {
6+
isEnabled = false
7+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of spongegradle-testlib, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.gradle.build;
26+
27+
import org.junit.jupiter.api.DisplayNameGenerator;
28+
29+
import java.lang.reflect.Method;
30+
31+
/**
32+
* An extension of the standard display name generator that only uses method names for test display names.
33+
*
34+
* <p>This is better suited for test directory selection.</p>
35+
*/
36+
public final class FunctionalTestDisplayNameGenerator extends DisplayNameGenerator.Standard {
37+
38+
@Override
39+
public String generateDisplayNameForMethod(final Class<?> testClass, final Method testMethod) {
40+
final String name = testMethod.getName();
41+
if (name.startsWith("test") && name.length() > 5) {
42+
return Character.toLowerCase(name.charAt(4)) + name.substring(5);
43+
} else {
44+
return name;
45+
}
46+
}
47+
48+
}

plugin-development/src/functionalTest/java/org/spongepowered/gradle/plugin/SpongeGradleFunctionalTest.java renamed to testlib/src/main/java/org/spongepowered/gradle/build/SpongeGradleFunctionalTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* This file is part of spongegradle-plugin-development, licensed under the MIT License (MIT).
2+
* This file is part of spongegradle-testlib, licensed under the MIT License (MIT).
33
*
44
* Copyright (c) SpongePowered <https://www.spongepowered.org>
55
* Copyright (c) contributors
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.gradle.plugin;
25+
package org.spongepowered.gradle.build;
2626

2727
import net.kyori.mammoth.test.GradleFunctionalTest;
2828
import net.kyori.mammoth.test.GradleParameters;
@@ -40,10 +40,8 @@
4040
*/
4141
@GradleFunctionalTest
4242
@GradleParameters({"--warning-mode", "fail", "--stacktrace"})
43-
@TestVariant(gradleVersion = "6.9.2")
44-
@TestVariant(gradleVersion = "7.5")
45-
@TestVariant(gradleVersion = "6.9.2", extraArguments = "--configuration-cache")
46-
@TestVariant(gradleVersion = "7.5", extraArguments = "--configuration-cache")
43+
@TestVariant(gradleVersion = "7.5.1")
44+
@TestVariant(gradleVersion = "7.5.1", extraArguments = "--configuration-cache")
4745
@TestVariantResource(value = "/injected-gradle-versions", optional = true)
4846
@Documented
4947
@Retention(RetentionPolicy.RUNTIME)

0 commit comments

Comments
 (0)