-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #375 from jdaugherty/7.0.x
End to End testing for the publish plugin & clean-up of previously failed changes
- Loading branch information
Showing
73 changed files
with
1,533 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
def e2eTest = sourceSets.create('e2eTest') | ||
def e2eTestTask = tasks.register('e2eTest', Test) { | ||
group = 'verification' | ||
testClassesDirs = sourceSets.e2eTest.output.classesDirs | ||
classpath = sourceSets.e2eTest.runtimeClasspath | ||
useJUnitPlatform() | ||
systemProperty("localMavenPath", rootProject.layout.buildDirectory.dir('local-maven').get().asFile.absolutePath) | ||
systemProperty("grailsGradlePluginVersion", rootProject.version) | ||
|
||
testLogging { | ||
exceptionFormat = 'full' | ||
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' | ||
} | ||
beforeTest { descriptor -> logger.quiet " -- $descriptor" } | ||
|
||
dependsOn "publishAllPublicationsToTestCaseMavenRepoRepository" | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn e2eTestTask | ||
} | ||
|
||
gradlePlugin { | ||
testSourceSets e2eTest | ||
} | ||
|
||
dependencies { | ||
// Note: must use a groovy 3 compatible version of Spock | ||
e2eTestImplementation "org.spockframework:spock-core:${project['spock.version']}", { | ||
exclude group: 'org.apache.groovy' | ||
} | ||
e2eTestImplementation 'commons-io:commons-io:2.18.0' | ||
e2eTestImplementation gradleTestKit() | ||
e2eTestRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
} |
130 changes: 130 additions & 0 deletions
130
src/e2eTest/groovy/org/grails/gradle/test/GradleSpecification.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package org.grails.gradle.test | ||
|
||
import org.apache.commons.io.FileUtils | ||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.BuildTask | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import spock.lang.Specification | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
abstract class GradleSpecification extends Specification { | ||
private static Path basePath | ||
|
||
private static GradleRunner gradleRunner | ||
|
||
void setupSpec() { | ||
basePath = Files.createTempDirectory("gradle-projects") | ||
Path testKitDirectory = Files.createDirectories(basePath.resolve('.gradle')) | ||
gradleRunner = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withTestKitDir(testKitDirectory.toFile()) | ||
|
||
gradleRunner = addEnvironmentVariable( | ||
"LOCAL_MAVEN_PATH", | ||
System.getProperty("localMavenPath"), | ||
gradleRunner | ||
) | ||
|
||
gradleRunner = setGradleProperty( | ||
"grailsGradlePluginVersion", | ||
System.getProperty("grailsGradlePluginVersion"), | ||
gradleRunner | ||
) | ||
} | ||
|
||
GradleRunner addEnvironmentVariable(String key, String value, GradleRunner runner) { | ||
Map environment = runner.environment | ||
if (environment) { | ||
environment.put(key, value) | ||
|
||
return runner | ||
} else { | ||
return runner.withEnvironment([(key): value]) | ||
} | ||
} | ||
|
||
GradleRunner setGradleProperty(String key, String value, GradleRunner runner) { | ||
addEnvironmentVariable("ORG_GRADLE_PROJECT_${key}", value, runner) | ||
} | ||
|
||
void cleanup() { | ||
basePath.toFile().listFiles().each { | ||
// Reuse the gradle cache from previous tests | ||
if (it.name == ".gradle") { | ||
return | ||
} | ||
|
||
FileUtils.deleteQuietly(it) | ||
} | ||
} | ||
|
||
void cleanupSpec() { | ||
FileUtils.deleteQuietly(basePath.toFile()) | ||
} | ||
|
||
protected GradleRunner setupTestResourceProject(String type, String projectName, String nestedProject = null) { | ||
Objects.requireNonNull(projectName, "projectName must not be null") | ||
|
||
Path destinationDir = basePath.resolve(type) | ||
Files.createDirectories(destinationDir) | ||
|
||
Path sourceProjectDir = Path.of("src/e2eTest/resources/publish-projects/$type/$projectName") | ||
FileUtils.copyDirectoryToDirectory(sourceProjectDir.toFile(), destinationDir.toFile()) | ||
|
||
setupProject(destinationDir.resolve(projectName).resolve(nestedProject ?: '.')) | ||
} | ||
|
||
protected GradleRunner setupProject(Path projectDirectory) { | ||
gradleRunner.withProjectDir(projectDirectory.toFile()) | ||
} | ||
|
||
protected Path createProjectDir(String projectName) { | ||
Objects.requireNonNull(projectName, "projectName must not be null") | ||
|
||
Path destinationDir = basePath.resolve(projectName) | ||
Files.createDirectories(destinationDir) | ||
|
||
destinationDir | ||
} | ||
|
||
protected BuildResult executeTask(String taskName, List<String> otherArguments = [], GradleRunner gradleRunner) { | ||
List arguments = [taskName, "--stacktrace"] | ||
arguments.addAll(otherArguments) | ||
|
||
gradleRunner.withArguments(arguments).forwardOutput().build() | ||
} | ||
|
||
protected void assertTaskSuccess(String taskName, BuildResult result) { | ||
def tasks = result.tasks.find { it.path.endsWith(":${taskName}") } | ||
if (!tasks) { | ||
throw new IllegalStateException("No tasks were found for `${taskName}`") | ||
} | ||
|
||
tasks.each { BuildTask task -> | ||
if (task.outcome != TaskOutcome.SUCCESS) { | ||
throw new IllegalStateException("Task $taskName failed with outcome $task.outcome") | ||
} | ||
} | ||
} | ||
|
||
protected void assertBuildSuccess(BuildResult result, List<String> ignoreTaskNames = []) { | ||
def results = result.tasks.groupBy { it.outcome } | ||
|
||
for (String ignoredTaskName : ignoreTaskNames) { | ||
for (BuildTask ignoredTask : result.tasks.findAll { it.path.endsWith("${ignoredTaskName}") }) { | ||
def taskOutComeTasks = results.get(ignoredTask.outcome) | ||
taskOutComeTasks.remove(ignoredTask) | ||
if (!taskOutComeTasks) { | ||
results.remove(ignoredTask.outcome) | ||
} | ||
} | ||
} | ||
|
||
if (results.keySet().size() != 1) { | ||
throw new IllegalStateException("Unexpected Task failures: ${results.findAll { it.key != TaskOutcome.SUCCESS }}") | ||
} | ||
} | ||
} |
Oops, something went wrong.