szpak / gradle-pitest-plugin

Gradle plugin for PIT Mutation Testing
http://gradle-pitest-plugin.solidsoft.info/
212 stars 57 forks source link

Skip Pitest task execution test when source set is empty #294

Open davidburstrom opened 2 years ago

davidburstrom commented 2 years ago

For a regular Gradle test task from the Java plugin, if there is no test source, it will just be skipped indicating NO-SOURCE. In contrast, Pitest tasks will fail with Coverage generation minion exited abnormally. I propose that the Pitest tasks should behave similarly as the test task. As for backwards compatibility, this would cause e.g. CI builds that are currently failing to pass instead, but I have a hard time seeing that as a problem.

The current workaround I use is pretty hard-coded (and deals with configuration caching, hence it looks a little weird):

tasks.named<PitestTask>("pitest").configure {
  inputs.property("src", file("src/test"))
  onlyIf {
    (inputs.properties.get("src") as File).exists()
  }
}
szpak commented 2 years ago

It sounds sensible. Currently the plugin is applied only on subprojects with the Java plugin, but no test source in fact could lead to that behavior. Nevertheless, in a corner case, there could be only some test content attached from some other subprojects (e.g. with the acceptance tests).

https://github.com/szpak/gradle-pitest-plugin/blob/c54467b6698ad17e3884fcb8ef97bf2322c05e4e/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy#L175-L182

Do you think that checking if additionalClasspath has some entries would be sufficient? Or you have some better proposal?

szpak commented 2 years ago

Btw, it is slightly related to #292 (in terms of behavior).

davidburstrom commented 2 years ago

The additionalClasspath has entries from the main source set (which for all practical purposes definitely should have entries) as well as test runtime classpath elements, so that won't work.

I was thinking that it should be sufficient to check if project.objects.fileCollection().from(extensions.testSourceSets.get() as Set<SourceSet>)*.allSource) is non-empty, but haven't verified that theory.

szpak commented 2 years ago

Yes, testRuntimeClasspath extends the main classpath.

Maybe, but source sets were always somehow specific for me and it would have to be verified :-).

davidburstrom commented 2 years ago

It is of course true that the test classpath can contain the test cases, imported from another project. I'm not sure if that is a sufficiently common case...

Using @SkipWhenEmpty @InputFiles on a property populated accordingly should result in a NO-SOURCE status. Not that it's critical that the status is the same as for a Test task.

Gradle Test solves it by having a testClassesDirs property which is separate from the test runtime classpath.

esfomeado commented 1 year ago

Any plans of when this would be available.

So far I have to exclude certain modules from running the pitest task.