Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support java-test-fixtures plugin #223

Merged
merged 2 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
pkubowicz marked this conversation as resolved.
Show resolved Hide resolved
then:
!result.standardError.contains("Build failed with an exception")
szpak marked this conversation as resolved.
Show resolved Hide resolved
!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', '-b', 'build.gradle.kts')
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 java-test-fixtures plugin"() {
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());
}
}
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") }
}
} + 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 @@ -233,30 +233,37 @@ class PitestTaskConfigurationSpec extends BasicProjectBuilderSpec implements Wit
sourceDirs == assembleMainSourceDirAsStringSet().join(",")
}

private Set<String> assembleMainSourceDirAsStringSet() {
return ["resources", "java"].collect { String dirName ->
new File(project.projectDir, "src//main//${dirName}")
}*.absolutePath
}

void "should consider testSourceSets in (additional) classpath"() {
given:
project.sourceSets { intTest }
project.pitest.testSourceSets = [project.sourceSets.intTest]
expect:
task.taskArgumentMap()['classPath'] == assembleSourceSetsClasspathByNameAsStringSet("intTest").join(",")
task.taskArgumentMap()['classPath'].split(",") as Set ==
[
sourceSetBuiltJavaClasses("intTest"),
sourceSetBuiltResources("intTest"),
sourceSetBuiltJavaClasses("main")
] as Set
}

private Set<String> assembleSourceSetsClasspathByNameAsStringSet(List<String> sourceSetNames) {
return sourceSetNames.collectMany { String sourceSetName ->
assembleSourceSetsClasspathByNameAsStringSet(sourceSetName)
[sourceSetBuiltJavaClasses(sourceSetName), sourceSetBuiltResources(sourceSetName)]
} as Set<String>
}

private Set<String> assembleSourceSetsClasspathByNameAsStringSet(String sourceSetName) {
return [new File(project.buildDir, "classes//java//${sourceSetName}"),
new File(project.buildDir, "resources//${sourceSetName}")
]*.absolutePath
private Set<String> assembleMainSourceDirAsStringSet() {
return ["resources", "java"].collect { String dirName ->
new File(project.projectDir, "src/main/${dirName}")
}*.absolutePath
}

private String sourceSetBuiltJavaClasses(String sourceSetName) {
return new File(project.buildDir, "classes/java/${sourceSetName}").absolutePath
}

private String sourceSetBuiltResources(String sourceSetName) {
return new File(project.buildDir, "resources/${sourceSetName}").absolutePath
}

}