Skip to content

Commit 25efb91

Browse files
authored
Merge pull request #837 from tgodzik/add-stacktrace
improvement: Add stack trace to failed results
2 parents 893391d + 1493ca0 commit 25efb91

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

modules/core/src/main/scala/ch/epfl/scala/debugadapter/testing/TestSuiteEventHandler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ object TestSuiteEventHandler {
3535
case Status.Failure =>
3636
val failedMsg =
3737
TestUtils.printThrowable(e.throwable()).getOrElse("")
38+
val stackTrace = TestUtils.printStackTrace(e.throwable()).getOrElse("")
3839
val formatted =
3940
TestSuiteEventHandler.formatError(
4041
name,
4142
failedMsg,
4243
indentSize = 0
4344
)
44-
SingleTestResult.Failed(name, e.duration, formatted)
45+
SingleTestResult.Failed(name, e.duration, formatted, stackTrace, location = null)
4546
case _ =>
4647
SingleTestResult.Skipped(name)
4748
}

modules/core/src/main/scala/ch/epfl/scala/debugadapter/testing/TestSuiteSummary.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ final case class TestSuiteSummary(
1010
tests: java.util.List[SingleTestSummary]
1111
)
1212

13+
final class TestLocation(
14+
val file: String,
15+
val line: Int
16+
)
17+
1318
/**
1419
* Sealed hierarchy that models 3 possible outcomes of single test case.
1520
* I wanted to model this a discriminated union type and due to gson serialization,
@@ -40,10 +45,18 @@ object SingleTestResult {
4045
val kind: String,
4146
val testName: String,
4247
val duration: Long,
43-
val error: String
48+
val error: String,
49+
val stackTrace: String,
50+
val location: TestLocation
4451
) extends SingleTestSummary
4552
object Failed {
46-
def apply(testName: String, duration: Long, error: String): Failed =
47-
new Failed("failed", testName, duration, error)
53+
def apply(
54+
testName: String,
55+
duration: Long,
56+
error: String,
57+
stackTrace: String,
58+
location: TestLocation
59+
): Failed =
60+
new Failed("failed", testName, duration, error, stackTrace, location)
4861
}
4962
}

modules/core/src/main/scala/ch/epfl/scala/debugadapter/testing/TestUtils.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package ch.epfl.scala.debugadapter.testing
22

3-
import sbt.testing._
3+
import sbt.testing.*
4+
5+
import java.io.ByteArrayOutputStream
6+
import java.io.PrintStream
47

58
object TestUtils {
69
def printSelector(selector: Selector): Option[String] = selector match {
@@ -17,6 +20,18 @@ object TestUtils {
1720
else Some(stripTestFrameworkSpecificInformation(opt.get().getMessage))
1821
}
1922

23+
def printStackTrace(opt: OptionalThrowable): Option[String] = {
24+
if (opt.isEmpty) None
25+
else
26+
Some {
27+
val writer = new StringBuffer
28+
val outputStream = new ByteArrayOutputStream()
29+
val printStream = new PrintStream(outputStream)
30+
opt.get().printStackTrace(printStream)
31+
outputStream.toString
32+
}
33+
}
34+
2035
private val specs2Prefix = "java.lang.Exception: "
2136
private val utestPrefix = "utest.AssertionError: "
2237
private val scalaTestPrefix = "org.scalatest.exceptions.TestFailedException: "

0 commit comments

Comments
 (0)