Skip to content

Commit

Permalink
Reuse GradleRunner config
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 18, 2024
1 parent b4284aa commit 8252f32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ abstract class AbstractFuncSpec extends Specification {
testedGradleVersion = gradleVersion
}

// TODO: We can remove this and fully enable CC in tests once bump the Shadow version to 8.1.1+.
// TODO: But Kotlin test still fails, it was suppressed in 1bab41646df6f47aea84ea3febeeec1c76cd2e79, need to investigate.
protected void withoutConfigurationCache(String reason) {
noConfigurationCacheReason = reason
}
Expand Down Expand Up @@ -83,6 +85,7 @@ abstract class AbstractFuncSpec extends Specification {
.withPluginClasspath()
.withProjectDir(projectDir)
.withArguments(arguments)
.withTestKitDir(testKitDir)
}

protected BuildResult build(String... arguments) {
Expand All @@ -94,13 +97,17 @@ abstract class AbstractFuncSpec extends Specification {
}

private List<String> calculateArguments(String... arguments) {
def gradleVersionWithConfigurationCache = testedGradleVersion >= GradleVersion.version('6.6')
if (gradleVersionWithConfigurationCache && noConfigurationCacheReason) {
println("Configuration cache disabled: $noConfigurationCacheReason")
}
(gradleVersionWithConfigurationCache && !noConfigurationCacheReason
(!noConfigurationCacheReason
? ['--stacktrace',
'--configuration-cache']
: ['--stacktrace']) + (arguments as List)
}

private static File getTestKitDir() {
def gradleUserHome = System.getenv("GRADLE_USER_HOME")
if (!gradleUserHome) {
gradleUserHome = new File(System.getProperty("user.home"), ".gradle").absolutePath
}
return new File(gradleUserHome, "testkit")
}
}
4 changes: 2 additions & 2 deletions src/funcTest/groovy/me/champeau/jmh/ParameterSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class ParameterSpec extends AbstractFuncSpec {
usingSample("java-project")

when:
def result = build("jmhJar", "--configuration-cache")
def result = build("jmhJar")

then:
result.task(":jmhJar").outcome == SUCCESS
result.output.contains("Calculating task graph as no configuration cache is available for tasks: jmhJar") ||
result.output.contains("Calculating task graph as no cached configuration is available for tasks: jmhJar")

when:
result = build("jmhJar", "--configuration-cache")
result = build("jmhJar")

then:
result.task(":jmhJar").outcome == UP_TO_DATE
Expand Down

0 comments on commit 8252f32

Please sign in to comment.