aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-10-30 15:24:47 +0000
committerGitHub <noreply@github.com>2025-10-30 15:24:47 +0000
commit4174ab9c2c98d798452dd745d5d5dc657d601591 (patch)
tree3c7b27d5e3ebc31e94c2865e017707717ed30c8b /lib/std/testing.zig
parent74c23a237ef5245b63eb06b832a511aabeb715c0 (diff)
parent32779a7c7392d823c945ae0a13a65cf94a4044b8 (diff)
downloadzig-4174ab9c2c98d798452dd745d5d5dc657d601591.tar.gz
zig-4174ab9c2c98d798452dd745d5d5dc657d601591.zip
Merge pull request #25726 from mlugg/std-log-colors
Cache stderr ttyconf, colorize `std.log`, and fix `--webui`
Diffstat (limited to 'lib/std/testing.zig')
-rw-r--r--lib/std/testing.zig8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 7cef6f9c58..b99542e7e5 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -355,7 +355,7 @@ test expectApproxEqRel {
/// This function is intended to be used only in tests. When the two slices are not
/// equal, prints diagnostics to stderr to show exactly how they are not equal (with
/// the differences highlighted in red), then returns a test failure error.
-/// The colorized output is optional and controlled by the return of `std.Io.tty.detectConfig()`.
+/// The colorized output is optional and controlled by the return of `std.Io.tty.Config.detect`.
/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
const diff_index: usize = diff_index: {
@@ -367,9 +367,9 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
break :diff_index if (expected.len == actual.len) return else shortest;
};
if (!backend_can_print) return error.TestExpectedEqual;
- const stderr_w = std.debug.lockStderrWriter(&.{});
+ const stderr_w, const ttyconf = std.debug.lockStderrWriter(&.{});
defer std.debug.unlockStderrWriter();
- failEqualSlices(T, expected, actual, diff_index, stderr_w) catch {};
+ failEqualSlices(T, expected, actual, diff_index, stderr_w, ttyconf) catch {};
return error.TestExpectedEqual;
}
@@ -379,6 +379,7 @@ fn failEqualSlices(
actual: []const T,
diff_index: usize,
w: *std.Io.Writer,
+ ttyconf: std.Io.tty.Config,
) !void {
try w.print("slices differ. first difference occurs at index {d} (0x{X})\n", .{ diff_index, diff_index });
@@ -398,7 +399,6 @@ fn failEqualSlices(
const actual_window = actual[window_start..@min(actual.len, window_start + max_window_size)];
const actual_truncated = window_start + actual_window.len < actual.len;
- const ttyconf = std.Io.tty.detectConfig(.stderr());
var differ = if (T == u8) BytesDiffer{
.expected = expected_window,
.actual = actual_window,