Skip to content

Commit d08ee17

Browse files
committed
#43 ignoring macros
1 parent 1652e78 commit d08ee17

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ resolvers := ("releases" at "https://oss.sonatype.org/service/local/staging/depl
1212

1313
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
1414

15-
scalaVersion := "2.11.2"
15+
scalaVersion := "2.11.0"
1616

17-
crossScalaVersions := Seq("2.10.4", "2.11.2")
17+
crossScalaVersions := Seq("2.10.4", "2.11.0")
1818

1919
libraryDependencies ++= Seq(
20-
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
20+
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
2121
"commons-io" % "commons-io" % "2.4",
2222
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
2323
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2" % "test",

src/main/scala/scoverage/plugin.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ class ScoverageInstrumentationComponent(val global: Global)
337337
c
338338
}
339339

340+
// ignore macro definitions in 2.11
341+
case DefDef(mods, _, _, _, _, _) if mods.isMacro => tree
342+
340343
// this will catch methods defined as macros, eg def test = macro testImpl
341344
// it will not catch macro implemenations
342345
case d: DefDef if d.symbol != null

src/test/scala/scoverage/PluginCoverageTest.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scoverage
22

3-
import org.scalatest.{BeforeAndAfterEachTestData, OneInstancePerTest, FunSuite}
43
import org.scalatest.mock.MockitoSugar
4+
import org.scalatest.{BeforeAndAfterEachTestData, FunSuite, OneInstancePerTest}
55

66
/** @author Stephen Samuel */
77
class PluginCoverageTest
@@ -23,6 +23,22 @@ class PluginCoverageTest
2323
assertNMeasuredStatements(2)
2424
}
2525

26+
test("scoverage should skip macros") {
27+
val code = """
28+
import scala.language.experimental.macros
29+
import scala.reflect.macros.Context
30+
class Impl(val c: Context) {
31+
import c.universe._
32+
def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString)
33+
}
34+
object Macros {
35+
def poly[T] = macro Impl.poly[T]
36+
}"""
37+
compileCodeSnippet(code)
38+
assert(!reporter.hasErrors)
39+
assertNMeasuredStatements(0)
40+
}
41+
2642
test("scoverage should instrument final vals") {
2743
compileCodeSnippet( """ object FinalVals {
2844
| final val name = {

0 commit comments

Comments
 (0)