Skip to content

Commit

Permalink
check-in acceptance test for configuration cache (#54)
Browse files Browse the repository at this point in the history
* and by the way update spock to used groovy version

Signed-off-by: Andreas Schmid <service@aaschmid.de>
  • Loading branch information
aaschmid committed Mar 28, 2021
1 parent 64eb4ac commit 1a1ec76
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {

integTestImplementation "org.assertj:assertj-core:3.13.2"
integTestImplementation "org.junit.vintage:junit-vintage-engine:5.5.2"
integTestImplementation("org.spockframework:spock-core:1.3-groovy-2.4") {
integTestImplementation("org.spockframework:spock-core:1.3-groovy-2.5") {
exclude module: "groovy-all"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,45 @@ class CpdAcceptanceTest extends IntegrationBaseSpec {
secondResult.output.contains("BUILD SUCCESSFUL")
!(secondResult.output =~ /CPD found duplicate code\. See the report at file:\/\/.*\/cpdCheck.vs/)
}

@Issue("https://github.com/aaschmid/gradle-cpd-plugin/issues/54")
def "Cpd task can be loaded from the configuration cache"() {
given:
buildFileWithPluginAndRepos() << """
cpdCheck{
reports{
csv.enabled = true
xml.enabled = false
}
source files(${testPath(JAVA, 'de/aaschmid/clazz')})
}
""".stripIndent()

when:
def result = runWithoutDebug('--configuration-cache', 'cpdCheck')

then:
result.task(':cpdCheck').outcome == SUCCESS
result.output.contains('BUILD SUCCESSFUL')
result.output.contains('Configuration cache entry stored.')

def report = file('build/reports/cpd/cpdCheck.csv')
report.exists()
report.text == "lines,tokens,occurrences\n" // empty

when:
report.delete() // remove report in order to force re-execution of `cpdCheck`

and:
def result2 = runWithoutDebug('--configuration-cache', 'cpdCheck')

then:
result2.task(':cpdCheck').outcome == SUCCESS
result2.output.contains("BUILD SUCCESSFUL")
result2.output.contains('Configuration cache entry reused.')

def report2 = file('build/reports/cpd/cpdCheck.csv')
report2.exists()
report.text == "lines,tokens,occurrences\n" // empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ abstract class IntegrationBaseSpec extends Specification {
}
}

protected BuildResult runWithoutDebug(String... arguments) {
try {
return GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments(arguments)
.withPluginClasspath()
.withDebug(false) // `true` fails if `--configuration-cache`, see https://github.com/gradle/gradle/issues/14125
.build()
} catch (UnexpectedBuildResultException e) {
return e.buildResult
}
}

/**
* As the Gradle test kit does not support the old plugin mechanism, this method generates a {@code buildscript}
* code block with the same dependencies as {@link org.gradle.testkit.runner.GradleRunner#withPluginClasspath()} or
Expand Down

0 comments on commit 1a1ec76

Please sign in to comment.