Add better error message if run fails

It is possible with the new layering strategies that tests may fail if a
java package private class is accessed across classloader layers. This
will result in an IllegalAccessError that is hard to debug. With this
commit, I add an error message that will be displayed if run throws an
IllegalAccessError that suggests that the user try the
ScalaInstance layering strategy or the flat layering strategy.
This commit is contained in:
Ethan Atkins
2019-04-02 20:53:37 -07:00
parent cb7fbfc810
commit 8ef5a67b64
7 changed files with 72 additions and 19 deletions
+17 -1
View File
@@ -122,9 +122,25 @@ final class TestRunner(
val results = new scala.collection.mutable.ListBuffer[Event]
val handler = new EventHandler { def handle(e: Event): Unit = { results += e } }
val loggers: Vector[ContentLogger] = listeners.flatMap(_.contentLogger(testDefinition))
def errorEvents(e: Throwable): Array[sbt.testing.Task] = {
val taskDef = testTask.taskDef
val event = new Event {
val status = Status.Error
val throwable = new OptionalThrowable(e)
val fullyQualifiedName = taskDef.fullyQualifiedName
val selector = new TestSelector(name)
val fingerprint = taskDef.fingerprint
val duration = -1L
}
results += event
Array.empty
}
val nestedTasks =
try testTask.execute(handler, loggers.map(_.log).toArray)
finally {
catch {
case NonFatal(e) => errorEvents(e)
case e: IllegalAccessError => errorEvents(e)
} finally {
loggers.foreach(_.flush())
}
val event = TestEvent(results)