Skip to content

Commit c768d69

Browse files
committed
test: cover parseHeapSize (--heap CLI parsing)
A coverage audit found main.zig's CLI flag parsing has almost no test coverage. parseHeapSize (backing --heap) checked out clean -- no bug found -- but had zero tests; adds a regression guard on the k/m/g suffix table and the "invalid input silently becomes 0" contract.
1 parent d148e8e commit c768d69

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/main.zig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,30 @@ fn testCaptureWrite(s: []const u8) void {
11921192
test_capture_len += avail;
11931193
}
11941194

1195+
// Coverage gap audit (2026-08-20): parseHeapSize backs --heap and had zero
1196+
// test coverage — same "no e2e/CLI test harness at all" gap the audit found
1197+
// for main.zig's flag parsing generally. Unlike splitPatternPort, this one
1198+
// checked out clean: no bug found, but worth having a regression guard on
1199+
// the suffix table and the "invalid input silently becomes 0" contract
1200+
// (callers treat 0 as "use the default heap size", not a hard error).
1201+
test "parseHeapSize parses k/m/g suffixes case-insensitively" {
1202+
try std.testing.expectEqual(@as(usize, 100), parseHeapSize("100"));
1203+
try std.testing.expectEqual(@as(usize, 4 * 1024), parseHeapSize("4k"));
1204+
try std.testing.expectEqual(@as(usize, 4 * 1024), parseHeapSize("4K"));
1205+
try std.testing.expectEqual(@as(usize, 16 * 1024 * 1024), parseHeapSize("16m"));
1206+
try std.testing.expectEqual(@as(usize, 16 * 1024 * 1024), parseHeapSize("16M"));
1207+
try std.testing.expectEqual(@as(usize, 1024 * 1024 * 1024), parseHeapSize("1g"));
1208+
try std.testing.expectEqual(@as(usize, 1024 * 1024 * 1024), parseHeapSize("1G"));
1209+
}
1210+
1211+
test "parseHeapSize returns 0 for empty, non-numeric, or suffix-only input" {
1212+
try std.testing.expectEqual(@as(usize, 0), parseHeapSize(""));
1213+
try std.testing.expectEqual(@as(usize, 0), parseHeapSize("abc"));
1214+
try std.testing.expectEqual(@as(usize, 0), parseHeapSize("k")); // no digits before the suffix
1215+
try std.testing.expectEqual(@as(usize, 0), parseHeapSize("-5m")); // parseUnsigned rejects the sign
1216+
try std.testing.expectEqual(@as(usize, 0), parseHeapSize("4mb")); // trailing garbage after the suffix
1217+
}
1218+
11951219
// Coverage gap audit (2026-08-19): splitPatternPort backs both
11961220
// --net-listen-allow and --net-dial-allow (added this session) and had
11971221
// zero test coverage of its own — worth checking carefully since it was

0 commit comments

Comments
 (0)