diff options
Diffstat (limited to 'contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala')
-rw-r--r-- | contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala b/contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala index 2e981259..05e58ec7 100644 --- a/contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala +++ b/contrib/bsp/src/mill/contrib/bsp/BspTestReporter.scala @@ -1,5 +1,7 @@ package mill.contrib.bsp +import java.io.{PrintWriter, StringWriter} + import ch.epfl.scala.bsp4j._ import mill.api.BspContext import sbt.testing._ @@ -50,7 +52,6 @@ class BspTestReporter( case sbt.testing.Status.Error => StatusCode.ERROR case default => StatusCode.OK }) - taskFinishParams.setDataKind(TaskDataKind.TEST_FINISH) val status = event.status match { case sbt.testing.Status.Success => passed += 1 @@ -74,21 +75,25 @@ class BspTestReporter( skipped += 1 TestStatus.SKIPPED //TODO: what to do here } - val testFinish = new TestFinish(getDisplayName(event), status) - taskFinishParams.setData(testFinish) - taskFinishParams.setEventTime(System.currentTimeMillis()) - taskFinishParams.setMessage("Finished running: " + getDisplayName(event)) - if (event.throwable.isDefined) { - val exception = event.throwable.get - taskFinishParams.setData( // send data about any potential exceptions thrown during testing - TestException(exception.getStackTrace.toString, - exception.getMessage, - exception.getClass.toString)) - } + taskFinishParams.setDataKind(TaskDataKind.TEST_FINISH) + taskFinishParams.setData({ + val testFinish = new TestFinish(getDisplayName(event), status) + if (event.throwable.isDefined) + testFinish.setMessage(throwableToString(event.throwable().get())) + testFinish + }) + taskFinishParams.setEventTime(System.currentTimeMillis()) client.onBuildTaskFinish(taskFinishParams) } + private def throwableToString(t: Throwable): String = { + val sw = new StringWriter + val pw = new PrintWriter(sw) + t.printStackTrace(pw) + sw.toString + } + // Compute the display name of the test / test suite // to which the given event relates private[this] def getDisplayName(e: Event): String = { |