From 58d4653aefbbc671853e99196cce2c090b21480f Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Fri, 27 Feb 2026 03:47:54 +0000 Subject: [PATCH] test: add unit tests for handleOutOfMemory and handleError functions --- src/main.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.zig b/src/main.zig index b95ee14..a379546 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(); -- Gitee