Remove stderr pollution in tests

This commit is contained in:
Lyssieth 2024-11-28 17:57:44 +02:00
parent cd86e774d5
commit d3703aa23d
Signed by untrusted user who does not match committer: lyssieth
GPG key ID: 200268854934CFAB

View file

@ -249,6 +249,11 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T {
}
}
if (builtin.is_test) {
// early return to not pollute the stderr
return error.NoValueForFlag;
}
if (inDebugMode) {
log.warn("flag `{s}` expected a value, but none was provided", .{f.name});
log.warn("expected type: {s}", .{niceTypeName(@TypeOf(fie.*.value))});
@ -325,11 +330,11 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T {
}
} else {
if (builtin.is_test) {
log.warn("could not find positional argument for `{s}`", .{field.name});
} else {
log.err("could not find positional argument for `{s}`", .{field.name});
// early return to not pollute the stderr
return error.NoArgumentFound;
}
log.err("could not find positional argument for `{s}`", .{field.name});
log.warn("hint: expected type: {s}", .{niceTypeName(@TypeOf(fie.*.value))});
log.warn("hint: try `<value>`", .{});
return error.NoArgumentFound;