Skip to content

Commit 2872e73

Browse files
JanBessaigslowikowski
authored andcommitted
Quick fix to get new Scala collections compatibility in test. (#228)
Add Scala 2.13.0-M4 support: * Quick fix to get new Scala collections compatibility in test. * Remove deprecated breakOut optimization * Base number of expected statements in yield test on compiler version * Remove unnecessary toList conversion in InvokerConcurrencyTest * Cleanup multiple depreacted collection API calls
1 parent cf71d82 commit 2872e73

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ class ScoveragePlugin(val global: Global) extends Plugin {
1818
val instrumentationComponent = new ScoverageInstrumentationComponent(global, extraAfterPhase, extraBeforePhase)
1919
override val components: List[PluginComponent] = List(instrumentationComponent)
2020

21+
private def parseExclusionEntry(entryName: String, inOption: String): Seq[String] =
22+
inOption.substring(entryName.length).split(";").map(_.trim).toIndexedSeq.filterNot(_.isEmpty)
23+
2124
override def processOptions(opts: List[String], error: String => Unit): Unit = {
2225
val options = new ScoverageOptions
26+
2327
for (opt <- opts) {
2428
if (opt.startsWith("excludedPackages:")) {
25-
options.excludedPackages = opt.substring("excludedPackages:".length).split(";").map(_.trim).filterNot(_.isEmpty)
29+
options.excludedPackages = parseExclusionEntry("excludedPackages", opt)
2630
} else if (opt.startsWith("excludedFiles:")) {
27-
options.excludedFiles = opt.substring("excludedFiles:".length).split(";").map(_.trim).filterNot(_.isEmpty)
31+
options.excludedFiles = parseExclusionEntry("excludedFiles", opt)
2832
} else if (opt.startsWith("excludedSymbols:")) {
29-
options.excludedSymbols = opt.substring("excludedSymbols:".length).split(";").map(_.trim).filterNot(_.isEmpty)
33+
options.excludedSymbols = parseExclusionEntry("excludedSymbols", opt)
3034
} else if (opt.startsWith("dataDir:")) {
3135
options.dataDir = opt.substring("dataDir:".length)
3236
} else if (opt.startsWith("extraAfterPhase:") || opt.startsWith("extraBeforePhase:")) {

scalac-scoverage-plugin/src/test/scala/scoverage/IOUtilsTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class IOUtilsTest extends FreeSpec with MockitoSugar with OneInstancePerTest wit
3636
writer2.close()
3737

3838
val files = IOUtils.findMeasurementFiles(file1.getParent)
39-
val invoked = IOUtils.invoked(files)
39+
val invoked = IOUtils.invoked(files.toIndexedSeq)
4040
assert(invoked.toSet === Set(1, 2, 5, 7, 9, 10, 14))
4141

4242
file1.delete()

scalac-scoverage-plugin/src/test/scala/scoverage/PluginCoverageTest.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ class PluginCoverageTest
263263
| }
264264
| }""".stripMargin)
265265
assert(!compiler.reporter.hasErrors)
266-
// 2 statements for the two applies in Seq, one for each literal which is 6, one for the flat map,
267-
// one for the map, one for the yield op.
268-
compiler.assertNMeasuredStatements(11)
266+
// 2 statements for the two applies in Seq, one for each literal which is 6, one for the operation passed to yield.
267+
// Depending on the collections api version, there can be additional implicit canBuildFrom statements.
268+
val expectedStatementsCount = if (ScoverageCompiler.ShortScalaVersion < "2.13") 11 else 9
269+
compiler.assertNMeasuredStatements(expectedStatementsCount)
269270
}
270271

271272
test("plugin should not instrument local macro implementation") {

scalac-scoverage-plugin/src/test/scala/scoverage/ScoverageCompiler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class ScoverageCompiler(settings: scala.tools.nsc.Settings, reporter: scala.tool
102102

103103
def assertNoCoverage() = assert(!testStore.sources.mkString(" ").contains(s"scoverage.Invoker.invoked"))
104104

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

141142
override def transform(tree: global.Tree) = {
142-
sources append tree.toString
143+
sources += tree.toString
143144
tree
144145
}
145146
}

scalac-scoverage-runtime/jvm/src/test/scala/scoverage/InvokerConcurrencyTest.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import java.util.concurrent.Executors
55

66
import org.scalatest.{BeforeAndAfter, FunSuite}
77

8-
import scala.collection.breakOut
98
import scala.concurrent._
109
import scala.concurrent.duration._
1110

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

3029
// Create 1k "invoked" calls on the common thread pool, to stress test
3130
// the method
32-
val futures: List[Future[Unit]] = testIds.map { i: Int =>
31+
val futures: Set[Future[Unit]] = testIds.map { i: Int =>
3332
Future {
3433
Invoker.invoked(i, measurementDir.toString)
3534
}
36-
}(breakOut)
35+
}
3736

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

4039
// Now verify that the measurement file is not corrupted by loading it
4140
val measurementFiles = Invoker.findMeasurementFiles(measurementDir)
42-
val idsFromFile = Invoker.invoked(measurementFiles).toSet
41+
val idsFromFile = Invoker.invoked(measurementFiles.toIndexedSeq).toSet
4342

4443
idsFromFile === testIds
4544
}

scalac-scoverage-runtime/shared/src/test/scala/scoverage/InvokerMultiModuleTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class InvokerMultiModuleTest extends FunSuite with BeforeAndAfter {
2727

2828
// Verify measurements went to correct directory
2929
val measurementFiles0 = Invoker.findMeasurementFiles(measurementDir(0))
30-
val idsFromFile0 = Invoker.invoked(measurementFiles0).toSet
30+
val idsFromFile0 = Invoker.invoked(measurementFiles0.toIndexedSeq).toSet
3131

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

3434
val measurementFiles1 = Invoker.findMeasurementFiles(measurementDir(0))
35-
val idsFromFile1 = Invoker.invoked(measurementFiles1).toSet
35+
val idsFromFile1 = Invoker.invoked(measurementFiles1.toIndexedSeq).toSet
3636
idsFromFile1 === testIds.filter { i: Int => i % 2 == 1 }
3737
}
3838

0 commit comments

Comments
 (0)