Skip to content

Commit bc3da6f

Browse files
authored
Merge pull request #141 from eyalroth/fix-tests
Fix functional tests and add (ignored) tests for composite builds and Scala 2.13
2 parents cfb3963 + 69bb994 commit bc3da6f

38 files changed

+309
-118
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ You can find instructions on how to apply the plugin at http://plugins.gradle.or
3535

3636
`gradle checkScoverage` will automatically invoke `reportScoverage` but it won't generate aggregated reports.
3737
In order to check coverage of aggregated reports one should use `gradle checkScoverage aggregateScoverage`.
38+
39+
**Note:** The plugin is not compatible with composite builds. For more information, see [the relevant issue](https://github.com/scoverage/gradle-scoverage/issues/98).
3840

3941
### Configuration
4042

Diff for: build.gradle

+24-11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ apply plugin: 'groovy'
4444
sourceCompatibility = '1.8'
4545
targetCompatibility = '1.8'
4646

47+
4748
dependencies {
4849
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.4.1"
4950
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
@@ -58,39 +59,51 @@ dependencies {
5859
sourceSets {
5960
functionalTest {
6061
java.srcDir file('src/functionalTest/java')
61-
resources.srcDir file('src/functionalTest/resources')
62-
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
63-
runtimeClasspath += output + compileClasspath
62+
compileClasspath += sourceSets.main.output
63+
runtimeClasspath += sourceSets.main.output
64+
}
65+
crossScalaVersionTest {
66+
java.srcDir file('src/crossScalaVersionTest/java')
67+
compileClasspath += sourceSets.main.output + sourceSets.functionalTest.output
68+
runtimeClasspath += sourceSets.main.output + sourceSets.functionalTest.output
6469
}
6570
}
6671

67-
task crossScalaVersionFunctionalTest(type: Test) {
72+
configurations {
73+
functionalTestImplementation.extendsFrom testImplementation
74+
functionalTestRuntimeOnly.extendsFrom testRuntimeOnly
75+
76+
crossScalaVersionTestImplementation.extendsFrom testImplementation
77+
crossScalaVersionTestRuntimeOnly.extendsFrom testRuntimeOnly
78+
}
79+
80+
task crossScalaVersionTest(type: Test) {
6881
description = 'Runs the cross scala version functional test.'
6982
group = 'verification'
70-
testClassesDirs = sourceSets.functionalTest.output.classesDirs
71-
classpath = sourceSets.functionalTest.runtimeClasspath
72-
include "**/ScalaMultiModuleCrossVersionTest.*"
83+
testClassesDirs = sourceSets.crossScalaVersionTest.output
84+
classpath = sourceSets.crossScalaVersionTest.runtimeClasspath
85+
forkEvery = 1 // crucial to run every test in its own JVM
7386

7487
testLogging.showStandardStreams = true
7588

7689
mustRunAfter test
7790
}
91+
check.dependsOn crossScalaVersionTest
7892

7993
task functionalTest(type: Test) {
8094
description = 'Runs the functional tests.'
8195
group = 'verification'
82-
testClassesDirs = sourceSets.functionalTest.output.classesDirs
96+
testClassesDirs = sourceSets.functionalTest.output
8397
classpath = sourceSets.functionalTest.runtimeClasspath
84-
exclude "**/ScalaMultiModuleCrossVersionTest.*"
8598

8699
testLogging.showStandardStreams = true
87100

88-
dependsOn crossScalaVersionFunctionalTest
101+
mustRunAfter crossScalaVersionTest
89102
}
90103
check.dependsOn functionalTest
91104

92105
gradlePlugin {
93-
testSourceSets sourceSets.functionalTest
106+
testSourceSets sourceSets.functionalTest, sourceSets.crossScalaVersionTest
94107
}
95108

96109
task groovydocJar(type: Jar, dependsOn: groovydoc) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.scoverage;
2+
3+
public class Scala211Test extends ScalaVersionTest {
4+
public Scala211Test() {
5+
super("2_11");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.scoverage;
2+
3+
public class Scala212Test extends ScalaVersionTest {
4+
public Scala212Test() {
5+
super("2_12");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scoverage;
2+
3+
import org.junit.Ignore;
4+
5+
/**
6+
* Tests is currently ignored as support for Scala 2.13 is not available yet.
7+
*
8+
* @see <a href="https://github.com/scoverage/gradle-scoverage/issues/106">Issue #106</a>.
9+
*/
10+
@Ignore
11+
public class Scala213Test extends ScalaVersionTest {
12+
public Scala213Test() {
13+
super("2_13");
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.scoverage;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.jupiter.api.Tag;
6+
import org.junit.runner.RunWith;
7+
import org.junit.runners.Suite;
8+
import org.scoverage.ScoverageFunctionalTest;
9+
import org.scoverage.ScoveragePlugin;
10+
11+
import java.io.File;
12+
13+
public class ScalaCrossVersionAggregationTest extends ScoverageFunctionalTest {
14+
15+
public ScalaCrossVersionAggregationTest() {
16+
super("scala-multi-module-cross-version");
17+
}
18+
19+
@Test
20+
public void checkAndAggregateAll() throws Exception {
21+
22+
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
23+
ScoveragePlugin.getAGGREGATE_NAME());
24+
25+
result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
26+
result.assertTaskSucceeded("2_11:" + ScoveragePlugin.getREPORT_NAME());
27+
result.assertTaskSucceeded("2_12:" + ScoveragePlugin.getREPORT_NAME());
28+
result.assertTaskSucceeded("2_13:" + ScoveragePlugin.getREPORT_NAME());
29+
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
30+
result.assertTaskSucceeded("2_11:" + ScoveragePlugin.getCHECK_NAME());
31+
result.assertTaskSucceeded("2_12:" + ScoveragePlugin.getCHECK_NAME());
32+
result.assertTaskSucceeded("2_13:" + ScoveragePlugin.getCHECK_NAME());
33+
result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME());
34+
35+
assertAggregationFilesExist();
36+
assertCoverage(100.0);
37+
}
38+
39+
private void assertAggregationFilesExist() {
40+
41+
Assert.assertTrue(resolve(reportDir(), "index.html").exists());
42+
Assert.assertTrue(resolve(reportDir(), "2_11/src/main/scala/org/hello/World2_11.scala.html").exists());
43+
Assert.assertTrue(resolve(reportDir(), "2_12/src/main/scala/org/hello/World2_12.scala.html").exists());
44+
Assert.assertTrue(resolve(reportDir(), "2_13/src/main/scala/org/hello/World2_13.scala.html").exists());
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.scoverage;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.jupiter.api.Tag;
6+
import org.scoverage.ScoverageFunctionalTest;
7+
import org.scoverage.ScoveragePlugin;
8+
9+
import java.io.File;
10+
11+
/**
12+
* This abstract class is used to test each scala version in an individual class.
13+
* It is crucial that each test will be separated into its own class,
14+
* as this is the only way to run these tests in separate JVM processes (via `forkEvery` gradle configuration).
15+
*/
16+
public abstract class ScalaVersionTest extends ScoverageFunctionalTest {
17+
18+
private final String scalaVersion;
19+
20+
public ScalaVersionTest(String scalaVersion) {
21+
super("scala-multi-module-cross-version");
22+
this.scalaVersion = scalaVersion;
23+
}
24+
25+
@Test
26+
public void report() throws Exception {
27+
28+
AssertableBuildResult result = run("clean", ":" + scalaVersion + ":" + ScoveragePlugin.getREPORT_NAME());
29+
result.assertTaskSucceeded(scalaVersion + ":" + ScoveragePlugin.getREPORT_NAME());
30+
31+
File reportDir = reportDir(projectDir().toPath().resolve(scalaVersion).toFile());
32+
Assert.assertTrue(resolve(reportDir, "index.html").exists());
33+
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/World" + scalaVersion + ".scala.html").exists());
34+
}
35+
}

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_11/src/main/scala/org/hello/World211.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_11/src/main/scala/org/hello/World2_11.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hello
22

3-
class World211 {
3+
class World2_11 {
44

55
def foo(): String = {
66
val s = "2" + "11"

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_13/src/test/scala/org/hello/World213Suite.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_11/src/test/scala/org/hello/World2_11Suite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import org.scalatest.FunSuite
55
import org.scalatest.junit.JUnitRunner
66

77
@RunWith(classOf[JUnitRunner])
8-
class World212Suite extends FunSuite {
8+
class World2_11Suite extends FunSuite {
99

1010
test("foo") {
11-
new World213().foo()
11+
new World2_11().foo()
1212
}
1313
}

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_13/src/main/scala/org/hello/World213.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_12/src/main/scala/org/hello/World2_12.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hello
22

3-
class World213 {
3+
class World2_12 {
44

55
def foo(): String = {
66
val s = "2" + "12"

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_11/src/test/scala/org/hello/World211Suite.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_12/src/test/scala/org/hello/World2_12Suite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import org.scalatest.FunSuite
55
import org.scalatest.junit.JUnitRunner
66

77
@RunWith(classOf[JUnitRunner])
8-
class World211Suite extends FunSuite {
8+
class World2_12Suite extends FunSuite {
99

1010
test("foo") {
11-
new World211().foo()
11+
new World2_12().foo()
1212
}
1313
}

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_12/src/main/scala/org/hello/World212.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_13/src/main/scala/org/hello/World2_13.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hello
22

3-
class World212 {
3+
class World2_13 {
44

55
def foo(): String = {
66
val s = "2" + "12"

Diff for: src/functionalTest/resources/projects/scala-multi-module-cross-version/2_12/src/test/scala/org/hello/World212Suite.scala renamed to src/crossScalaVersionTest/resources/projects/scala-multi-module-cross-version/2_13/src/test/scala/org/hello/World2_13Suite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import org.scalatest.junit.JUnitRunner
88
class World212Suite extends FunSuite {
99

1010
test("foo") {
11-
new World212().foo()
11+
new World2_13().foo()
1212
}
1313
}

Diff for: src/functionalTest/java/org.scoverage/ScalaMultiModuleCrossVersionTest.java

-98
This file was deleted.

0 commit comments

Comments
 (0)