Skip to content

Quick fix to get new Scala collections compatibility in test. #228

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
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -263,9 +263,9 @@ 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.
compiler.assertAtLeastNStatements(9)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check the version of Scala here and expect different number of statements based on it:

   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 @@ -102,11 +102,16 @@ 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 ) {

def assertAtLeastNStatements(n: Int): Unit = {
for (k <- 1 to n) {
assert(testStore.sources.mkString(" ").contains(s"scoverage.Invoker.invoked($k,"),
s"Should be $n invoked statements but missing #$k")
}
}

def assertNMeasuredStatements(n: Int): Unit = {
assertAtLeastNStatements(n)
assert(!testStore.sources.mkString(" ").contains(s"scoverage.Invoker.invoked(${n + 1},"),
s"Found statement ${n + 1} but only expected $n")
}
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 Down Expand Up @@ -33,7 +32,7 @@ class InvokerConcurrencyTest extends FunSuite with BeforeAndAfter {
Future {
Invoker.invoked(i, measurementDir.toString)
}
}(breakOut)
}.toList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't need a list here, set would be good (val futures: Set[Future[Unit]] ...)


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

Expand Down