We got a test working for panicking with the appropriate number fo failures. Ultimatly we want:

+ An error maessage that says what the failures were
+ Not panicking (so these are effectively error productions)
This commit is contained in:
Chelsea Troy 2022-01-30 18:55:09 -06:00
parent 085c02ffee
commit 4f8d0776b3
8 changed files with 103 additions and 24 deletions

View file

@ -23,12 +23,13 @@ extern fn roc_memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void;
comptime {
const builtin = @import("builtin");
// During tetsts, use the testing allocators to satisfy these functions.
// During tests, use the testing allocators to satisfy these functions.
if (builtin.is_test) {
@export(testing_roc_alloc, .{ .name = "roc_alloc", .linkage = .Strong });
@export(testing_roc_realloc, .{ .name = "roc_realloc", .linkage = .Strong });
@export(testing_roc_dealloc, .{ .name = "roc_dealloc", .linkage = .Strong });
@export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .Strong });
@export(testing_roc_memcpy, .{ .name = "roc_memcpy", .linkage = .Strong });
}
}
@ -56,6 +57,14 @@ fn testing_roc_panic(c_ptr: *c_void, tag_id: u32) callconv(.C) void {
@panic("Roc panicked");
}
fn testing_roc_memcpy(dest: *c_void, src: *c_void, bytes: usize) callconv(.C) ?*c_void {
const zig_dest = @ptrCast([*]u8, dest);
const zig_src = @ptrCast([*]u8, src);
@memcpy(zig_dest, zig_src, bytes);
return dest;
}
pub fn alloc(size: usize, alignment: u32) [*]u8 {
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_alloc, .{ size, alignment }));
}