Plugin tests using "project.tasks['test']" worked in 4.7 but fail with 4.8+

(Richard Richter) #1

Hello master builders

I wanted to modify a plugin from this repo
I downloaded it and ./gradlew clean build worked just fine, all 4 tests passed.
I upgraded the version of Gradle to 4.10.2 (later confirmed the problem starts with 4.8) and it started to fail on two tests using:

    def t = project.tasks['test']

Working test uses:

def t = project.tasks.create("myJavaExec", JavaExec) {...}

Execute does not fail, but this plugin tests whether custom TaskActionListener gets executed and in second case it doesn’t. Execution path seems to diverge in SkipEmptySourceFilesTaskExecuter.execute(...) on a line with:

if (taskProperties.hasSourceFiles() && sourceFiles.isEmpty()) {

Here the first condition returns consistently false in Gradle 4.7 but true for tests working with “:test” task. It all ends with info log: “Skipping {} as it has no source files and no previous output files.”

Now I don’t know whether this is a regression or the test is flawed and had some design problem that popped up after Gradle upgrade. Test source can be found here on GitHub.

How to write the test so it does test the action listener on a “:test” task and really executes it with its listener? Obviously it’s not easy to Google for “Gradle plugin testing using test task”. :slight_smile: Too many “test” words there.

Thank you very much
Richard “Virgo” Richter