From 53bba1f32fba276a2fb5e1fb9af510b9c8878e5c Mon Sep 17 00:00:00 2001 From: Clay Johnson Date: Wed, 4 May 2022 10:32:32 -0500 Subject: [PATCH] Add UP-TO-DATE tests for changing paths This test should cover #557. --- .../gradle/ProtobufJavaPluginTest.groovy | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index f5543b82..bc773d15 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -484,6 +484,61 @@ class ProtobufJavaPluginTest extends Specification { gradleVersion << GRADLE_VERSIONS } + @Unroll + void "test proto generation is not up-to-date on path changes [gradle #gradleVersion]"() { + given: "project from testProject" + File projectDir = ProtobufPluginTestHelper.projectBuilder('testProject') + .copyDirs('testProjectBase', 'testProject') + .build() + + when: "protoc path is set and build is invoked" + def buildGradleFile = new File(projectDir, "build.gradle") + buildGradleFile.append(""" + configurations { + protoc + } + + dependencies { + protoc "com.google.protobuf:protoc:3.0.0:\$project.osdetector.classifier@exe" + } + + protobuf { + protoc { + path = "\$configurations.protoc.singleFile" + } + }""") + def result = GradleRunner.create() + .withProjectDir(projectDir) + .withArguments('build', '--stacktrace') + .withPluginClasspath() + .withGradleVersion(gradleVersion) + .forwardStdOutput(new OutputStreamWriter(System.out)) + .forwardStdError(new OutputStreamWriter(System.err)) + .withDebug(true) + .build() + + then: "it succeeds" + result.task(":generateProto").outcome == TaskOutcome.SUCCESS + + when: "protoc path is changed and build runs again" + buildGradleFile.text = buildGradleFile.text.replace("com.google.protobuf:protoc:3.0.0", "com.google.protobuf:protoc:3.0.2") + result = GradleRunner.create() + .withProjectDir(projectDir) + .withArguments('build', '--stacktrace') + .withPluginClasspath() + .withGradleVersion(gradleVersion) + .forwardStdOutput(new OutputStreamWriter(System.out)) + .forwardStdError(new OutputStreamWriter(System.err)) + .withDebug(true) + .build() + + then: "generateProto is not UP_TO_DATE" + result.task(":generateProto").outcome == TaskOutcome.SUCCESS + + where: + gradleVersion << GRADLE_VERSIONS + } + @Unroll void "test proto extraction is up-to-date for testProject when changing java sources [gradle #gradleVersion]"() { given: "project from testProject"