Skip to content

Commit 780dad5

Browse files
committed
Merge remote-tracking branch 'eyalroth/issues/93/multiple-check-tasks'
2 parents 2ae36a2 + d3663ca commit 780dad5

File tree

29 files changed

+615
-192
lines changed

29 files changed

+615
-192
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,51 @@ be overridden by the version of the `scala-library` compile dependency (if the d
5555
* `minimumRate = <double>` (default `0.75`): The minimum amount of coverage in decimal proportion (`1.0` == 100%)
5656
required for the validation to pass (otherwise `checkScoverage` will fail the build).
5757

58-
* `coverageType = <"Statement" | "Branch" | "Line">` (default `"Statement"`): The type of coverage validated by the
58+
* `coverageType = <CoverageType.Statement | CoverageType.Branch | CoverageType.Line>` (default `CoverageType.Statement`): The type of coverage validated by the
5959
`checkScoverage` task. For more information on the different types, please refer to the documentation of the scalac
6060
plugin (https://github.com/scoverage/scalac-scoverage-plugin).
6161

62+
#### Multiple check tasks
63+
64+
It is possible to configure multiple checks; for instance, one check for a statement rate and another for a branch rate:
65+
```
66+
scoverage {
67+
check {
68+
minimumRate = 0.5
69+
coverageType = CoverageType.Statement
70+
}
71+
check {
72+
minimumRate = 0.8
73+
coverageType = CoverageType.Branch
74+
}
75+
}
76+
```
77+
78+
Note that you cannot mix multiple-checks syntax with plain check configuration:
79+
```
80+
// ok
81+
scoverage {
82+
check {
83+
minimumRate = 0.5
84+
coverageType = CoverageType.Statement
85+
}
86+
}
87+
88+
// ok
89+
scoverage {
90+
minimumRate = 0.2
91+
}
92+
93+
// NOT ok
94+
scoverage {
95+
minimumRate = 0.2
96+
check {
97+
minimumRate = 0.5
98+
coverageType = CoverageType.Statement
99+
}
100+
}
101+
```
102+
62103
### Run without normal compilation
63104

64105
By default, running any of the plugin tasks will compile the code both using "normal" compilation (`compileScala`)

build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ sourceCompatibility = '1.8'
4545
targetCompatibility = '1.8'
4646

4747
dependencies {
48-
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.4.0"
49-
compile group: 'commons-io', name: 'commons-io', version: '2.6'
50-
testCompile 'junit:junit:4.12'
51-
testCompile 'org.hamcrest:hamcrest-library:1.3'
48+
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.4.1"
49+
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
50+
51+
testImplementation 'junit:junit:4.12'
52+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
53+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2'
54+
55+
testImplementation 'org.hamcrest:hamcrest-library:1.3'
5256
}
5357

5458
sourceSets {
5559
functionalTest {
5660
java.srcDir file('src/functionalTest/java')
5761
resources.srcDir file('src/functionalTest/resources')
58-
compileClasspath += sourceSets.main.output + configurations.testRuntime
62+
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
5963
runtimeClasspath += output + compileClasspath
6064
}
6165
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.scoverage;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public abstract class MultipleCheckTasksTest extends ScoverageFunctionalTest {
7+
8+
/* --- Abstract Test ---- */
9+
10+
private final boolean shouldSucceed;
11+
12+
public MultipleCheckTasksTest(String projectDir, boolean shouldSucceed) {
13+
super("multiple-check-tasks/" + projectDir);
14+
this.shouldSucceed = shouldSucceed;
15+
}
16+
17+
@Test
18+
public void test() {
19+
assertResult(run());
20+
}
21+
22+
protected abstract void assertResult(AssertableBuildResult result);
23+
24+
protected void assertOutput(AssertableBuildResult result, CoverageType type, double minimumRate) {
25+
String expectedMessage = String.format("Checking coverage. Type: %s. Minimum rate: %s", type, minimumRate);
26+
Assert.assertTrue(result.getResult().getOutput().contains(expectedMessage));
27+
}
28+
29+
private AssertableBuildResult run() {
30+
if (shouldSucceed) {
31+
return run("clean", ScoveragePlugin.getCHECK_NAME(), "--info");
32+
} else {
33+
return runAndFail(ScoveragePlugin.getCHECK_NAME(), "--info");
34+
}
35+
}
36+
37+
/* --- Test Classes ---- */
38+
39+
public static class MultipleChecks extends MultipleCheckTasksTest {
40+
public MultipleChecks() {
41+
super("multiple-checks", true);
42+
}
43+
@Override
44+
protected void assertResult(AssertableBuildResult result) {
45+
46+
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
47+
assertOutput(result, CoverageType.Line, 0.3);
48+
assertOutput(result, CoverageType.Branch, 0.1);
49+
assertOutput(result, CoverageType.Statement, 0.6);
50+
51+
}
52+
}
53+
public static class SingleCheckNewSyntax extends MultipleCheckTasksTest {
54+
public SingleCheckNewSyntax() {
55+
super("single-check-new-syntax", true);
56+
}
57+
@Override
58+
protected void assertResult(AssertableBuildResult result) {
59+
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
60+
assertOutput(result, CoverageType.Line, 0.3);
61+
}
62+
}
63+
public static class SingleCheckOldSyntax extends MultipleCheckTasksTest {
64+
public SingleCheckOldSyntax() {
65+
super("single-check-old-syntax", true);
66+
}
67+
@Override
68+
protected void assertResult(AssertableBuildResult result) {
69+
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
70+
assertOutput(result, CoverageType.Line, 0.3);
71+
}
72+
}
73+
public static class OldAndNewSyntax extends MultipleCheckTasksTest {
74+
public OldAndNewSyntax() {
75+
super("old-and-new-syntax", false);
76+
}
77+
@Override
78+
protected void assertResult(AssertableBuildResult result) {
79+
}
80+
}
81+
public static class NoCheck extends MultipleCheckTasksTest {
82+
public NoCheck() {
83+
super("no-check", true);
84+
}
85+
@Override
86+
protected void assertResult(AssertableBuildResult result) {
87+
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
88+
assertOutput(result, ScoverageExtension.DEFAULT_COVERAGE_TYPE, ScoverageExtension.DEFAULT_MINIMUM_RATE);
89+
}
90+
}
91+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'org.scoverage'
3+
}
4+
5+
repositories {
6+
jcenter()
7+
}
8+
9+
description = 'a single-module Scala project that has multiple check configurations'
10+
11+
apply plugin: 'java'
12+
apply plugin: 'scala'
13+
14+
dependencies {
15+
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
16+
17+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
18+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
19+
20+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
21+
}
22+
23+
test {
24+
useJUnitPlatform()
25+
}
26+
27+
scoverage {
28+
check {
29+
minimumRate = 0.3
30+
coverageType = org.scoverage.CoverageType.Line
31+
}
32+
check {
33+
minimumRate = 0.1
34+
coverageType = org.scoverage.CoverageType.Branch
35+
}
36+
check {
37+
minimumRate = 0.6
38+
coverageType = org.scoverage.CoverageType.Statement
39+
}
40+
}

src/functionalTest/resources/projects/multiple-check-tasks/multiple-checks/settings.gradle

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hello
2+
3+
class World {
4+
5+
def foo(): String = {
6+
"a" + "b"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.hello
2+
3+
import org.junit.runner.RunWith
4+
import org.scalatest.FunSuite
5+
import org.scalatest.junit.JUnitRunner
6+
7+
@RunWith(classOf[JUnitRunner])
8+
class WorldSuite extends FunSuite {
9+
10+
test("foo") {
11+
new World().foo()
12+
}
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id 'org.scoverage'
3+
}
4+
5+
repositories {
6+
jcenter()
7+
}
8+
9+
description = 'a single-module Scala project with no check configured'
10+
11+
apply plugin: 'java'
12+
apply plugin: 'scala'
13+
14+
dependencies {
15+
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
16+
17+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
18+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
19+
20+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
21+
}
22+
23+
test {
24+
useJUnitPlatform()
25+
}

src/functionalTest/resources/projects/multiple-check-tasks/no-check/settings.gradle

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hello
2+
3+
class World {
4+
5+
def foo(): String = {
6+
"a" + "b"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.hello
2+
3+
import org.junit.runner.RunWith
4+
import org.scalatest.FunSuite
5+
import org.scalatest.junit.JUnitRunner
6+
7+
@RunWith(classOf[JUnitRunner])
8+
class WorldSuite extends FunSuite {
9+
10+
test("foo") {
11+
new World().foo()
12+
}
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'org.scoverage'
3+
}
4+
5+
repositories {
6+
jcenter()
7+
}
8+
9+
description = 'a single-module Scala project that has multiple check configurations - some new syntax, some old'
10+
11+
apply plugin: 'java'
12+
apply plugin: 'scala'
13+
14+
dependencies {
15+
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
16+
17+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
18+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
19+
20+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
21+
}
22+
23+
test {
24+
useJUnitPlatform()
25+
}
26+
27+
scoverage {
28+
minimumRate = 0.3
29+
coverageType = org.scoverage.CoverageType.Line
30+
check {
31+
minimumRate = 0.1
32+
coverageType = org.scoverage.CoverageType.Branch
33+
}
34+
check {
35+
minimumRate = 0.6
36+
coverageType = org.scoverage.CoverageType.Statement
37+
}
38+
}

src/functionalTest/resources/projects/multiple-check-tasks/old-and-new-syntax/settings.gradle

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hello
2+
3+
class World {
4+
5+
def foo(): String = {
6+
"a" + "b"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.hello
2+
3+
import org.junit.runner.RunWith
4+
import org.scalatest.FunSuite
5+
import org.scalatest.junit.JUnitRunner
6+
7+
@RunWith(classOf[JUnitRunner])
8+
class WorldSuite extends FunSuite {
9+
10+
test("foo") {
11+
new World().foo()
12+
}
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id 'org.scoverage'
3+
}
4+
5+
repositories {
6+
jcenter()
7+
}
8+
9+
description = 'a single-module Scala project that has a single check configurations (with the new syntax)'
10+
11+
apply plugin: 'java'
12+
apply plugin: 'scala'
13+
14+
dependencies {
15+
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
16+
17+
testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
18+
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
19+
20+
testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
21+
}
22+
23+
test {
24+
useJUnitPlatform()
25+
}
26+
27+
scoverage {
28+
check {
29+
minimumRate = 0.3
30+
coverageType = org.scoverage.CoverageType.Line
31+
}
32+
}

src/functionalTest/resources/projects/multiple-check-tasks/single-check-new-syntax/settings.gradle

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hello
2+
3+
class World {
4+
5+
def foo(): String = {
6+
"a" + "b"
7+
}
8+
}

0 commit comments

Comments
 (0)