From 35156988d3a2770808d8e4023960cf7b957470e6 Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Thu, 26 Feb 2026 10:43:08 +0000 Subject: [PATCH 1/2] docs: add documentation for functions in PR #56834 --- src/main.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.zig b/src/main.zig index cd0c056..b95ee14 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,12 +6,18 @@ const Driver = aro.Driver; const Toolchain = aro.Toolchain; const assembly_backend = @import("assembly_backend"); +/// Handles out of memory error by printing a message and optionally exiting. +/// If fast_exit is true, terminates the process immediately; otherwise returns exit code 1. +/// Returns: Exit code (0 on successful handling with fast_exit=false, 1 otherwise) fn handleOutOfMemory(fast_exit: bool) u8 { std.debug.print("out of memory\n", .{}); if (fast_exit) process.exit(1); return 1; } +/// Handles generic errors by dispatching to appropriate handlers based on error type. +/// Currently handles OutOfMemory errors by calling handleOutOfMemory. +/// Returns: Exit code from the specific error handler (typically 0 on success, 1 on failure) fn handleError(fast_exit: bool, er: anyerror) u8 { return switch (er) { error.OutOfMemory => handleOutOfMemory(fast_exit), -- Gitee From 58d4653aefbbc671853e99196cce2c090b21480f Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Fri, 27 Feb 2026 03:47:54 +0000 Subject: [PATCH 2/2] 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