diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-26 15:47:13 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-26 15:49:33 +0000 |
| commit | 1b7e1f872b27493895d44d038763cbb20e869d77 (patch) | |
| tree | 8add52ab2700128e59e4a10771e2ec487a5c97e0 /src/test/java | |
| parent | 52444b565aa3fa5719df3acf490eb11b9337511c (diff) | |
Support Wasm try with no catch blocks
Diffstat (limited to 'src/test/java')
3 files changed, 83 insertions, 25 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java new file mode 100644 index 00000000..54bc52a0 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java @@ -0,0 +1,45 @@ +package org.shedlang.compiler.backends.wasm.structure.binary; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.backends.wasm.structure.ast.instructions.*; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFunction; +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmModule; +import org.shedlang.compiler.backends.wasm.structure.ast.types.WasmValueType; +import org.shedlang.compiler.testing.snapshots.SnapshotResolver; +import org.shedlang.compiler.testing.snapshots.Snapshotter; + +import java.io.IOException; +import java.util.List; + +import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModule; + +@ExtendWith({SnapshotResolver.class}) +public class WasmBinaryFormatInstructionsTests { + // == Exception Instructions (v3 proposal) == + + @Test + public void canSerializeTryWithNoCatchBlocks(Snapshotter snapshotter) throws IOException, InterruptedException { + var module = WasmModule.EMPTY + .addFunction(new WasmFunction( + "f", + List.of(), + List.of(), + List.of(), + new WasmExpression(List.of( + new WasmTry( + new WasmBlockType(List.of(WasmValueType.I32)), + List.of(), + List.of( + new WasmI32Const(42) + ) + ), + new WasmDrop() + )) + )); + + var result = serializeModule(module); + + snapshotter.assertSnapshot(result); + } +} diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java index afc44c79..02314d04 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java @@ -8,17 +8,13 @@ import org.shedlang.compiler.backends.wasm.structure.ast.instructions.WasmI64Con import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmInitFunc; import org.shedlang.compiler.backends.wasm.structure.ast.modules.*; import org.shedlang.compiler.backends.wasm.structure.ast.types.*; -import org.shedlang.compiler.testing.TestProcessRunner; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; -import java.io.FileOutputStream; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.List; -import static org.shedlang.compiler.backends.wasm.structure.WasmObjdump.objdump; +import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModule; @ExtendWith({SnapshotResolver.class}) public class WasmBinaryFormatModulesTests { @@ -368,24 +364,4 @@ public class WasmBinaryFormatModulesTests { snapshotter.assertSnapshot(result); } - - private String serializeModule(WasmModule module) throws IOException, InterruptedException { - Files.createDirectories(Path.of("tests-tmp")); - var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); - var modulePath = temporaryDirectory.resolve("module.wasm"); - System.out.println(modulePath); - - try (var outputStream = new FileOutputStream(modulePath.toFile())) { - WasmBinaryFormatModules.serializeModule(module, outputStream); - } - - validate(modulePath); - - return objdump(modulePath); - } - - private void validate(Path path) throws IOException, InterruptedException { - TestProcessRunner.runCaptureOutput(List.of("wasm-validate", "--enable-exceptions", path.toString())) - .throwOnError(); - } } diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java new file mode 100644 index 00000000..9d11dd18 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java @@ -0,0 +1,37 @@ +package org.shedlang.compiler.backends.wasm.structure.binary; + +import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmModule; +import org.shedlang.compiler.testing.TestProcessRunner; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import static org.shedlang.compiler.backends.wasm.structure.WasmObjdump.objdump; + +public class WasmBinaryFormatTesting { + private WasmBinaryFormatTesting() { + } + + static String serializeModule(WasmModule module) throws IOException, InterruptedException { + Files.createDirectories(Path.of("tests-tmp")); + var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat"); + var modulePath = temporaryDirectory.resolve("module.wasm"); + System.out.println(modulePath); + + try (var outputStream = new FileOutputStream(modulePath.toFile())) { + WasmBinaryFormatModules.serializeModule(module, outputStream); + } + + validate(modulePath); + + return objdump(modulePath); + } + + private static void validate(Path path) throws IOException, InterruptedException { + TestProcessRunner.runCaptureOutput(List.of("wasm-validate", "--enable-exceptions", path.toString())) + .throwOnError(); + } +} |
