Skip to content

Commit

Permalink
Fix testing for name based filtering of tasks (#28433)
Browse files Browse the repository at this point in the history
  • Loading branch information
bot-gradle committed Mar 12, 2024
2 parents 531f735 + 8dfff26 commit 5fa8744
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,67 @@ trait AbstractTaskContainerIntegrationTest {

class TaskContainerIntegrationTest extends AbstractDomainObjectContainerIntegrationTest implements AbstractTaskContainerIntegrationTest {

@Issue("https://github.com/gradle/gradle/issues/28347")
def "filtering is lazy (`#filtering` + `#configAction`)"() {
given:
buildFile """
tasks.configureEach { println("configured \$path") }

tasks.$filtering.$configAction

tasks.register("foo", Copy)
tasks.register("bar", Delete)
"""
when:
succeeds "help"
then:
// help task is realized and configured
outputContains("configured :help")
// are "built-in" tasks realized and configured?
if (realizesBuiltInTasks) {
outputContains("configured :tasks")
outputContains("configured :projects")
} else {
outputDoesNotContain("configured :tasks")
outputDoesNotContain("configured :projects")
}
// are explicitly registered tasks realized and configured?
if (realizesExplicitTasks) {
outputContains("configured :foo")
outputContains("configured :bar")
} else {
outputDoesNotContain("configured :foo")
outputDoesNotContain("configured :bar")
}
where:
filtering | configAction | realizesBuiltInTasks | realizesExplicitTasks
"named { it == \"help\" }" | "all {}" | true | true
"named { it == \"help\" }" | "forEach {}" | true | false
"named { it == \"help\" }" | "configureEach {}" | false | false
"named { it == \"help\" }" | "toList()" | true | false
"named { it == \"help\" }" | "iterator()" | true | false
// TODO: no other tasks should be realized, that was the intent of having the new `named()` method
"matching { it.name == \"help\" }" | "all {}" | true | true
"matching { it.name == \"help\" }" | "forEach {}" | true | false
"matching { it.name == \"help\" }" | "configureEach {}" | false | false
"matching { it.name == \"help\" }" | "toList()" | true | false
"matching { it.name == \"help\" }" | "iterator()" | true | false
"matching { it.group == \"help\" }" | "all {}" | true | true
"matching { it.group == \"help\" }" | "forEach {}" | true | false
"matching { it.group == \"help\" }" | "configureEach {}" | false | false
"matching { it.group == \"help\" }" | "toList()" | true | false
"matching { it.group == \"help\" }" | "iterator()" | true | false
}
def "chained lookup of tasks.withType.matching"() {
buildFile """
tasks.withType(Copy).matching({ it.name.endsWith("foo") }).all { task ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1603,43 +1603,6 @@ class DefaultTaskContainerTest extends AbstractPolymorphicDomainObjectContainerS
container.size() == 2
}
def "name based filtering does not realize pending"() {
given: "a few realized tasks"
1 * taskFactory.create(_ as TaskIdentity, _) >> task("r1")
container.create("r1")
1 * taskFactory.create(_ as TaskIdentity, _) >> task("r2")
container.create("r2")
1 * taskFactory.create(_ as TaskIdentity, _) >> task("r3")
container.create("r3")
and: "a few registered task"
def action = Mock(Action)
container.configureEach(action)
container.register("t1")
container.register("t2")
container.register("t3")
when: "name based filtering is applied"
def filtered = container.named { !it.contains("2") }
then: "the right task are filtered out"
filtered.names.toList() == ["r1", "r3", "t1", "t3"]
and: "no registered tasks get realized"
0 * action.execute(_)
when: "the filtered collection is iterated"
1 * taskFactory.create(_ as TaskIdentity, _) >> task("t1")
1 * taskFactory.create(_ as TaskIdentity, _) >> task("t3")
filtered.toList()
then: "filtered out registered tasks aren't realized"
2 * action.execute(_)
}
private ProjectInternal expectTaskLookupInOtherProject(final String projectPath, final String taskName, def task) {
def otherProject = Mock(ProjectInternal)
def otherTaskContainer = Mock(TaskContainerInternal)
Expand Down

0 comments on commit 5fa8744

Please sign in to comment.