Skip to content

Commit e19c1a9

Browse files
scripted test to check for delegation to the sbt compiler reporter
1 parent dae2d64 commit e19c1a9

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait A
2+
trait B
3+
4+
trait Wr {
5+
val z: A with B
6+
}
7+
8+
object Er {
9+
val a = er1
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reporter.checkSettings
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := "0.1-SNAPSHOT",
10+
scalaOrganization := "ch.epfl.lamp",
11+
scalacOptions += "-language:Scala2",
12+
scalaBinaryVersion := "2.11",
13+
autoScalaLibrary := false,
14+
libraryDependencies ++= Seq("org.scala-lang" % "scala-library" % "2.11.5"),
15+
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1.1-SNAPSHOT" % "component").sources()
16+
)
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import sbt._
2+
import Keys._
3+
import KeyRanks.DTask
4+
5+
object Reporter {
6+
import xsbti.{Reporter, Problem, Position, Severity, Maybe}
7+
8+
lazy val check = TaskKey[Unit]("check", "make sure compilation info are forwared to sbt")
9+
10+
// compilerReporter is marked private in sbt
11+
lazy val compilerReporter = TaskKey[Option[xsbti.Reporter]]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask)
12+
13+
lazy val reporter =
14+
Some(new xsbti.Reporter {
15+
private val buffer = collection.mutable.ArrayBuffer.empty[Problem]
16+
def reset(): Unit = buffer.clear()
17+
def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error)
18+
def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn)
19+
def printSummary(): Unit = println(problems.mkString(System.lineSeparator))
20+
def problems: Array[Problem] = buffer.toArray
21+
def log(pos: Position, msg: String, sev: Severity): Unit = {
22+
object MyProblem extends Problem {
23+
def category: String = null
24+
def severity: Severity = sev
25+
def message: String = msg
26+
def position: Position = pos
27+
override def toString = s"custom: $position:$severity: $message"
28+
}
29+
buffer.append(MyProblem)
30+
}
31+
def comment(pos: xsbti.Position, msg: String): Unit = ()
32+
})
33+
34+
lazy val checkSettings = Seq(
35+
compilerReporter in (Compile, compile) := reporter,
36+
check <<= (compile in Compile).mapFailure( _ => {
37+
val problems = reporter.get.problems
38+
println(problems.toList)
39+
assert(problems.size == 3)
40+
assert(problems.count(_.severity == Severity.Error) == 1) // not found: er1,
41+
assert(problems.count(_.severity == Severity.Warn) == 1) // `with' as a type operator has been deprecated; use `&' instead,
42+
assert(problems.count(_.severity == Severity.Info) == 1) // one error found
43+
})
44+
)
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> check

0 commit comments

Comments
 (0)