diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-26 18:56:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-26 18:56:21 +0000 |
| commit | e47ef5189a0658d1dd7a90d759204bd8cb32bd67 (patch) | |
| tree | fd4e498a2561c5e63883a2e892b69b3cf2767df7 /src/test/java | |
| parent | aa13c97dac536bd1c4bf2f4e5c6ee505a487c634 (diff) | |
Add test for Patio for ignoring non-matching exception handlers
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 | 61 |
2 files changed, 67 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 56262676..e0477419 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java @@ -72,4 +72,10 @@ public class LlvmPatioCodeGenTests extends PatioExampleTests { public void whenExceptionIsThrownThenFirstMatchingExceptionHandlerIsUsed() { } + + @Disabled("WIP") + @Test + public void whenExceptionIsThrownThenExceptionHandlerForOtherExceptionsIsIgnored() { + + } } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index d1314e5c..0111b71c 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -282,6 +282,67 @@ public abstract class PatioExampleTests { } @Test + public void whenExceptionIsThrownThenExceptionHandlerForOtherExceptionsIsIgnored() 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( + "OtherError", + Patio.localRef("e2"), + Patio.block( + List.of(), + 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), + Patio.exceptionTypeDefinition("OtherError", 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) |
