]> Dogcows Code - chaz/sbt-tap/commitdiff
output errors as diagnostic messages
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 11 Jan 2013 22:59:53 +0000 (15:59 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 11 Jan 2013 23:01:14 +0000 (16:01 -0700)
src/main/scala/SbtTapReporting.scala

index 097157a520359f862faee08c7ba748c7597908b4..531a86b463b9af88ba0650108a2779788268a96e 100644 (file)
@@ -20,55 +20,55 @@ class SbtTapListener extends TestsListener {
   var testId = new AtomicInteger(0)
   var fileWriter: FileWriter = _
 
-  override def doInit {
-    new File("test-results").mkdirs()
+  override def doInit {
+    new File("test-results").mkdirs
 
     fileWriter = new FileWriter(
       scala.util.Properties.envOrElse("SBT_TAP_OUTPUT", "test-results/test.tap")
     )
   }
 
-  def startGroup(name: String) {
-    writeTapFields("#", "start", name)
-  }
+  def startGroup(name: String) =
+    writeTapDiag("start", name)
 
-  def endGroup(name: String, result: TestResult.Value) {
-    writeTapFields("#", "end", name, "with result", result.toString.toLowerCase)
-  }
+  def endGroup(name: String, result: TestResult.Value) =
+    writeTapDiag("end", name, "with result", result.toString.toLowerCase)
 
-  def endGroup(name: String, t: Throwable) {
-    writeTapFields("#", "end", name)
+  def endGroup(name: String, t: Throwable) = {
+    writeTapDiag("end", name)
+    writeTapDiag(stackTraceForError(t))
   }
 
-  def testEvent(event: TestEvent) {
+  def testEvent(event: TestEvent) {
     event.detail.foreach { e: TEvent =>
       e.result match {
-        case TResult.Success => writeTapFields("ok", testId.incrementAndGet(), "-", e.testName())
+        case TResult.Success => writeTap("ok", testId.incrementAndGet, "-", e.testName)
         case TResult.Error | TResult.Failure =>
-          writeTapFields("not ok", testId.incrementAndGet(), "-", e.testName())
-          // According to the TAP spec, as long as there is any kind of whitespace, this output should belong to the
-          // the test that failed and it should get displayed in the UI.
-          // TODO:It would be nice if we could report the exact line in the test where this happened.
-          writeTapFields(" ", stackTraceForError(e.error()))
+          writeTap("not ok", testId.incrementAndGet, "-", e.testName)
+          // TODO: It would be nice if we could report the exact line in the test where this happened.
+          writeTapDiag(stackTraceForError(e.error))
         case TResult.Skipped =>
           // it doesn't look like this framework distinguishes between pending and ignored.
-          writeTapFields("ok", testId.incrementAndGet(), e.testName(), "#", "skip", e.testName())
+          writeTap("ok", testId.incrementAndGet, e.testName, "#", "skip", e.testName)
       }
     }
   }
 
-  override def doComplete(finalResult: TestResult.Value) {
-    writeTapFields("1.." + testId.get)
-    fileWriter.close()
+  override def doComplete(finalResult: TestResult.Value) {
+    writeTap("1.." + testId.get)
+    fileWriter.close
   }
 
-  private def writeTapFields(s: Any*) {
-    fileWriter.write(s.mkString("",  " ", "\n"))
-    fileWriter.flush()
+  private def writeTap(s: Any*) = {
+    fileWriter.write(s.mkString("", " ", "\n"))
+    fileWriter.flush
   }
 
+  private def writeTapDiag(s: Any*) =
+    writeTap("#", s.mkString("", " ", "\n").trim.replaceAll("\\n", "\n# "))
+
   private def stackTraceForError(t: Throwable): String = {
-    val sw = new StringWriter()
+    val sw = new StringWriter
     val printWriter = new PrintWriter(sw)
     t.printStackTrace(printWriter)
     sw.toString
This page took 0.027324 seconds and 4 git commands to generate.