Skip to content

Commit f406a53

Browse files
Excavator: Migrate Groovy nebula test TestDependencyVersionsTaskSpec to the new Java Junit framework (#303)
1 parent adf00a8 commit f406a53

File tree

4 files changed

+3581
-119
lines changed

4 files changed

+3581
-119
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
1010
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.69.0'
1111
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.24.0'
12-
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.34.0'
12+
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.35.0'
1313
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.27.0'
1414
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.82.0'
1515
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.26.0'

gradle-plugin-testing/src/test/groovy/com/palantir/gradle/plugintesting/TestDependencyVersionsTaskSpec.groovy

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.palantir.gradle.plugintesting;
18+
19+
import com.palantir.gradle.testing.execution.GradleInvoker;
20+
import com.palantir.gradle.testing.files.arbitrary.ArbitraryFile;
21+
import com.palantir.gradle.testing.junit.GradlePluginTests;
22+
import com.palantir.gradle.testing.project.RootProject;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
26+
@GradlePluginTests
27+
class TestDependencyVersionsTaskTest {
28+
29+
private ArbitraryFile outputFile;
30+
31+
@BeforeEach
32+
void setup(RootProject rootProject) {
33+
outputFile = rootProject.buildDir().file("plugin-testing/dependency-versions.properties");
34+
35+
rootProject
36+
.gradlePropertiesFile()
37+
.appendProperty(PluginTestingPlugin.PLUGIN_VERSION_PROPERTY_NAME, System.getProperty("projectVersion"));
38+
}
39+
40+
@Test
41+
void write_versions_without_gcv(GradleInvoker gradle, RootProject project) {
42+
project.buildGradle().plugins().add("groovy").add("com.palantir.gradle-plugin-testing");
43+
44+
project.buildGradle().append("""
45+
repositories {
46+
mavenCentral()
47+
mavenLocal()
48+
}
49+
50+
dependencies {
51+
//WARNING: Do not include any dependencies here that the plugin-testing-core project uses in it's
52+
// api or implementation configurations. Because the plugin adds the plugin-testing-core artifact as
53+
// a testImplementation dependency, we get the transitive dependencies of it (e.g. guava). Since those
54+
// versions will update over time this test could start erroneously failing. So just list some random
55+
// dependencies here that are unlikely to be added to the plugin-test-core project.
56+
//implementation 'com.google.guava:guava:33.3.1-jre'
57+
implementation 'org.ow2.asm:asm:9.7.1'
58+
59+
testImplementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1'
60+
61+
testRuntimeOnly 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.31.0'
62+
}
63+
""");
64+
65+
gradle.withArgs("writeTestDependencyVersions").buildsSuccessfully();
66+
67+
outputFile.assertThat().exists();
68+
outputFile.assertThat().content().doesNotContain("null");
69+
outputFile.assertThat().content().contains("org.ow2.asm:asm=9.7.1");
70+
outputFile.assertThat().content().contains("org.apache.httpcomponents.client5:httpclient5=5.3.1");
71+
outputFile
72+
.assertThat()
73+
.content()
74+
.contains("com.palantir.gradle.consistentversions:gradle-consistent-versions=2.31.0");
75+
for (String name : PluginTestingPlugin.CORE_MAVEN_NAMES) {
76+
outputFile.assertThat().content().contains("com.palantir.gradle.plugintesting:" + name);
77+
}
78+
}
79+
80+
@Test
81+
void write_versions_with_gcv(GradleInvoker gradle, RootProject project) {
82+
// remember - the resolved version for this dependency is using the information passed from the version of the
83+
// plugin
84+
// applied to the gradle-plugin-test project itself, _not_ the current version under test. So the
85+
// addBuildScriptDependencies code and the "resolve" logic it calls is the current version, but the information
86+
// it is working with is from the last published version of the plugin (assuming that's the one applied to the
87+
// root build.gradle file of this project.
88+
project.buildGradle()
89+
.append(TestContentHelpers.addBuildScriptBlock(
90+
"mavenCentral()", "com.palantir.gradle.consistentversions:gradle-consistent-versions"));
91+
92+
project.buildGradle()
93+
.plugins()
94+
.add("com.palantir.consistent-versions")
95+
.add("groovy")
96+
.add("com.palantir.gradle-plugin-testing");
97+
98+
project.buildGradle().append("""
99+
repositories {
100+
mavenCentral()
101+
mavenLocal()
102+
}
103+
104+
dependencies {
105+
implementation 'com.google.guava:guava'
106+
107+
testImplementation 'org.junit.jupiter:junit-jupiter'
108+
testImplementation 'com.netflix.nebula:nebula-test'
109+
110+
testRuntimeOnly 'com.palantir.gradle.consistentversions:gradle-consistent-versions'
111+
}
112+
""");
113+
114+
project.propertiesFile("versions.props")
115+
.appendProperty(
116+
"org.junit.jupiter:junit-jupiter",
117+
TestDependencyVersions.version("org.junit.jupiter:junit-jupiter"))
118+
.appendProperty(
119+
"com.netflix.nebula:nebula-test",
120+
TestDependencyVersions.version("com.netflix.nebula:nebula-test"))
121+
.appendProperty("com.google.guava:guava", TestDependencyVersions.version("com.google.guava:guava"))
122+
.appendProperty(
123+
"com.palantir.gradle.consistentversions:gradle-consistent-versions",
124+
TestDependencyVersions.version(
125+
"com.palantir.gradle.consistentversions:gradle-consistent-versions"));
126+
127+
gradle.withArgs("writeVersionLocks").buildsSuccessfully();
128+
129+
gradle.withArgs("writeTestDependencyVersions").buildsSuccessfully();
130+
131+
outputFile.assertThat().exists();
132+
outputFile.assertThat().content().doesNotContain("null");
133+
outputFile.assertThat().content().contains("org.junit.jupiter:junit-jupiter");
134+
for (String name : PluginTestingPlugin.CORE_MAVEN_NAMES) {
135+
outputFile.assertThat().content().contains("com.palantir.gradle.plugintesting:" + name);
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)