Skip to content

Commit

Permalink
Support java-test-fixtures plugin
Browse files Browse the repository at this point in the history
Applying 'java-test-fixtures' plugin caused 'No mutations found'
from Pitest.

The plugin changes test runtime classpath:
tested code is included as a JAR instead of as a directory
(see gradle/gradle#11696). It seems that Pitest ignores correct
directories being passed using --mutableCodePaths and insists on
having those directories also passed in --classPath.

Also change functional tests: runTasksSuccessfully() fails the test
without giving any context, so it should be avoided.
  • Loading branch information
pkubowicz committed Jul 27, 2020
1 parent 7513387 commit 8a5c9c5
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class Junit5FunctionalSpec extends AbstractPitestFunctionalSpec {
given:
copyResources("testProjects/junit5kotlin", "")
when:
ExecutionResult result = runTasksSuccessfully('pitest')
ExecutionResult result = runTasks('pitest')
then:
!result.standardError.contains("Build failed with an exception")
!result.failure
result.wasExecuted('pitest')
result.standardOutput.contains('Generated 2 mutations Killed 2 (100%)')
}
Expand All @@ -21,8 +23,10 @@ class Junit5FunctionalSpec extends AbstractPitestFunctionalSpec {
given:
copyResources("testProjects/junit5kotlin", "")
when:
ExecutionResult result = runTasksSuccessfully('pitest', '-b', 'build.gradle.kts')
ExecutionResult result = runTasks('pitest')
then:
!result.standardError.contains("Build failed with an exception")
!result.failure
result.wasExecuted('pitest')
result.standardOutput.contains('Generated 2 mutations Killed 2 (100%)')
}
Expand All @@ -32,8 +36,10 @@ class Junit5FunctionalSpec extends AbstractPitestFunctionalSpec {
given:
copyResources("testProjects/junit5simple", "")
when:
ExecutionResult result = runTasksSuccessfully('pitest')
ExecutionResult result = runTasks('pitest')
then:
!result.standardError.contains("Build failed with an exception")
!result.failure
result.wasExecuted('pitest')
and:
result.standardOutput.contains('--testPlugin=junit5')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package info.solidsoft.gradle.pitest.functional

import groovy.transform.CompileDynamic
import nebula.test.functional.ExecutionResult

@CompileDynamic
class TestFixturesFunctionalSpec extends AbstractPitestFunctionalSpec {

void "should work with kotlin and test fixtures"() {
given:
copyResources("testProjects/testFixtures", "")
when:
ExecutionResult result = runTasks('pitest')
then:
!result.standardError.contains("Build failed with an exception")
!result.failure
result.wasExecuted('pitest')
result.standardOutput.contains('Generated 1 mutations Killed 1 (100%)')
}

}
24 changes: 24 additions & 0 deletions src/funcTest/resources/testProjects/testFixtures/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'info.solidsoft.pitest'

buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
//Local/current version of the plugin should be put on a classpath earlier to override that plugin version
// classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.7-SNAPSHOT'
}
}

repositories {
mavenCentral()
}

group = "pitest.test"

dependencies {
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'testFixtures'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pitest.test;

public class Library {
public boolean someLibraryMethod() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pitest.test;

import org.junit.Test;
import pitest.test.Library;

import static org.junit.Assert.*;

public class LibraryTest {
@Test public void testSomeLibraryMethod() {
Library classUnderTest = new Library();
assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod());
}
}
11 changes: 6 additions & 5 deletions src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,20 @@ class PitestPlugin implements Plugin<Project> {
task.sourceDirs.setFrom(extension.mainSourceSets.map { mainSourceSet -> mainSourceSet*.allSource*.srcDirs })
task.detectInlinedCode.set(extension.detectInlinedCode)
task.timestampedReports.set(extension.timestampedReports)
Callable<Set<File>> allMutableCodePaths = {
calculateBaseMutableCodePaths() + (extension.additionalMutableCodePaths.getOrElse([] as Set) as Set<File>)
}
task.additionalClasspath.setFrom({
List<FileCollection> testRuntimeClasspath = (extension.testSourceSets.get() as Set<SourceSet>)*.runtimeClasspath
FileCollection combinedTaskClasspath = project.objects.fileCollection().from(testRuntimeClasspath)
FileCollection filteredCombinedTaskClasspath = combinedTaskClasspath.filter { File file ->
!extension.fileExtensionsToFilter.getOrElse([]).find { extension -> file.name.endsWith(".$extension") }
}
!extension.fileExtensionsToFilter.getOrElse([]).find { extension -> file.name.endsWith(".$extension") || file == "core.jar" }
} + project.files(allMutableCodePaths)
return filteredCombinedTaskClasspath
} as Callable<FileCollection>)
task.useAdditionalClasspathFile.set(extension.useClasspathFile)
//additionalClasspathFile - separate method
task.mutableCodePaths.setFrom({
calculateBaseMutableCodePaths() + (extension.additionalMutableCodePaths.getOrElse([] as Set) as Set<File>)
} as Callable<Set<File>>)
task.mutableCodePaths.setFrom(allMutableCodePaths)
task.historyInputLocation.set(extension.historyInputLocation)
task.historyOutputLocation.set(extension.historyOutputLocation)
task.enableDefaultIncrementalAnalysis.set(extension.enableDefaultIncrementalAnalysis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ class PitestTaskConfigurationSpec extends BasicProjectBuilderSpec implements Wit
project.sourceSets { intTest }
project.pitest.testSourceSets = [project.sourceSets.intTest]
expect:
task.taskArgumentMap()['classPath'] == assembleSourceSetsClasspathByNameAsStringSet("intTest").join(",")
task.taskArgumentMap()['classPath'] ==
(
assembleSourceSetsClasspathByNameAsStringSet("intTest") +
["${project.buildDir}/classes/java/main"]
).join(",")
}
private Set<String> assembleSourceSetsClasspathByNameAsStringSet(List<String> sourceSetNames) {
Expand All @@ -254,8 +258,8 @@ class PitestTaskConfigurationSpec extends BasicProjectBuilderSpec implements Wit
}
private Set<String> assembleSourceSetsClasspathByNameAsStringSet(String sourceSetName) {
return [new File(project.buildDir, "classes//java//${sourceSetName}"),
new File(project.buildDir, "resources//${sourceSetName}")
return [new File(project.buildDir, "classes/java/${sourceSetName}"),
new File(project.buildDir, "resources/${sourceSetName}")
]*.absolutePath
}
Expand Down

0 comments on commit 8a5c9c5

Please sign in to comment.