Skip to content

Commit 921d329

Browse files
committed
Test exception in worksheet evaluation
1 parent 036201f commit 921d329

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

language-server/test/dotty/tools/languageserver/WorksheetTest.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class WorksheetTest {
8484
.evaluate(m1, "1:val foo: Int = 1\nval bar: Int = 2")
8585
}
8686

87+
@Test def evaluationException: Unit = {
88+
ws"""${m1}val foo = 1 / 0
89+
val bar = 2""".withSource
90+
.evaluateNonStrict(m1, "1:java.lang.ArithmeticException: / by zero",
91+
"2:val bar: Int = 2")
92+
}
93+
8794
@Test def worksheetCompletion(): Unit = {
8895
ws"""class Foo { def bar = 123 }
8996
val x = new Foo

language-server/test/dotty/tools/languageserver/util/CodeTester.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,19 @@ class CodeTester(sources: List[SourceWithPositions], actions: List[Action]) {
127127
* @see dotty.tools.languageserver.util.actions.WorksheetEvaluate
128128
*/
129129
def evaluate(marker: CodeMarker, expected: String*): this.type =
130-
doAction(new WorksheetEvaluate(marker, expected))
130+
doAction(new WorksheetEvaluate(marker, expected, strict = true))
131+
132+
/**
133+
* Triggers evaluation of the worksheet specified by `marker`, verifies that each line of output
134+
* starts with `expected`.
135+
*
136+
* @param marker A marker a identifies the worksheet to evaluate.
137+
* @param expected The expected starts of output.
138+
*
139+
* @see dotty.tools.languageserver.util.actions.WorksheetEvaluate
140+
*/
141+
def evaluateNonStrict(marker: CodeMarker, expected: String*): this.type =
142+
doAction(new WorksheetEvaluate(marker, expected, strict = false))
131143

132144
/**
133145
* Triggers evaluation of the worksheet specified by `marker`, then verifies that execution can be

language-server/test/dotty/tools/languageserver/util/actions/WorksheetEvaluate.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package dotty.tools.languageserver.util.actions
33
import dotty.tools.languageserver.util.PositionContext
44
import dotty.tools.languageserver.util.embedded.CodeMarker
55

6-
import org.junit.Assert.{assertEquals, fail}
6+
import org.junit.Assert.{assertEquals, assertTrue, fail}
77

8-
class WorksheetEvaluate(marker: CodeMarker, expected: Seq[String]) extends WorksheetAction {
8+
class WorksheetEvaluate(marker: CodeMarker, expected: Seq[String], strict: Boolean) extends WorksheetAction {
99

1010
private final val evaluationTimeoutMs = 30 * 1000
1111

@@ -20,7 +20,13 @@ class WorksheetEvaluate(marker: CodeMarker, expected: Seq[String]) extends Works
2020
Thread.sleep(100)
2121
}
2222

23-
assertEquals(expected, getLogs(marker).init)
23+
if (strict) {
24+
assertEquals(expected, getLogs(marker).init)
25+
} else {
26+
expected.zip(getLogs(marker).init).foreach {
27+
case (expected, message) => assertTrue(s"'$message' didn't start with '$expected'", message.startsWith(expected))
28+
}
29+
}
2430
client.log.clear()
2531
}
2632

0 commit comments

Comments
 (0)