diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-26 18:57:51 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-26 18:57:51 +0000 |
| commit | dcd48e7774260e0b21e63393d92b24e053905408 (patch) | |
| tree | a8949249bb63725b5bbb6247857006aaa480f5a6 /src/test/java | |
| parent | e47ef5189a0658d1dd7a90d759204bd8cb32bd67 (diff) | |
Test throwing from catch clause
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java | 6 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 62 |
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) |
