Skip to content

Fix configuration of coverage type check #123

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

Merged
merged 1 commit into from
Nov 19, 2019
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 @@ -26,6 +26,7 @@ test {

scoverage {
minimumRate = 0.3
coverageType = "Line"
}

if (hasProperty("excludedFile")) {
Expand Down
25 changes: 19 additions & 6 deletions src/main/groovy/org/scoverage/OverallCheckTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ import java.text.NumberFormat
* Handles different types of coverage Scoverage can measure.
*/
enum CoverageType {
Line('cobertura.xml', 'line-rate', 1.0),
Statement('scoverage.xml', 'statement-rate', 100.0),
Branch('scoverage.xml', 'branch-rate', 100.0)
Line('Line', 'cobertura.xml', 'line-rate', 1.0),
Statement('Statement', 'scoverage.xml', 'statement-rate', 100.0),
Branch('Branch', 'scoverage.xml', 'branch-rate', 100.0)

/** Name of enum option the way it appears in the build configuration */
String configurationName
/** Name of file with coverage data */
String fileName
/** Name of param in XML file with coverage value */
String paramName
/** Used to normalize coverage value */
private double factor

private CoverageType(String fileName, String paramName, double factor) {
private CoverageType(String configurationName, String fileName, String paramName, double factor) {
this.configurationName = configurationName
this.fileName = fileName
this.paramName = paramName
this.factor = factor
Expand All @@ -36,6 +39,12 @@ enum CoverageType {
Double normalize(Double value) {
return value / factor
}

static CoverageType find(String configurationName) {
CoverageType.values().find {
it.configurationName.toLowerCase() == configurationName.toLowerCase()
}
}
}

/**
Expand All @@ -46,7 +55,7 @@ class OverallCheckTask extends DefaultTask {

/** Type of coverage to check. Available options: Line, Statement and Branch */
@Input
final Property<CoverageType> coverageType = project.objects.property(CoverageType)
final Property<String> coverageType = project.objects.property(String)
@Input
final Property<BigDecimal> minimumRate = project.objects.property(BigDecimal)

Expand All @@ -61,7 +70,11 @@ class OverallCheckTask extends DefaultTask {
void requireLineCoverage() {
NumberFormat nf = NumberFormat.getInstance(locale.get())

Exception failure = checkLineCoverage(nf, reportDir.get(), coverageType.get(), minimumRate.get().doubleValue())
CoverageType coverageType = CoverageType.find(this.coverageType.get())
if (coverageType == null) {
throw new GradleException("Unknown coverage type ${this.coverageType.get()}")
}
Exception failure = checkLineCoverage(nf, reportDir.get(), coverageType, minimumRate.get().doubleValue())

if (failure) throw failure
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ScoverageExtension {

final Property<Boolean> deleteReportsOnAggregation

final Property<CoverageType> coverageType
final Property<String> coverageType
final Property<BigDecimal> minimumRate

ScoverageExtension(Project project) {
Expand Down Expand Up @@ -87,8 +87,8 @@ class ScoverageExtension {
deleteReportsOnAggregation = project.objects.property(Boolean)
deleteReportsOnAggregation.set(false)

coverageType = project.objects.property(CoverageType)
coverageType.set(CoverageType.Statement)
coverageType = project.objects.property(String)
coverageType.set(CoverageType.Statement.configurationName)

minimumRate = project.objects.property(BigDecimal)
minimumRate.set(0.75)
Expand Down