unnoisy the tests

This commit is contained in:
Emil Lerch 2026-05-08 12:30:48 -07:00
parent 832ce93155
commit 57d3b03623
4 changed files with 25 additions and 3 deletions

View file

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const zfin = @import("../root.zig"); const zfin = @import("../root.zig");
const srf = @import("srf"); const srf = @import("srf");
const history = @import("../history.zig"); const history = @import("../history.zig");
@ -109,6 +110,10 @@ pub fn printGainLoss(
// Stderr helpers // Stderr helpers
pub fn stderrPrint(msg: []const u8) !void { 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 buf: [1024]u8 = undefined;
var writer = std.fs.File.stderr().writer(&buf); var writer = std.fs.File.stderr().writer(&buf);
const out = &writer.interface; const out = &writer.interface;
@ -118,6 +123,7 @@ pub fn stderrPrint(msg: []const u8) !void {
/// Print progress line to stderr: " [N/M] SYMBOL (status)" /// 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 { 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 buf: [256]u8 = undefined;
var writer = std.fs.File.stderr().writer(&buf); var writer = std.fs.File.stderr().writer(&buf);
const out = &writer.interface; 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 /// Print rate-limit wait message to stderr
pub fn stderrRateLimitWait(wait_seconds: u64, color: bool) !void { pub fn stderrRateLimitWait(wait_seconds: u64, color: bool) !void {
if (builtin.is_test) return;
var buf: [256]u8 = undefined; var buf: [256]u8 = undefined;
var writer = std.fs.File.stderr().writer(&buf); var writer = std.fs.File.stderr().writer(&buf);
const out = &writer.interface; const out = &writer.interface;

View file

@ -30,6 +30,7 @@
//! all go through here). The command module stays a thin CLI wrapper. //! all go through here). The command module stays a thin CLI wrapper.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const srf = @import("srf"); const srf = @import("srf");
const snapshot = @import("models/snapshot.zig"); const snapshot = @import("models/snapshot.zig");
const Date = @import("models/date.zig").Date; const Date = @import("models/date.zig").Date;
@ -202,7 +203,12 @@ pub fn loadHistoryDir(
// `bytes` is freed either by LoadedHistory.deinit on success or // `bytes` is freed either by LoadedHistory.deinit on success or
// by the branch below on parse failure no defer-free here. // by the branch below on parse failure no defer-free here.
const snap = parseSnapshotBytes(allocator, bytes) catch |err| { 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); allocator.free(bytes);
continue; continue;
}; };

View file

@ -55,6 +55,7 @@
//! `src/commands/contributions.zig` for the classifier integration. //! `src/commands/contributions.zig` for the classifier integration.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const srf = @import("srf"); const srf = @import("srf");
const Date = @import("date.zig").Date; const Date = @import("date.zig").Date;
@ -239,7 +240,11 @@ pub fn parseTransactionLogFile(
while (try it.next()) |fields| { while (try it.next()) |fields| {
const parsed = fields.to(TransferRecord) catch |err| { 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; continue;
}; };
// String fields on `parsed` point into the iterator's internal // String fields on `parsed` point into the iterator's internal

View file

@ -8,6 +8,7 @@
//! based on available API keys. Callers never need to know which provider was used. //! based on available API keys. Callers never need to know which provider was used.
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const log = std.log.scoped(.service); const log = std.log.scoped(.service);
const Date = @import("models/date.zig").Date; const Date = @import("models/date.zig").Date;
@ -171,7 +172,10 @@ pub const DataService = struct {
.thread_safe = .{ .child_allocator = base_allocator }, .thread_safe = .{ .child_allocator = base_allocator },
.config = config, .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; return self;
} }