From 38e9db2e5470c91c3ea6ea0eb96321f3007d4279 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Thu, 5 Nov 2026 10:51:26 -0800 Subject: [PATCH 1/2] Track Clojure test selectors without parent project lookups --- README.md | 33 ++ .../clojuresque/ClojureBasePlugin.groovy | 12 +- .../clojuresque/tasks/ClojureTest.groovy | 3 +- .../clojure/ClojureTestSelectorSpec.groovy | 317 ++++++++++++++++++ 4 files changed, 362 insertions(+), 3 deletions(-) create mode 100644 src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy diff --git a/README.md b/README.md index 9106058..bdef4dc 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,36 @@ Plugin providing Clojuresque with compatibility fixes for Gradle 8.x # Quick Start Refer to the [Gradle Plugin Portal](https://plugins.gradle.org/plugin/nebula.clojure) for instructions on how to apply the plugin. + +# Selecting Clojure tests + +Use `./gradlew clojureTest -Pclojuresque.test.vars=example.app-test/first-test` +to select test vars. Separate multiple vars with commas. The selector can also be +set in `gradle.properties` as `clojuresque.test.vars=example.app-test/first-test`; +`-P` overrides that value. An absent or empty selector runs all tests. + +A project's own `ext.set('clojuresque.test.vars', 'example.app-test/first-test')` +takes precedence over Gradle properties, including `-P`. Set this local extra +before `clojureTest` is realized; it is read during lazy task configuration, so +setting it after plugin application is supported. Changing the extra after task +realization does not change the captured selection. Explicit task configuration +such as `tasks.named('clojureTest') { tests.set(['example.app-test/second-test']) }` +overrides the selector. `tests.set([])` runs all tests. Selection changes are +tracked task inputs and cause the newly selected tests to run. These selection +rules apply to the default `junit = false` runner; the existing `junit = true` +runner continues to run whole namespaces. + +**Adoption requirement:** parent-only extra properties are no longer inherited as +selectors, in either ordinary builds or Isolated Projects builds. Move shared +values from a root or parent `ext` to `gradle.properties` or `-P`, or configure +`tests`/the local extra in each participating project, preferably through a +locally applied convention plugin. Apply the Clojure plugin locally in each +participating project as well; root-only application remains root-only. + +The selector path is tested with strict configuration-cache validation in single, +sibling, and nested projects on Gradle 8.0 and the current wrapper (9.2.1), both +with and without Isolated Projects. This is a bounded fix for +selector ownership and input tracking. Enabled uber-JAR configuration-cache +issues and overly broad documentation inputs remain unresolved; whole-plugin +Isolated Projects compatibility is not claimed. These tests do not define a new +minimum supported Gradle/JDK version. diff --git a/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy b/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy index d7a088e..03616d5 100644 --- a/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy +++ b/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy @@ -131,8 +131,16 @@ class ClojureBasePlugin implements Plugin { dependsOn project.tasks.classes, project.configurations.testRuntimeClasspath description = "Run Clojure tests in src/test." group = JavaBasePlugin.VERIFICATION_GROUP - if (project.hasProperty("clojuresque.test.vars")) { - tests.set(project.property("clojuresque.test.vars").split(",").toList()) + // Read only this project's extras, at the same lazy task-configuration + // point as before. Local DSL values take precedence over Gradle properties. + def selectorProperty = "clojuresque.test.vars" + def localExtras = project.extensions.extraProperties + if (localExtras.has(selectorProperty)) { + tests.set(localExtras.get(selectorProperty).split(",").toList()) + } else { + tests.set(project.providers.gradleProperty(selectorProperty).map { + it.split(",").toList() + }.orElse([])) } if (project.gradle.startParameter.taskNames.contains('--tests')) { enabled = false diff --git a/src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureTest.groovy b/src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureTest.groovy index 4fff0d7..b31b64f 100644 --- a/src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureTest.groovy +++ b/src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureTest.groovy @@ -47,7 +47,8 @@ abstract class ClojureTest extends ClojureSourceTask { @Optional abstract Property getJunitOutputDir() - @Internal + @Input + @Optional abstract ListProperty getTests() private final ExecOperations execOperations diff --git a/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy b/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy new file mode 100644 index 0000000..f7f2b82 --- /dev/null +++ b/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy @@ -0,0 +1,317 @@ +package nebula.plugin.clojure + +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.gradle.util.GradleVersion +import spock.lang.Unroll + +/** Functional coverage for test-selector ownership and task input tracking. */ +class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { + // 8.0 is the assessed lower bound of README's 8.x claim, not a new support policy. + private static final List VERSIONS = ['8.0', GradleVersion.current().version].unique() + private static final String KEY = 'clojuresque.test.vars' + private static final String FIRST = 'selector.app-test/first-test' + private static final String SECOND = 'selector.app-test/second-test' + + @Unroll + def 'selector changes execute real tests in #topology on Gradle #version, isolation=#isolated'() { + given: + def participants = fixture(topology) + + when: 'no selector runs every test, even in child projects' + def initial = execute(version, isolated, participants) + def initialReuse = execute(version, isolated, participants) + + then: + stored(initial) + selected(initial, participants, ['first', 'second']) + reused(initialReuse) + outcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) + + when: + def first = execute(version, isolated, participants, ["-P$KEY=$FIRST"]) + def firstReuse = execute(version, isolated, participants, ["-P$KEY=$FIRST"]) + + then: + stored(first) + outcomes(first, participants, TaskOutcome.SUCCESS) + selected(first, participants, ['first']) + reused(firstReuse) + outcomes(firstReuse, participants, TaskOutcome.UP_TO_DATE) + + when: 'a changed selector invalidates configuration and task inputs' + def second = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) + def secondReuse = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) + + then: + stored(second) + outcomes(second, participants, TaskOutcome.SUCCESS) + selected(second, participants, ['second']) + reused(secondReuse) + outcomes(secondReuse, participants, TaskOutcome.UP_TO_DATE) + + when: 'editing selected test source reuses configuration but executes that project' + def leaf = participants.last() + def source = new File(projectDir, relative(leaf, 'src/test/clojure/selector/app_test.clj')) + source.text = source.text.replace('selected-second', 'selected-second-edited') + def edited = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) + def editedReuse = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) + + then: + reused(edited) + edited.task(taskPath(leaf)).outcome == TaskOutcome.SUCCESS + (participants - leaf).every { edited.task(taskPath(it)).outcome == TaskOutcome.UP_TO_DATE } + edited.output.contains("$leaf:selected-second-edited") + edited.output.contains('Ran 1 tests containing 1 assertions.') + reused(editedReuse) + outcomes(editedReuse, participants, TaskOutcome.UP_TO_DATE) + + where: + [version, isolated, topology] << [VERSIONS, [false, true], ['single', 'siblings', 'nested']].combinations() + } + + @Unroll + def 'parent-only extras are ignored and local extras win in #topology on Gradle #version, isolation=#isolated'() { + given: + def participants = fixture(topology) + buildFile << "ext.set('$KEY', '$FIRST')\n" + if (topology == 'nested') { + write('group/build.gradle', "ext.set('$KEY', '$SECOND')\n") + } + + when: 'neither root nor immediate-parent extras become child selectors' + def initial = execute(version, isolated, participants) + def initialReuse = execute(version, isolated, participants) + + then: + stored(initial) + selected(initial, participants, ['first', 'second']) + reused(initialReuse) + outcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) + + when: 'each child owns its extra, which takes precedence over -P' + participants.eachWithIndex { path, index -> + new File(projectDir, relative(path, 'build.gradle')) << + "ext.set('$KEY', '${index == 0 ? FIRST : SECOND}')\n" + } + def local = execute(version, isolated, participants, ["-P$KEY=$FIRST,$SECOND"]) + def localReuse = execute(version, isolated, participants, ["-P$KEY=$FIRST,$SECOND"]) + + then: + stored(local) + outcomes(local, participants, TaskOutcome.SUCCESS) + participants.eachWithIndex { path, index -> + assert local.output.contains("$path:selected-${index == 0 ? 'first' : 'second'}") + assert !local.output.contains("$path:selected-${index == 0 ? 'second' : 'first'}") + } + local.output.count('Ran 1 tests containing 1 assertions.') == participants.size() + reused(localReuse) + outcomes(localReuse, participants, TaskOutcome.UP_TO_DATE) + + where: + [version, isolated, topology] << [VERSIONS, [false, true], ['siblings', 'nested']].combinations() + } + + @Unroll + def 'selector precedence and timing: #scenario, isolation=#isolated'() { + given: + fixture('single', beforeApply, customization) + if (properties) write('gradle.properties', "$KEY=$FIRST\n") + + when: + def first = execute(GradleVersion.current().version, isolated, [':'], arguments) + def second = execute(GradleVersion.current().version, isolated, [':'], arguments) + + then: + stored(first) + outcomes(first, [':'], TaskOutcome.SUCCESS) + selected(first, [':'], expected) + reused(second) + outcomes(second, [':'], TaskOutcome.UP_TO_DATE) + + where: + [isolated, scenario, beforeApply, customization, properties, arguments, expected] << + [false, true].collectMany { isolation -> + [ + ['absent selector retains empty list', '', "assert tasks.named('clojureTest').get().tests.get() == []", false, [], ['first', 'second']], + ['Gradle property', '', '', true, [], ['first']], + ['CLI overrides gradle.properties', '', '', true, ["-P$KEY=$SECOND"], ['second']], + ['extra before apply overrides CLI', "ext.set('$KEY', '$FIRST')", '', false, ["-P$KEY=$SECOND"], ['first']], + ['extra after apply overrides CLI', '', "ext.set('$KEY', '$FIRST')", false, ["-P$KEY=$SECOND"], ['first']], + ['last extra before realization', '', "ext.set('$KEY', '$FIRST'); ext.set('$KEY', '$SECOND')", false, [], ['second']], + ['extra after realization is too late', '', "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest').get(); ext.set('$KEY', '$SECOND')", false, [], ['first']], + ['explicit task override', '', "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest') { tests.set(['$SECOND']) }", false, ["-P$KEY=$FIRST"], ['second']], + ['explicit override after realization', '', "tasks.named('clojureTest').get().tests.set(['$SECOND'])", false, ["-P$KEY=$FIRST"], ['second']], + ['explicit empty task selection', '', "tasks.named('clojureTest') { tests.set([]) }", false, ["-P$KEY=$FIRST"], ['first', 'second']], + ['explicit absent task selection', '', "tasks.named('clojureTest') { tests.set(providers.gradleProperty('absent.selector').map { it.split(',').toList() }) }", false, ["-P$KEY=$FIRST"], ['first', 'second']], + ['comma splitting with trailing comma', '', '', false, ["-P$KEY=$FIRST,$SECOND,"], ['first', 'second']], + ['empty CLI selection', '', '', false, ["-P$KEY="], ['first', 'second']], + ['empty local extra overrides CLI', '', "ext.set('$KEY', '')", false, ["-P$KEY=$FIRST"], ['first', 'second']] + ].collect { [isolation] + it } + } + } + + @Unroll + def 'changing #source invalidates selection, isolation=#isolated'() { + given: + fixture('single') + if (source == 'task.tests') { + buildFile << "tasks.named('clojureTest') { tests.set(providers.gradleProperty('selection').map { it.split(',').toList() }) }\n" + } + configureSelector(source, FIRST) + + when: + def first = execute(GradleVersion.current().version, isolated, [':']) + def firstReuse = execute(GradleVersion.current().version, isolated, [':']) + + then: + stored(first) + selected(first, [':'], ['first']) + reused(firstReuse) + outcomes(firstReuse, [':'], TaskOutcome.UP_TO_DATE) + + when: + configureSelector(source, SECOND) + def changed = execute(GradleVersion.current().version, isolated, [':']) + def changedReuse = execute(GradleVersion.current().version, isolated, [':']) + + then: + stored(changed) + outcomes(changed, [':'], TaskOutcome.SUCCESS) + selected(changed, [':'], ['second']) + reused(changedReuse) + outcomes(changedReuse, [':'], TaskOutcome.UP_TO_DATE) + + where: + [isolated, source] << [[false, true], ['gradle.properties', 'local extra', 'task.tests']].combinations() + } + + private void configureSelector(String source, String selector) { + if (source == 'local extra') { + buildFile << "ext.set('$KEY', '$selector')\n" + } else { + write('gradle.properties', "${source == 'task.tests' ? 'selection' : KEY}=$selector\n") + } + } + + @Unroll + def 'a selected failure is executed on Gradle #version, isolation=#isolated'() { + given: + fixture('single') + def source = new File(projectDir, 'src/test/clojure/selector/app_test.clj') + source << ''' + (deftest failing-test + (println "selected-failure") + (is (= 1 2))) + '''.stripIndent() + + when: + def first = execute(version, isolated, [':'], ["-P$KEY=$FIRST"]) + def failed = execute(version, isolated, [':'], ["-P$KEY=selector.app-test/failing-test"], true) + + then: + stored(first) + selected(first, [':'], ['first']) + failed.task(':clojureTest').outcome == TaskOutcome.FAILED + failed.output.contains('selected-failure') + failed.output.contains('FAIL in (failing-test)') + failed.output.contains('1 failures, 0 errors.') + stored(failed) + + when: + def passing = execute(version, isolated, [':'], ["-P$KEY=$SECOND"]) + def passingReuse = execute(version, isolated, [':'], ["-P$KEY=$SECOND"]) + + then: + outcomes(passing, [':'], TaskOutcome.SUCCESS) + selected(passing, [':'], ['second']) + reused(passingReuse) + outcomes(passingReuse, [':'], TaskOutcome.UP_TO_DATE) + + where: + [version, isolated] << [VERSIONS, [false, true]].combinations() + } + + private List fixture(String topology, String beforeApply = '', String customization = '') { + def participants = topology == 'single' ? [':'] : + (topology == 'siblings' ? [':library', ':app'] : [':library', ':group:app']) + settingsFile.text = "rootProject.name = 'selector'\n" + if (topology != 'single') { + settingsFile << "include ${participants.collect { "'${it.substring(1)}'" }.join(', ')}\n" + buildFile.text = '' + if (topology == 'nested') write('group/build.gradle', '') + } + participants.each { path -> + write(relative(path, 'build.gradle'), """ + plugins { id 'com.netflix.nebula.clojure' apply false } + $beforeApply + apply plugin: 'com.netflix.nebula.clojure' + repositories { mavenCentral() } + dependencies { implementation 'org.clojure:clojure:1.10.3' } + $customization + """.stripIndent()) + write(relative(path, 'src/test/clojure/selector/app_test.clj'), """ + (ns selector.app-test (:require [clojure.test :refer :all])) + (deftest first-test (println "$path:selected-first") (is (= 2 (+ 1 1)))) + (deftest second-test (println "$path:selected-second") (is (= 4 (+ 2 2)))) + """.stripIndent()) + } + participants + } + + private BuildResult execute(String version, boolean isolated, List participants, + List options = [], boolean fails = false) { + def isolationProperty = GradleVersion.version(version) >= GradleVersion.version('9.7') ? + 'org.gradle.isolated-projects' : 'org.gradle.unsafe.isolated-projects' + def arguments = participants.collect { taskPath(it) } + options + + ['--configuration-cache', '--configuration-cache-problems=fail', '--no-build-cache', + "-D$isolationProperty=$isolated", '--stacktrace', '--console=plain', '--max-workers=2'] + // Each test/mode gets a separate fixture, so isolation always starts with a cold cache. + def runner = GradleRunner.create().withProjectDir(projectDir).withPluginClasspath() + .withGradleVersion(version).withArguments(arguments.collect { it.toString() }) + fails ? runner.buildAndFail() : runner.build() + } + + private static boolean stored(BuildResult result) { + assert result.output.contains('Configuration cache entry stored') + assert !result.output.contains('Configuration cache problems found') + assert !result.output.contains('Reusing configuration cache.') + true + } + + private static boolean reused(BuildResult result) { + assert result.output.contains('Configuration cache entry reused') + assert !result.output.contains('Configuration cache problems found') + true + } + + private static boolean outcomes(BuildResult result, List participants, TaskOutcome outcome) { + participants.each { assert result.task(taskPath(it)).outcome == outcome } + true + } + + private static boolean selected(BuildResult result, List participants, List expected) { + participants.each { path -> + ['first', 'second'].each { test -> + assert result.output.contains("$path:selected-$test") == expected.contains(test) + } + } + assert result.output.count("Ran ${expected.size()} tests containing ${expected.size()} assertions.") == participants.size() + true + } + + private void write(String path, String content) { + def target = new File(projectDir, path) + target.parentFile.mkdirs() + target.text = content + } + + private static String relative(String projectPath, String path) { + (projectPath == ':' ? '' : projectPath.substring(1).replace(':', '/') + '/') + path + } + + private static String taskPath(String projectPath) { + (projectPath == ':' ? '' : projectPath) + ':clojureTest' + } +} From ddf2a43cad96fb2e861d0db7b61c5f2fe5059f77 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Thu, 5 Nov 2026 11:33:25 -0800 Subject: [PATCH 2/2] Simplify selector configuration and fix test JDK coverage --- .github/workflows/build.yml | 3 +- README.md | 41 ++--- build.gradle | 1 + .../clojuresque/ClojureBasePlugin.groovy | 13 +- .../clojure/ClojureTestSelectorSpec.groovy | 158 +++++++++--------- 5 files changed, 109 insertions(+), 107 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c32d137..164c458 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,7 @@ jobs: with: distribution: 'zulu' java-version: | + 8 17 21 ${{ matrix.java }} @@ -38,4 +39,4 @@ jobs: - name: Gradle build run: ./gradlew --stacktrace build env: - JDK_VERSION_FOR_TESTS: ${{ matrix.java }} \ No newline at end of file + JDK_VERSION_FOR_TESTS: ${{ matrix.java }} diff --git a/README.md b/README.md index bdef4dc..3b19d94 100644 --- a/README.md +++ b/README.md @@ -22,27 +22,30 @@ set in `gradle.properties` as `clojuresque.test.vars=example.app-test/first-test `-P` overrides that value. An absent or empty selector runs all tests. A project's own `ext.set('clojuresque.test.vars', 'example.app-test/first-test')` -takes precedence over Gradle properties, including `-P`. Set this local extra -before `clojureTest` is realized; it is read during lazy task configuration, so -setting it after plugin application is supported. Changing the extra after task -realization does not change the captured selection. Explicit task configuration -such as `tasks.named('clojureTest') { tests.set(['example.app-test/second-test']) }` -overrides the selector. `tests.set([])` runs all tests. Selection changes are -tracked task inputs and cause the newly selected tests to run. These selection -rules apply to the default `junit = false` runner; the existing `junit = true` -runner continues to run whole namespaces. +takes precedence over `-P` and `gradle.properties`. It can be set after plugin +application, but must be set before `clojureTest` is realized. Later changes to +the extra do not affect the captured selection. + +Explicit task configuration overrides the selector: + +```groovy +tasks.named('clojureTest') { + tests.set(['example.app-test/second-test']) +} +``` + +`tests.set([])` runs all tests. Selection changes are tracked task inputs and +execute the newly selected tests. These rules apply to the default `junit = false` +runner; `junit = true` continues to run whole namespaces. **Adoption requirement:** parent-only extra properties are no longer inherited as -selectors, in either ordinary builds or Isolated Projects builds. Move shared -values from a root or parent `ext` to `gradle.properties` or `-P`, or configure -`tests`/the local extra in each participating project, preferably through a -locally applied convention plugin. Apply the Clojure plugin locally in each -participating project as well; root-only application remains root-only. +selectors in either build mode. Move shared values to `gradle.properties` or `-P`, +or configure `tests`/the local extra in each participating project. Each project +must also apply the Clojure plugin, directly or through a local convention plugin. The selector path is tested with strict configuration-cache validation in single, sibling, and nested projects on Gradle 8.0 and the current wrapper (9.2.1), both -with and without Isolated Projects. This is a bounded fix for -selector ownership and input tracking. Enabled uber-JAR configuration-cache -issues and overly broad documentation inputs remain unresolved; whole-plugin -Isolated Projects compatibility is not claimed. These tests do not define a new -minimum supported Gradle/JDK version. +with and without Isolated Projects. Enabled uber-JAR configuration-cache issues +and overly broad documentation inputs remain unresolved. This coverage establishes +selector behavior only, without claiming whole-plugin isolation compatibility or +defining a new minimum supported Gradle/JDK version. diff --git a/build.gradle b/build.gradle index 888cdf4..425d358 100644 --- a/build.gradle +++ b/build.gradle @@ -77,5 +77,6 @@ tasks.withType(Test).configureEach { maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 testLogging { events "PASSED", "FAILED", "SKIPPED" + exceptionFormat 'full' } } diff --git a/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy b/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy index 03616d5..1d38a18 100644 --- a/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy +++ b/src/main/groovy/nebula/plugin/clojuresque/ClojureBasePlugin.groovy @@ -131,16 +131,13 @@ class ClojureBasePlugin implements Plugin { dependsOn project.tasks.classes, project.configurations.testRuntimeClasspath description = "Run Clojure tests in src/test." group = JavaBasePlugin.VERIFICATION_GROUP - // Read only this project's extras, at the same lazy task-configuration - // point as before. Local DSL values take precedence over Gradle properties. + // Resolve during lazy task configuration so local extras retain their override timing. def selectorProperty = "clojuresque.test.vars" def localExtras = project.extensions.extraProperties - if (localExtras.has(selectorProperty)) { - tests.set(localExtras.get(selectorProperty).split(",").toList()) - } else { - tests.set(project.providers.gradleProperty(selectorProperty).map { - it.split(",").toList() - }.orElse([])) + def selector = localExtras.has(selectorProperty) ? localExtras.get(selectorProperty) : + project.providers.gradleProperty(selectorProperty).orNull + if (selector != null) { + tests.set(selector.split(",").toList()) } if (project.gradle.startParameter.taskNames.contains('--tests')) { enabled = false diff --git a/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy b/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy index f7f2b82..2745c9f 100644 --- a/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy +++ b/src/test/groovy/nebula/plugin/clojure/ClojureTestSelectorSpec.groovy @@ -1,5 +1,6 @@ package nebula.plugin.clojure +import org.gradle.api.JavaVersion import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome @@ -8,8 +9,10 @@ import spock.lang.Unroll /** Functional coverage for test-selector ownership and task input tracking. */ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { - // 8.0 is the assessed lower bound of README's 8.x claim, not a new support policy. - private static final List VERSIONS = ['8.0', GradleVersion.current().version].unique() + // Gradle 8.0 supports Java 8–19; CI exercises it on Java 17. + private static final List VERSIONS = + ((JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_20) ? [] : ['8.0']) + + [GradleVersion.current().version]).unique() private static final String KEY = 'clojuresque.test.vars' private static final String FIRST = 'selector.app-test/first-test' private static final String SECOND = 'selector.app-test/second-test' @@ -24,32 +27,32 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def initialReuse = execute(version, isolated, participants) then: - stored(initial) - selected(initial, participants, ['first', 'second']) - reused(initialReuse) - outcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) + assertStored(initial) + assertSelected(initial, participants, ['first', 'second']) + assertReused(initialReuse) + assertOutcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) when: def first = execute(version, isolated, participants, ["-P$KEY=$FIRST"]) def firstReuse = execute(version, isolated, participants, ["-P$KEY=$FIRST"]) then: - stored(first) - outcomes(first, participants, TaskOutcome.SUCCESS) - selected(first, participants, ['first']) - reused(firstReuse) - outcomes(firstReuse, participants, TaskOutcome.UP_TO_DATE) + assertStored(first) + assertOutcomes(first, participants, TaskOutcome.SUCCESS) + assertSelected(first, participants, ['first']) + assertReused(firstReuse) + assertOutcomes(firstReuse, participants, TaskOutcome.UP_TO_DATE) when: 'a changed selector invalidates configuration and task inputs' def second = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) def secondReuse = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) then: - stored(second) - outcomes(second, participants, TaskOutcome.SUCCESS) - selected(second, participants, ['second']) - reused(secondReuse) - outcomes(secondReuse, participants, TaskOutcome.UP_TO_DATE) + assertStored(second) + assertOutcomes(second, participants, TaskOutcome.SUCCESS) + assertSelected(second, participants, ['second']) + assertReused(secondReuse) + assertOutcomes(secondReuse, participants, TaskOutcome.UP_TO_DATE) when: 'editing selected test source reuses configuration but executes that project' def leaf = participants.last() @@ -59,13 +62,13 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def editedReuse = execute(version, isolated, participants, ["-P$KEY=$SECOND"]) then: - reused(edited) + assertReused(edited) edited.task(taskPath(leaf)).outcome == TaskOutcome.SUCCESS (participants - leaf).every { edited.task(taskPath(it)).outcome == TaskOutcome.UP_TO_DATE } edited.output.contains("$leaf:selected-second-edited") edited.output.contains('Ran 1 tests containing 1 assertions.') - reused(editedReuse) - outcomes(editedReuse, participants, TaskOutcome.UP_TO_DATE) + assertReused(editedReuse) + assertOutcomes(editedReuse, participants, TaskOutcome.UP_TO_DATE) where: [version, isolated, topology] << [VERSIONS, [false, true], ['single', 'siblings', 'nested']].combinations() @@ -85,10 +88,10 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def initialReuse = execute(version, isolated, participants) then: - stored(initial) - selected(initial, participants, ['first', 'second']) - reused(initialReuse) - outcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) + assertStored(initial) + assertSelected(initial, participants, ['first', 'second']) + assertReused(initialReuse) + assertOutcomes(initialReuse, participants, TaskOutcome.UP_TO_DATE) when: 'each child owns its extra, which takes precedence over -P' participants.eachWithIndex { path, index -> @@ -99,15 +102,15 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def localReuse = execute(version, isolated, participants, ["-P$KEY=$FIRST,$SECOND"]) then: - stored(local) - outcomes(local, participants, TaskOutcome.SUCCESS) + assertStored(local) + assertOutcomes(local, participants, TaskOutcome.SUCCESS) participants.eachWithIndex { path, index -> assert local.output.contains("$path:selected-${index == 0 ? 'first' : 'second'}") assert !local.output.contains("$path:selected-${index == 0 ? 'second' : 'first'}") } local.output.count('Ran 1 tests containing 1 assertions.') == participants.size() - reused(localReuse) - outcomes(localReuse, participants, TaskOutcome.UP_TO_DATE) + assertReused(localReuse) + assertOutcomes(localReuse, participants, TaskOutcome.UP_TO_DATE) where: [version, isolated, topology] << [VERSIONS, [false, true], ['siblings', 'nested']].combinations() @@ -116,40 +119,41 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { @Unroll def 'selector precedence and timing: #scenario, isolation=#isolated'() { given: - fixture('single', beforeApply, customization) - if (properties) write('gradle.properties', "$KEY=$FIRST\n") + fixture('single', configuration.beforeApply ?: '', configuration.afterApply ?: '') + if (configuration.gradleProperty != null) { + write('gradle.properties', "$KEY=${configuration.gradleProperty}\n") + } when: - def first = execute(GradleVersion.current().version, isolated, [':'], arguments) - def second = execute(GradleVersion.current().version, isolated, [':'], arguments) + def first = execute(GradleVersion.current().version, isolated, [':'], configuration.arguments ?: []) + def second = execute(GradleVersion.current().version, isolated, [':'], configuration.arguments ?: []) then: - stored(first) - outcomes(first, [':'], TaskOutcome.SUCCESS) - selected(first, [':'], expected) - reused(second) - outcomes(second, [':'], TaskOutcome.UP_TO_DATE) + assertStored(first) + assertOutcomes(first, [':'], TaskOutcome.SUCCESS) + assertSelected(first, [':'], expected) + assertReused(second) + assertOutcomes(second, [':'], TaskOutcome.UP_TO_DATE) where: - [isolated, scenario, beforeApply, customization, properties, arguments, expected] << - [false, true].collectMany { isolation -> - [ - ['absent selector retains empty list', '', "assert tasks.named('clojureTest').get().tests.get() == []", false, [], ['first', 'second']], - ['Gradle property', '', '', true, [], ['first']], - ['CLI overrides gradle.properties', '', '', true, ["-P$KEY=$SECOND"], ['second']], - ['extra before apply overrides CLI', "ext.set('$KEY', '$FIRST')", '', false, ["-P$KEY=$SECOND"], ['first']], - ['extra after apply overrides CLI', '', "ext.set('$KEY', '$FIRST')", false, ["-P$KEY=$SECOND"], ['first']], - ['last extra before realization', '', "ext.set('$KEY', '$FIRST'); ext.set('$KEY', '$SECOND')", false, [], ['second']], - ['extra after realization is too late', '', "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest').get(); ext.set('$KEY', '$SECOND')", false, [], ['first']], - ['explicit task override', '', "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest') { tests.set(['$SECOND']) }", false, ["-P$KEY=$FIRST"], ['second']], - ['explicit override after realization', '', "tasks.named('clojureTest').get().tests.set(['$SECOND'])", false, ["-P$KEY=$FIRST"], ['second']], - ['explicit empty task selection', '', "tasks.named('clojureTest') { tests.set([]) }", false, ["-P$KEY=$FIRST"], ['first', 'second']], - ['explicit absent task selection', '', "tasks.named('clojureTest') { tests.set(providers.gradleProperty('absent.selector').map { it.split(',').toList() }) }", false, ["-P$KEY=$FIRST"], ['first', 'second']], - ['comma splitting with trailing comma', '', '', false, ["-P$KEY=$FIRST,$SECOND,"], ['first', 'second']], - ['empty CLI selection', '', '', false, ["-P$KEY="], ['first', 'second']], - ['empty local extra overrides CLI', '', "ext.set('$KEY', '')", false, ["-P$KEY=$FIRST"], ['first', 'second']] - ].collect { [isolation] + it } - } + scenario | expected | configuration + 'absent selector retains empty list' | ['first', 'second'] | [afterApply: "assert tasks.named('clojureTest').get().tests.get() == []"] + 'Gradle property' | ['first'] | [gradleProperty: FIRST] + 'CLI overrides gradle.properties' | ['second'] | [gradleProperty: FIRST, arguments: ["-P$KEY=$SECOND"]] + 'extra before apply overrides CLI' | ['first'] | [beforeApply: "ext.set('$KEY', '$FIRST')", arguments: ["-P$KEY=$SECOND"]] + 'extra after apply overrides CLI' | ['first'] | [afterApply: "ext.set('$KEY', '$FIRST')", arguments: ["-P$KEY=$SECOND"]] + 'last extra before realization' | ['second'] | [afterApply: "ext.set('$KEY', '$FIRST'); ext.set('$KEY', '$SECOND')"] + 'extra after realization is too late' | ['first'] | [afterApply: "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest').get(); ext.set('$KEY', '$SECOND')"] + 'explicit task override' | ['second'] | [afterApply: "ext.set('$KEY', '$FIRST'); tasks.named('clojureTest') { tests.set(['$SECOND']) }", arguments: ["-P$KEY=$FIRST"]] + 'explicit override after realization' | ['second'] | [afterApply: "tasks.named('clojureTest').get().tests.set(['$SECOND'])", arguments: ["-P$KEY=$FIRST"]] + 'explicit empty task selection' | ['first', 'second'] | [afterApply: "tasks.named('clojureTest') { tests.set([]) }", arguments: ["-P$KEY=$FIRST"]] + 'explicit absent task selection' | ['first', 'second'] | [afterApply: "tasks.named('clojureTest') { tests.set(providers.gradleProperty('absent.selector').map { it.split(',').toList() }) }", arguments: ["-P$KEY=$FIRST"]] + 'comma splitting with trailing comma' | ['first', 'second'] | [arguments: ["-P$KEY=$FIRST,$SECOND,"]] + 'empty CLI selection' | ['first', 'second'] | [arguments: ["-P$KEY="]] + 'empty local extra overrides CLI' | ['first', 'second'] | [afterApply: "ext.set('$KEY', '')", arguments: ["-P$KEY=$FIRST"]] + + combined: + isolated << [false, true] } @Unroll @@ -166,10 +170,10 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def firstReuse = execute(GradleVersion.current().version, isolated, [':']) then: - stored(first) - selected(first, [':'], ['first']) - reused(firstReuse) - outcomes(firstReuse, [':'], TaskOutcome.UP_TO_DATE) + assertStored(first) + assertSelected(first, [':'], ['first']) + assertReused(firstReuse) + assertOutcomes(firstReuse, [':'], TaskOutcome.UP_TO_DATE) when: configureSelector(source, SECOND) @@ -177,11 +181,11 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def changedReuse = execute(GradleVersion.current().version, isolated, [':']) then: - stored(changed) - outcomes(changed, [':'], TaskOutcome.SUCCESS) - selected(changed, [':'], ['second']) - reused(changedReuse) - outcomes(changedReuse, [':'], TaskOutcome.UP_TO_DATE) + assertStored(changed) + assertOutcomes(changed, [':'], TaskOutcome.SUCCESS) + assertSelected(changed, [':'], ['second']) + assertReused(changedReuse) + assertOutcomes(changedReuse, [':'], TaskOutcome.UP_TO_DATE) where: [isolated, source] << [[false, true], ['gradle.properties', 'local extra', 'task.tests']].combinations() @@ -211,23 +215,23 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { def failed = execute(version, isolated, [':'], ["-P$KEY=selector.app-test/failing-test"], true) then: - stored(first) - selected(first, [':'], ['first']) + assertStored(first) + assertSelected(first, [':'], ['first']) failed.task(':clojureTest').outcome == TaskOutcome.FAILED failed.output.contains('selected-failure') failed.output.contains('FAIL in (failing-test)') failed.output.contains('1 failures, 0 errors.') - stored(failed) + assertStored(failed) when: def passing = execute(version, isolated, [':'], ["-P$KEY=$SECOND"]) def passingReuse = execute(version, isolated, [':'], ["-P$KEY=$SECOND"]) then: - outcomes(passing, [':'], TaskOutcome.SUCCESS) - selected(passing, [':'], ['second']) - reused(passingReuse) - outcomes(passingReuse, [':'], TaskOutcome.UP_TO_DATE) + assertOutcomes(passing, [':'], TaskOutcome.SUCCESS) + assertSelected(passing, [':'], ['second']) + assertReused(passingReuse) + assertOutcomes(passingReuse, [':'], TaskOutcome.UP_TO_DATE) where: [version, isolated] << [VERSIONS, [false, true]].combinations() @@ -273,32 +277,28 @@ class ClojureTestSelectorSpec extends BaseIntegrationTestKitSpec { fails ? runner.buildAndFail() : runner.build() } - private static boolean stored(BuildResult result) { + private static void assertStored(BuildResult result) { assert result.output.contains('Configuration cache entry stored') assert !result.output.contains('Configuration cache problems found') assert !result.output.contains('Reusing configuration cache.') - true } - private static boolean reused(BuildResult result) { + private static void assertReused(BuildResult result) { assert result.output.contains('Configuration cache entry reused') assert !result.output.contains('Configuration cache problems found') - true } - private static boolean outcomes(BuildResult result, List participants, TaskOutcome outcome) { + private static void assertOutcomes(BuildResult result, List participants, TaskOutcome outcome) { participants.each { assert result.task(taskPath(it)).outcome == outcome } - true } - private static boolean selected(BuildResult result, List participants, List expected) { + private static void assertSelected(BuildResult result, List participants, List expected) { participants.each { path -> ['first', 'second'].each { test -> assert result.output.contains("$path:selected-$test") == expected.contains(test) } } assert result.output.count("Ran ${expected.size()} tests containing ${expected.size()} assertions.") == participants.size() - true } private void write(String path, String content) {