Skip to content

Commit 417bbe2

Browse files
committed
Remove 'com.typesafe.scala-logging:scala-logging' dependency
Add macros directly to plugin's test sources. `test-classes` directory will be added to the class path instead of `scala-logging` dependencies. Maybe it's not an elegant solution, but it is simple and does not require any external dependencies.
1 parent 7358333 commit 417bbe2

File tree

8 files changed

+83
-67
lines changed

8 files changed

+83
-67
lines changed

build.sbt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,27 @@ lazy val plugin = Project("scalac-scoverage-plugin", file("scalac-scoverage-plug
7979
.dependsOn(`scalac-scoverage-runtimeJVM` % "test")
8080
.settings(name := "scalac-scoverage-plugin")
8181
.settings(appSettings: _*)
82-
.settings(libraryDependencies ++= Seq(
83-
"org.scalatest" %% "scalatest" % ScalatestVersion % "test",
84-
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
85-
)).settings(libraryDependencies ++= {
86-
CrossVersion.partialVersion(scalaVersion.value) match {
87-
case Some((2, scalaMajor)) if scalaMajor > 10 => Seq(
88-
"org.scala-lang.modules" %% "scala-xml" % "1.1.1",
89-
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0" % "test"
82+
.settings(
83+
libraryDependencies ++= Seq(
84+
"org.scalatest" %% "scalatest" % ScalatestVersion % "test",
85+
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
9086
)
91-
case _ => Seq(
92-
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2" % "test"
93-
)
94-
}
95-
})
87+
)
88+
.settings(
89+
unmanagedSourceDirectories in Test ++= {
90+
CrossVersion.partialVersion(scalaVersion.value) match {
91+
case Some((2, scalaMajor)) if scalaMajor > 10 =>
92+
Seq((sourceDirectory in Test).value / "scala-2.11+")
93+
case _ =>
94+
Seq()
95+
}
96+
},
97+
libraryDependencies ++= {
98+
CrossVersion.partialVersion(scalaVersion.value) match {
99+
case Some((2, scalaMajor)) if scalaMajor > 10 =>
100+
Seq("org.scala-lang.modules" %% "scala-xml" % "1.1.1")
101+
case _ =>
102+
Seq()
103+
}
104+
}
105+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package scoverage.macrosupport
2+
3+
import scala.reflect.macros.Context
4+
5+
private object TesterMacro {
6+
7+
type TesterContext = Context { type PrefixType = Tester.type }
8+
9+
def test(c: TesterContext) =
10+
c.universe.reify(
11+
println("macro test")
12+
)
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package scoverage.macrosupport
2+
3+
import scala.reflect.macros.blackbox.Context
4+
5+
private object TesterMacro {
6+
7+
type TesterContext = Context { type PrefixType = Tester.type }
8+
9+
def test(c: TesterContext) = {
10+
import c.universe._
11+
q"""println("macro test")"""
12+
}
13+
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scoverage
2+
3+
import java.io.File
4+
5+
trait MacroSupport {
6+
7+
val macroSupportDeps = Seq(testClasses)
8+
9+
private def testClasses: File = new File(s"./scalac-scoverage-plugin/target/scala-${ScoverageCompiler.ShortScalaVersion}/test-classes")
10+
11+
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PluginASTSupportTest
77
extends FunSuite
88
with OneInstancePerTest
99
with BeforeAndAfterEachTestData
10-
with ScalaLoggingSupport {
10+
with MacroSupport {
1111

1212
override protected def afterEach(testData: TestData): Unit = {
1313
val compiler = ScoverageCompiler.default
@@ -145,12 +145,11 @@ class PluginASTSupportTest
145145
// https://github.com/skinny-framework/skinny-framework/issues/97
146146
test("macro range positions should not break plugin") {
147147
val compiler = ScoverageCompiler.default
148-
scalaLoggingDeps.foreach(compiler.addToClassPath(_))
149-
compiler.compileCodeSnippet( s"""import ${scalaLoggingPackageName}.StrictLogging
148+
macroSupportDeps.foreach(compiler.addToClassPath(_))
149+
compiler.compileCodeSnippet( s"""import scoverage.macrosupport.Tester
150150
|
151-
|object MacroTest extends StrictLogging {
152-
| println("Hello")
153-
| logger.info("will break")
151+
|object MacroTest {
152+
| Tester.test
154153
|} """.stripMargin)
155154
assert(!compiler.reporter.hasErrors)
156155
assert(!compiler.reporter.hasWarnings)

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PluginCoverageTest
77
extends FunSuite
88
with OneInstancePerTest
99
with BeforeAndAfterEachTestData
10-
with ScalaLoggingSupport {
10+
with MacroSupport {
1111

1212
test("scoverage should instrument default arguments with methods") {
1313
val compiler = ScoverageCompiler.default
@@ -285,12 +285,13 @@ class PluginCoverageTest
285285
compiler.assertNoCoverage()
286286
}
287287

288-
test("plugin should not instrument expanded macro code github.com/skinny-framework/skinny-framework/issues/97") {
288+
test("plugin should not instrument expanded macro code http://github.com/skinny-framework/skinny-framework/issues/97") {
289289
val compiler = ScoverageCompiler.default
290-
scalaLoggingDeps.foreach(compiler.addToClassPath(_))
291-
compiler.compileCodeSnippet( s"""import ${scalaLoggingPackageName}.StrictLogging
292-
|class MacroTest extends StrictLogging {
293-
| logger.info("will break")
290+
macroSupportDeps.foreach(compiler.addToClassPath(_))
291+
compiler.compileCodeSnippet( s"""import scoverage.macrosupport.Tester
292+
|
293+
|class MacroTest {
294+
| Tester.test
294295
|} """.stripMargin)
295296
assert(!compiler.reporter.hasErrors)
296297
assert(!compiler.reporter.hasWarnings)

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

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package scoverage.macrosupport
2+
3+
import scala.language.experimental.macros
4+
5+
object Tester {
6+
7+
def test: Unit = macro TesterMacro.test
8+
9+
}

0 commit comments

Comments
 (0)