Skip to content

Commit 96eab98

Browse files
committed
improvement: Add location to failure to help mark it in VS Code
1 parent 1081e6e commit 96eab98

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ object TestSuiteEventHandler {
3535
case Status.Failure =>
3636
val failedMsg =
3737
TestUtils.printThrowable(e.throwable()).getOrElse("")
38+
val location = if (e.throwable().isDefined()) {
39+
val throwable = e.throwable().get.getStackTrace().headOption
40+
throwable.map(stackElement =>
41+
new SingleTestResult.Location(stackElement.getFileName(), stackElement.getLineNumber())
42+
)
43+
} else {
44+
None
45+
}
3846
val formatted =
3947
TestSuiteEventHandler.formatError(
4048
name,
4149
failedMsg,
4250
indentSize = 0
4351
)
44-
SingleTestResult.Failed(name, e.duration, formatted)
52+
SingleTestResult.Failed(name, e.duration, formatted, location)
4553
case _ =>
4654
SingleTestResult.Skipped(name)
4755
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ object SingleTestResult {
3636
def apply(testName: String): Skipped = new Skipped("skipped", testName)
3737
}
3838

39+
final class Location(
40+
val file: String,
41+
val line: Int
42+
)
43+
3944
final class Failed private (
4045
val kind: String,
4146
val testName: String,
4247
val duration: Long,
43-
val error: String
48+
val error: String,
49+
val location: Option[Location]
4450
) extends SingleTestSummary
4551
object Failed {
46-
def apply(testName: String, duration: Long, error: String): Failed =
47-
new Failed("failed", testName, duration, error)
52+
def apply(testName: String, duration: Long, error: String, location: Option[Location] = None): Failed =
53+
new Failed("failed", testName, duration, error, location)
4854
}
4955
}

0 commit comments

Comments
 (0)