diff --git a/src/main.zig b/src/main.zig index b95ee14ee066b8b8ca25f112505fbc734248f4f5..a3795464b99944ed74fc6c0fbc444d5639301acf 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const process = std.process; +const testing = std.testing; const aro = @import("aro"); const Compilation = aro.Compilation; const Driver = aro.Driver; @@ -24,6 +25,21 @@ fn handleError(fast_exit: bool, er: anyerror) u8 { }; } +test "handleOutOfMemory returns 1 when fast_exit is false" { + const result = handleOutOfMemory(false); + try testing.expectEqual(@as(u8, 1), result); +} + +test "handleError returns 1 for OutOfMemory error when fast_exit is false" { + const result = handleError(false, error.OutOfMemory); + try testing.expectEqual(@as(u8, 1), result); +} + +test "handleError handles OutOfMemory error with fast_exit true" { + const result = handleError(true, error.OutOfMemory); + try testing.expectEqual(@as(u8, 1), result); +} + pub fn main() u8 { const link_libc = @import("builtin").link_libc; const gpa = if (link_libc) std.heap.raw_c_allocator else std.heap.GeneralPurposeAllocator(.{}).allocator();