From 1ab6fd8353ca224caf4740ec2c3133e660f0ce34 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 8 May 2026 12:30:48 -0700 Subject: [PATCH] unnoisy the tests --- src/commands/common.zig | 7 +++++++ src/history.zig | 8 +++++++- src/models/transaction_log.zig | 7 ++++++- src/service.zig | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/commands/common.zig b/src/commands/common.zig index 946d331..b8b4a67 100644 --- a/src/commands/common.zig +++ b/src/commands/common.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const zfin = @import("../root.zig"); const srf = @import("srf"); const history = @import("../history.zig"); @@ -109,6 +110,10 @@ pub fn printGainLoss( // ── Stderr helpers ─────────────────────────────────────────── pub fn stderrPrint(msg: []const u8) !void { + // Under `zig build test` these messages are just noise — tests + // that exercise error paths emit the same usage/hint strings on + // every run. Real CLI users always reach the real stderr. + if (builtin.is_test) return; var buf: [1024]u8 = undefined; var writer = std.fs.File.stderr().writer(&buf); const out = &writer.interface; @@ -118,6 +123,7 @@ pub fn stderrPrint(msg: []const u8) !void { /// Print progress line to stderr: " [N/M] SYMBOL (status)" pub fn stderrProgress(symbol: []const u8, status: []const u8, current: usize, total: usize, color: bool) !void { + if (builtin.is_test) return; var buf: [256]u8 = undefined; var writer = std.fs.File.stderr().writer(&buf); const out = &writer.interface; @@ -133,6 +139,7 @@ pub fn stderrProgress(symbol: []const u8, status: []const u8, current: usize, to /// Print rate-limit wait message to stderr pub fn stderrRateLimitWait(wait_seconds: u64, color: bool) !void { + if (builtin.is_test) return; var buf: [256]u8 = undefined; var writer = std.fs.File.stderr().writer(&buf); const out = &writer.interface; diff --git a/src/history.zig b/src/history.zig index 7c9bef8..d67ba14 100644 --- a/src/history.zig +++ b/src/history.zig @@ -30,6 +30,7 @@ //! all go through here). The command module stays a thin CLI wrapper. const std = @import("std"); +const builtin = @import("builtin"); const srf = @import("srf"); const snapshot = @import("models/snapshot.zig"); const Date = @import("models/date.zig").Date; @@ -202,7 +203,12 @@ pub fn loadHistoryDir( // `bytes` is freed either by LoadedHistory.deinit on success or // by the branch below on parse failure — no defer-free here. const snap = parseSnapshotBytes(allocator, bytes) catch |err| { - std.log.warn("history: failed to parse {s}: {s}", .{ full_path, @errorName(err) }); + // Tests intentionally feed malformed snapshots to exercise + // the error path — suppress the warn under `zig build test` + // so real parse failures stay visible in production runs. + if (!builtin.is_test) { + std.log.warn("history: failed to parse {s}: {s}", .{ full_path, @errorName(err) }); + } allocator.free(bytes); continue; }; diff --git a/src/models/transaction_log.zig b/src/models/transaction_log.zig index b3486b4..511bb16 100644 --- a/src/models/transaction_log.zig +++ b/src/models/transaction_log.zig @@ -55,6 +55,7 @@ //! `src/commands/contributions.zig` for the classifier integration. const std = @import("std"); +const builtin = @import("builtin"); const srf = @import("srf"); const Date = @import("date.zig").Date; @@ -239,7 +240,11 @@ pub fn parseTransactionLogFile( while (try it.next()) |fields| { const parsed = fields.to(TransferRecord) catch |err| { - logger.warn("skipping malformed transfer record: {s}", .{@errorName(err)}); + // Tests intentionally feed malformed records to exercise the + // skip path; real parse failures stay visible outside tests. + if (!builtin.is_test) { + logger.warn("skipping malformed transfer record: {s}", .{@errorName(err)}); + } continue; }; // String fields on `parsed` point into the iterator's internal diff --git a/src/service.zig b/src/service.zig index 3c70e06..0bb49a7 100644 --- a/src/service.zig +++ b/src/service.zig @@ -8,6 +8,7 @@ //! based on available API keys. Callers never need to know which provider was used. const std = @import("std"); +const builtin = @import("builtin"); const log = std.log.scoped(.service); const Date = @import("models/date.zig").Date; @@ -171,7 +172,10 @@ pub const DataService = struct { .thread_safe = .{ .child_allocator = base_allocator }, .config = config, }; - self.logMissingKeys(); + // Missing-key warnings are noise under `zig build test` where + // every test that spins up a DataService re-emits the whole + // block. Real users always see them at CLI/TUI startup. + if (!builtin.is_test) self.logMissingKeys(); return self; }