54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
package io.gitlab.jfronny.muscript.test;
|
|
|
|
import io.gitlab.jfronny.muscript.StandardLib;
|
|
import io.gitlab.jfronny.muscript.compiler.Parser;
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
|
import io.gitlab.jfronny.muscript.error.LocationalException;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
class StackTraceTest {
|
|
final String source = """
|
|
someInner = { ->
|
|
throw()
|
|
}
|
|
|
|
someOuter = { ->
|
|
someInner()
|
|
}
|
|
|
|
someOuter()
|
|
""";
|
|
|
|
final Scope scope = StandardLib.createScope()
|
|
.set("throw", args -> {
|
|
throw new IllegalArgumentException("Expected Exception");
|
|
});
|
|
|
|
@Test
|
|
void stackTrace() {
|
|
assertEquals("""
|
|
Error at '(' (character 8): Expected Exception
|
|
1 | throw()
|
|
^-- Here
|
|
at someInner (call: line 5)
|
|
at someOuter (call: line 8)""",
|
|
assertThrows(LocationalException.class, () -> Parser.parseScript(source).run(scope))
|
|
.asPrintable().toString());
|
|
}
|
|
|
|
@Test
|
|
void stackTrace2() {
|
|
assertEquals("""
|
|
Error at '(' (character 8): Expected Exception
|
|
1 | throw()
|
|
^-- Here
|
|
at someInner (call: line 5 in some/file.mu)
|
|
at someOuter (call: line 8 in some/file.mu)""",
|
|
assertThrows(LocationalException.class, () -> Parser.parseScript(source, "some/file.mu").run(scope))
|
|
.asPrintable().toString());
|
|
}
|
|
}
|