Skip to content

Issue #102: Honor java sources when running compileScoverageScala #103

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
Jun 1, 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
@@ -0,0 +1,145 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Test;

public class ScalaSingleMultiLangModuleTest extends ScoverageFunctionalTest {

public ScalaSingleMultiLangModuleTest() { super("scala-single-multi-lang-module"); }

@Test
public void test() {

AssertableBuildResult result = dryRun("clean", "test");

result.assertTaskDoesntExist(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
}

@Test
public void build() {

AssertableBuildResult result = dryRun("clean", "build");

result.assertTaskDoesntExist(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
}

@Test
public void reportScoverage() {

AssertableBuildResult result = dryRun("clean", ScoveragePlugin.getREPORT_NAME());

result.assertTaskExists(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskExists(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
}

@Test
public void aggregateScoverage() {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getAGGREGATE_NAME());

result.assertNoTasks();
}

@Test
public void checkScoverage() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME());

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

assertReportFilesExist();
assertCoverage(66.7);
}

@Test
public void checkScoverageFails() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test", "--tests", "org.hello.TestNothingSuite");

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskFailed(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

assertReportFilesExist();
assertCoverage(0.0);
}

@Test
public void reportScoverageWithExcludedClasses() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
"-PexcludedFile=.*");

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Assert.assertTrue(resolve(buildDir(), "classes/scala/main/org/hello/World.class").exists());
Assert.assertFalse(resolve(buildDir(), "classes/scala/scoverage/org/hello/World.class").exists());
}

@Test
public void reportScoverageWithoutNormalCompilation() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
"-x", "compileScala");

result.assertTaskSkipped("compileScala");
result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

assertReportFilesExist();
assertCoverage(66.7);

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/java/org/hello/JavaWorld.java.html").exists());

Assert.assertTrue(resolve(buildDir(), "classes/java/main/org/hello/JavaWorld.class").exists());
Assert.assertTrue(resolve(buildDir(), "classes/java/scoverage/org/hello/JavaWorld.class").exists());
Assert.assertTrue(resolve(buildDir(), "classes/scala/main/org/hello/World.class").exists());
Assert.assertFalse(resolve(buildDir(), "classes/scala/scoverage/org/hello/World.class").exists());
}

@Test
public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
"-PexcludedFile=.*", "-x", "compileScala");

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Assert.assertTrue(resolve(buildDir(), "classes/scala/main/org/hello/World.class").exists());
Assert.assertFalse(resolve(buildDir(), "classes/scala/scoverage/org/hello/World.class").exists());
}


private void assertReportFilesExist() {
Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'org.scoverage'
}

repositories {
jcenter()
}

description = 'a single-module Scala project with java and scala sources'

apply plugin: 'java'
apply plugin: 'scala'

dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"

testRuntime group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion

testCompile group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

test {
useJUnitPlatform()
}

scoverage {
minimumRate = 0.3
}

if (hasProperty("excludedFile")) {
scoverage.excludedFiles = [excludedFile]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hello;

public class JavaWorld {
public static void hello() {
System.out.println("Hello, World!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.hello

class World {

def foo(): String = {
val s = "a" + "b"
s
}

// not covered by tests
def bar(): String = "y"

def helloFromJava(): Unit = JavaWorld.hello()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class TestNothingSuite extends FunSuite {

test("nothing") {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class WorldSuite extends FunSuite {

test("foo") {
new World().foo()
}

test("helloFromJava") {
new World().helloFromJava()
}
}
1 change: 1 addition & 0 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
def instrumentedSourceSet = project.sourceSets.create('scoverage') {

resources.source(originalSourceSet.resources)
java.source(originalSourceSet.java)
scala.source(originalSourceSet.scala)

compileClasspath += originalSourceSet.compileClasspath + project.configurations.scoverage
Expand Down