aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-26 18:57:51 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-26 18:57:51 +0000
commitdcd48e7774260e0b21e63393d92b24e053905408 (patch)
treea8949249bb63725b5bbb6247857006aaa480f5a6 /src/test/java
parente47ef5189a0658d1dd7a90d759204bd8cb32bd67 (diff)
Test throwing from catch clause
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java6
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java62
2 files changed, 68 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
index e0477419..27543828 100644
--- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
@@ -78,4 +78,10 @@ public class LlvmPatioCodeGenTests extends PatioExampleTests {
public void whenExceptionIsThrownThenExceptionHandlerForOtherExceptionsIsIgnored() {
}
+
+ @Disabled("WIP")
+ @Test
+ public void catchClauseCanThrow() {
+
+ }
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
index 0111b71c..dc61101d 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -343,6 +343,68 @@ public abstract class PatioExampleTests {
}
@Test
+ public void catchClauseCanThrow() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .addLocal(Patio.val("r1", PatioTypes.INT))
+ .addLocal(Patio.val("r2", PatioTypes.INT))
+ .addLocal(Patio.val("e1", PatioTypes.INT))
+ .addLocal(Patio.val("e2", PatioTypes.INT))
+ .addBodyInstruction(Patio.try_(
+ List.of(Patio.localRef("r1")),
+ List.of(
+ Patio.catchClause(
+ "Error",
+ Patio.localRef("e1"),
+ Patio.block(
+ List.of(),
+ List.of(Patio.int_(1))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(
+ Patio.try_(
+ List.of(Patio.localRef("r2")),
+ List.of(
+ Patio.catchClause(
+ "Error",
+ Patio.localRef("e2"),
+ Patio.block(
+ List.of(
+ Patio.throw_("Error", Patio.int_(0))
+ ),
+ List.of(Patio.int_(2))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(
+ Patio.throw_("Error", Patio.int_(0))
+ ),
+ List.of(Patio.int_(0))
+ )
+ )
+ ),
+ List.of(Patio.localRef("r2"))
+ )
+ ))
+ .addBodyInstruction(Patio.return_(
+ Patio.localRef("r1")
+ ))
+ .build();
+ var patio = Patio.compilationUnit(List.of(
+ Patio.exceptionTypeDefinition("Error", PatioTypes.INT),
+ patioFunction
+ ));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(1));
+ }
+
+ @Test
public void vars() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)