Skip to content

Commit

Permalink
Let the testing directory be configurable. Fixes #277. Fixes #278
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Almiray committed Apr 13, 2020
1 parent 0698579 commit 8510d33
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Responsibilities:

* Create two additional configurations: `functionalTestImplementation` and `functionalTestRuntimeOnly`. These configurations
extend from `imlementation` and `runtimeOnly` respectively.
* Create a `SourceSet` named `functionalTest` pointing to `src/main/[java|groovy|kotlin|scala]`.
* Create a `Test` task named `functionalTest` pointing to `src/functional-test/[java|groovy|kotlin|scala]`.
* Create a `SourceSet` named `functionalTest` pointing to `${config.testing.functional.baseDir}/[java|groovy|kotlin|scala]`.
* Create a `Test` task named `functionalTest` pointing to `${config.testing.functional.baseDir}/[java|groovy|kotlin|scala]`.
* Create a `TestReport` task named `functionalTestReport`. This task is added as a dependency to `check`.

NOTE: You must add testing dependencies to `functionalTestImplementation` as this configuration is independent from `testImplementation`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Responsibilities:

* Create two additional configurations: `integrationTestImplementation` and `integrationTestRuntimeOnly`. These configurations
extend from `testImplementation` and `testRuntimeOnly` respectively.
* Create a `SourceSet` named `integrationTest` pointing to `src/integration-test/[java|groovy|kotlin|scala]`.
* Create a `Test` task named `integrationTest` pointing to `src/integration-test/[java|groovy|kotlin|scala]`.
* Create a `SourceSet` named `integrationTest` pointing to `${config.testing.integration.baseDir}/[java|groovy|kotlin|scala]`.
* Create a `Test` task named `integrationTest` pointing to `${config.testing.integration.baseDir}/[java|groovy|kotlin|scala]`.
* Create a `TestReport` task named `integrationTestReport`. This task is added as a dependency to `check`.

16 changes: 10 additions & 6 deletions docs/guide/src/docs/asciidoc/plugins/testing-gradle-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ config {
integration {
logging
aggregate
baseDir
}
functional {
logging
aggregate
baseDir
}
}
}
Expand All @@ -47,19 +49,21 @@ config {

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| logging | boolean | no | true | Enables verbose output
| aggregate | boolean | no | true | Enables test report aggregation
| Name | Type | Required | Default Value | Description
| logging | boolean | no | true | Enables verbose output
| aggregate | boolean | no | true | Enables test report aggregation
| baseDir | String | no | src/integration-test |
|===

[[_testing_functional]]
*functional*

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| logging | boolean | no | true | Enables verbose output
| aggregate | boolean | no | true | Enables test report aggregation
| Name | Type | Required | Default Value | Description
| logging | boolean | no | true | Enables verbose output
| aggregate | boolean | no | true | Enables test report aggregation
| baseDir | String | no | src/functional-test |
|===

[[_org_kordamp_gradle_testing_tasks]]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ targetCompatibility = 1.8

kordampPluginVersion = 0.33.0
spockVersion = 1.3-groovy-2.5
bintrayVersion = 1.8.4
bintrayVersion = 1.8.5
kotlinVersion = 1.3.71
detektVersion = 1.7.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,16 @@ class ProjectConfigurationExtension {
plugin.normalize()
publishing.normalize()
docs.normalize()
coverage.normalize()
quality.normalize()
this
}

ProjectConfigurationExtension postMerge() {
testing.postMerge()
docs.postMerge()
quality.postMerge()
coverage.postMerge()
stats.postMerge()
this
}

Expand Down Expand Up @@ -688,8 +690,8 @@ class ProjectConfigurationExtension {
o1
}

Coverage normalize() {
jacoco.normalize()
Coverage postMerge() {
jacoco.postMerge()
this
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package org.kordamp.gradle.plugin.base.plugins
import groovy.transform.Canonical
import groovy.transform.CompileStatic

import static org.kordamp.gradle.StringUtils.isNotBlank

/**
* @author Andres Almiray
* @since 0.14.0
Expand All @@ -31,6 +33,7 @@ class Functional {

boolean logging = true
boolean aggregate = true
String baseDir

private boolean loggingSet = false
private boolean aggregateSet = false
Expand Down Expand Up @@ -67,7 +70,8 @@ class Functional {
Map<String, Object> toMap() {
new LinkedHashMap<>([
logging : logging,
aggregate: aggregate
aggregate: aggregate,
baseDir : baseDir
])
}

Expand All @@ -76,6 +80,7 @@ class Functional {
copy.@loggingSet = loggingSet
copy.@aggregate = aggregate
copy.@aggregateSet = aggregateSet
copy.@baseDir = baseDir
}

static void merge(Functional o1, Functional o2) {
Expand All @@ -86,5 +91,10 @@ class Functional {
boolean thisAggregate = (boolean) (o1.aggregateSet ? o1.aggregate : o2.aggregate)
boolean superAggregate = (boolean) (o1.test.aggregateSet) ? o1.test.aggregate : o2.aggregate
o1.setAggregate(thisAggregate ?: superAggregate)
o1.setBaseDir(isNotBlank(o1.baseDir) ? o1.baseDir : o2.baseDir)
}

void postMerge() {
baseDir = baseDir ?: 'src/functional-test'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package org.kordamp.gradle.plugin.base.plugins
import groovy.transform.Canonical
import groovy.transform.CompileStatic

import static org.kordamp.gradle.StringUtils.isNotBlank

/**
* @author Andres Almiray
* @since 0.14.0
Expand All @@ -31,6 +33,7 @@ class Integration {

boolean logging = true
boolean aggregate = true
String baseDir

private boolean loggingSet = false
private boolean aggregateSet = false
Expand Down Expand Up @@ -67,7 +70,8 @@ class Integration {
Map<String, Object> toMap() {
new LinkedHashMap<String, Object>([
logging : logging,
aggregate: aggregate
aggregate: aggregate,
baseDir : baseDir
])
}

Expand All @@ -76,10 +80,16 @@ class Integration {
copy.@loggingSet = loggingSet
copy.@aggregate = aggregate
copy.@aggregateSet = aggregateSet
copy.@baseDir = baseDir
}

static void merge(Integration o1, Integration o2) {
o1.setLogging((boolean) (o1.loggingSet ? o1.logging : (o2.loggingSet ? o2.logging : (o1.test.loggingSet ? o1.test.logging : o2.test.logging))))
o1.setAggregate((boolean) (o1.aggregateSet ? o1.aggregate : (o2.aggregateSet ? o2.aggregate : (o1.test.aggregateSet ? o1.test.aggregate : o2.test.aggregate))))
o1.setBaseDir(isNotBlank(o1.baseDir) ? o1.baseDir : o2.baseDir)
}

void postMerge() {
baseDir = baseDir ?: 'src/integration-test'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Jacoco extends AbstractFeature {
new LinkedHashMap<>('jacoco': map)
}

void normalize() {
void postMerge() {
if (!enabledSet) {
if (isRoot()) {
if (project.childProjects.isEmpty()) {
Expand All @@ -136,8 +136,8 @@ class Jacoco extends AbstractFeature {

boolean hasTestSourceSets() {
hasTestsAt(project.file('src/test')) ||
hasTestsAt(project.file('src/integration-test')) ||
hasTestsAt(project.file('src/functional-test'))
hasTestsAt(project.file(config.testing.integration.baseDir)) ||
hasTestsAt(project.file(config.testing.functional.baseDir))
}

private static boolean hasTestsAt(File testDir) {
Expand All @@ -156,7 +156,7 @@ class Jacoco extends AbstractFeature {
}

static void merge(Jacoco o1, Jacoco o2) {
AbstractFeature.merge(o1, o2)
// AbstractFeature.merge(o1, o2)
o1.aggregateExecFile = o1.aggregateExecFile ?: o2.aggregateExecFile
o1.aggregateReportHtmlFile = o1.aggregateReportHtmlFile ?: o2.aggregateReportHtmlFile
o1.aggregateReportXmlFile = o1.aggregateReportXmlFile ?: o2.aggregateReportXmlFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Stats extends AbstractAggregateFeature {

Stats(ProjectConfigurationExtension config, Project project) {
super(config, project, PLUGIN_ID, 'stats')
paths.putAll(defaultPaths())
}

@Override
Expand All @@ -55,7 +54,7 @@ class Stats extends AbstractAggregateFeature {
map.paths = paths
}

static Map<String, Map<String, String>> defaultPaths() {
private Map<String, Map<String, String>> defaultPaths() {
Map<String, Map<String, String>> basePaths = [:]

[
Expand All @@ -75,9 +74,12 @@ class Stats extends AbstractAggregateFeature {
yaml : 'YAML',
clojure : 'Clojure'
].each { extension, name ->
['test', 'integration-test', 'functional-test'].each { source ->
String classifier = getPropertyNameForLowerCaseHyphenSeparatedName(source)
basePaths[classifier + extension.capitalize()] = [name: name + ' ' + getNaturalName(classifier) + ' Sources', path: 'src/' + source, extension: extension]
['src/test',
config.testing.integration.baseDir,
config.testing.functional.baseDir].each { source ->
String[] parts = source.split(File.separator)
String classifier = getPropertyNameForLowerCaseHyphenSeparatedName(parts[-1])
basePaths[classifier + extension.capitalize()] = [name: name + ' ' + getNaturalName(classifier) + ' Sources', path: source, extension: extension]
}
}

Expand Down Expand Up @@ -116,4 +118,11 @@ class Stats extends AbstractAggregateFeature {
o1.paths.putAll(o2.paths)
CollectionUtils.merge(o1.formats, o2?.formats)
}

void postMerge() {
Map<String, Map<String, String>> mergedPaths = [:]
mergedPaths.putAll(defaultPaths())
mergedPaths.putAll(paths)
paths.putAll(mergedPaths)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class Testing extends AbstractFeature {
Functional.merge(o1.functional, o2.functional)
}

void postMerge() {
integration.postMerge()
functional.postMerge()
}

Set<Test> testTasks() {
testTasks
}
Expand Down
Loading

0 comments on commit 8510d33

Please sign in to comment.