commit 73a3bfd1dd63a160fd3776b8394d9336abd1ae99 (tree)
parent 146be2a8cb3272673a99050351b5f394fd1de30b
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Tue, 2 Jun 2020 13:26:49 +0200
Add basic tests for the new builtins
Diffstat:
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -7504,4 +7504,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
, &[_][]const u8{
":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted",
});
+
+ cases.add("wasmMemorySize is a compile error in non-Wasm targets",
+ \\export fn foo() void {
+ \\ _ = @wasmMemorySize();
+ \\ return;
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only",
+ });
+
+ cases.add("wasmMemoryGrow is a compile error in non-Wasm targets",
+ \\export fn foo() void {
+ \\ _ = @wasmMemoryGrow(1);
+ \\ return;
+ \\}
+ , &[_][]const u8{
+ "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only",
+ });
}
diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig
@@ -126,6 +126,9 @@ comptime {
_ = @import("behavior/var_args.zig");
_ = @import("behavior/vector.zig");
_ = @import("behavior/void.zig");
+ if (builtin.arch == .wasm32) {
+ _ = @import("behavior/wasm.zig");
+ }
_ = @import("behavior/while.zig");
_ = @import("behavior/widening.zig");
}
diff --git a/test/stage1/behavior/wasm.zig b/test/stage1/behavior/wasm.zig
@@ -0,0 +1,8 @@
+const std = @import("std");
+const expect = std.testing.expect;
+
+test "memory size and grow" {
+ var prev = @wasmMemorySize();
+ expect(prev == @wasmMemoryGrow(1));
+ expect(prev + 1 == @wasmMemorySize());
+}