diff options
author | Samvel Abrahamyan <samvel1024@gmail.com> | 2019-08-12 12:17:35 +0400 |
---|---|---|
committer | Samvel Abrahamyan <samvel1024@gmail.com> | 2019-10-12 14:33:15 +0200 |
commit | fcdfba1df24ff921d7bbb95e0f43c9b35e4a7b70 (patch) | |
tree | 95d9a3400ded4d7fab583c08fd32417e835b5923 | |
parent | 33725730a0211cc437cf2158599b39aad86ac56d (diff) | |
download | mill-fcdfba1df24ff921d7bbb95e0f43c9b35e4a7b70.tar.gz mill-fcdfba1df24ff921d7bbb95e0f43c9b35e4a7b70.tar.bz2 mill-fcdfba1df24ff921d7bbb95e0f43c9b35e4a7b70.zip |
Fix failed test not being reported with appropriate status, add full stacktrace as message
-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 = { |