Skip to content

Add Scala 2.13.0-M4 support #229

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 3 commits into from
Jul 22, 2018
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jdk:
scala:
- 2.10.7
- 2.11.12
- 2.12.4
- 2.13.0-M3
- 2.12.6
- 2.13.0-M4

before_cache:
- find "$HOME/.sbt/" -name '*.lock' -print0 | xargs -0 rm
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import sbtcrossproject.CrossType

val Org = "org.scoverage"
val MockitoVersion = "2.19.0"
val ScalatestVersion = "3.0.5-M1"
val ScalatestVersion = "3.0.6-SNAP1"

val appSettings = Seq(
organization := Org,
scalaVersion := "2.12.4",
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.4", "2.13.0-M3"),
scalaVersion := "2.12.6",
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.6", "2.13.0-M4"),
fork in Test := false,
publishMavenStyle := true,
publishArtifact in Test := false,
Expand Down Expand Up @@ -91,7 +91,7 @@ lazy val plugin = Project("scalac-scoverage-plugin", file("scalac-scoverage-plug
)).settings(libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor > 10 => Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
"org.scala-lang.modules" %% "scala-xml" % "1.1.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0" % "test"
)
case _ => Seq(
Expand Down
10 changes: 7 additions & 3 deletions scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ class ScoveragePlugin(val global: Global) extends Plugin {
val instrumentationComponent = new ScoverageInstrumentationComponent(global, extraAfterPhase, extraBeforePhase)
override val components: List[PluginComponent] = List(instrumentationComponent)

private def parseExclusionEntry(entryName: String, inOption: String): Seq[String] =
inOption.substring(entryName.length).split(";").map(_.trim).toIndexedSeq.filterNot(_.isEmpty)

override def processOptions(opts: List[String], error: String => Unit): Unit = {
val options = new ScoverageOptions

for (opt <- opts) {
if (opt.startsWith("excludedPackages:")) {
options.excludedPackages = opt.substring("excludedPackages:".length).split(";").map(_.trim).filterNot(_.isEmpty)
options.excludedPackages = parseExclusionEntry("excludedPackages", opt)
} else if (opt.startsWith("excludedFiles:")) {
options.excludedFiles = opt.substring("excludedFiles:".length).split(";").map(_.trim).filterNot(_.isEmpty)
options.excludedFiles = parseExclusionEntry("excludedFiles", opt)
} else if (opt.startsWith("excludedSymbols:")) {
options.excludedSymbols = opt.substring("excludedSymbols:".length).split(";").map(_.trim).filterNot(_.isEmpty)
options.excludedSymbols = parseExclusionEntry("excludedSymbols", opt)
} else if (opt.startsWith("dataDir:")) {
options.dataDir = opt.substring("dataDir:".length)
} else if (opt.startsWith("extraAfterPhase:") || opt.startsWith("extraBeforePhase:")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IOUtilsTest extends FreeSpec with MockitoSugar with OneInstancePerTest wit
writer.write("1\n5\n9\n\n10\n")
writer.close()
val invoked = IOUtils.invoked(Seq(file))
assert(invoked.toSet === Set(1, 5, 9, 10))
assert(invoked === Set(1, 5, 9, 10))

file.delete()
}
Expand All @@ -36,8 +36,8 @@ class IOUtilsTest extends FreeSpec with MockitoSugar with OneInstancePerTest wit
writer2.close()

val files = IOUtils.findMeasurementFiles(file1.getParent)
val invoked = IOUtils.invoked(files)
assert(invoked.toSet === Set(1, 2, 5, 7, 9, 10, 14))
val invoked = IOUtils.invoked(files.toIndexedSeq)
assert(invoked === Set(1, 2, 5, 7, 9, 10, 14))

file1.delete()
file2.delete()
Expand Down Expand Up @@ -66,7 +66,7 @@ class IOUtilsTest extends FreeSpec with MockitoSugar with OneInstancePerTest wit

val files = IOUtils.reportFileSearch(base, IOUtils.isReportFile)
val invoked = IOUtils.invoked(files)
assert(invoked.toSet === Set(1, 2, 3, 4, 5, 6, 7, 8, 11, 20, 30, 44))
assert(invoked === Set(1, 2, 3, 4, 5, 6, 7, 8, 11, 20, 30, 44))

file1.delete()
file2.delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ class PluginCoverageTest
| }
| }""".stripMargin)
assert(!compiler.reporter.hasErrors)
// 2 statements for the two applies in Seq, one for each literal which is 6, one for the flat map,
// one for the map, one for the yield op.
compiler.assertNMeasuredStatements(11)
// 2 statements for the two applies in Seq, one for each literal which is 6, one for the operation passed to yield.
// Depending on the collections api version, there can be additional implicit canBuildFrom statements.
val expectedStatementsCount = if (ScoverageCompiler.ShortScalaVersion < "2.13") 11 else 9
compiler.assertNMeasuredStatements(expectedStatementsCount)
}

test("plugin should not instrument local macro implementation") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ScoverageCompiler(settings: scala.tools.nsc.Settings, reporter: scala.tool
def assertNoCoverage() = assert(!testStore.sources.mkString(" ").contains(s"scoverage.Invoker.invoked"))

def assertNMeasuredStatements(n: Int): Unit = {
for ( k <- 1 to n ) {
for (k <- 1 to n) {
assert(testStore.sources.mkString(" ").contains(s"scoverage.Invoker.invoked($k,"),
s"Should be $n invoked statements but missing #$k")
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class ScoverageCompiler(settings: scala.tools.nsc.Settings, reporter: scala.tool
class Transformer(unit: global.CompilationUnit) extends TypingTransformer(unit) {

override def transform(tree: global.Tree) = {
sources append tree.toString
sources += tree.toString
tree
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.util.concurrent.Executors

import org.scalatest.{BeforeAndAfter, FunSuite}

import scala.collection.breakOut
import scala.concurrent._
import scala.concurrent.duration._

Expand All @@ -29,17 +28,17 @@ class InvokerConcurrencyTest extends FunSuite with BeforeAndAfter {

// Create 1k "invoked" calls on the common thread pool, to stress test
// the method
val futures: List[Future[Unit]] = testIds.map { i: Int =>
val futures: Set[Future[Unit]] = testIds.map { i: Int =>
Future {
Invoker.invoked(i, measurementDir.toString)
}
}(breakOut)
}

futures.foreach(Await.result(_, 1.second))

// Now verify that the measurement file is not corrupted by loading it
val measurementFiles = Invoker.findMeasurementFiles(measurementDir)
val idsFromFile = Invoker.invoked(measurementFiles).toSet
val idsFromFile = Invoker.invoked(measurementFiles.toIndexedSeq)

idsFromFile === testIds
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class InvokerMultiModuleTest extends FunSuite with BeforeAndAfter {

// Verify measurements went to correct directory
val measurementFiles0 = Invoker.findMeasurementFiles(measurementDir(0))
val idsFromFile0 = Invoker.invoked(measurementFiles0).toSet
val idsFromFile0 = Invoker.invoked(measurementFiles0.toIndexedSeq)

idsFromFile0 === testIds.filter { i: Int => i % 2 == 0 }

val measurementFiles1 = Invoker.findMeasurementFiles(measurementDir(0))
val idsFromFile1 = Invoker.invoked(measurementFiles1).toSet
val idsFromFile1 = Invoker.invoked(measurementFiles1.toIndexedSeq)
idsFromFile1 === testIds.filter { i: Int => i % 2 == 1 }
}

Expand Down