authorgravatar for k4@noreply.codeberg.orgK4 <k4@noreply.codeberg.org> 2026-07-28 19:10:53+03:00
committergravatar for k4@noreply.codeberg.orgK4 <k4@noreply.codeberg.org> 2026-08-05 11:17:43+03:00
logf7bb482ff38973a94ef693d558993aeac26fc991
tree12109fb1b45b5978b34c7f85c6c88a237e6ac89d
parent7aef9e5fb2cd17859510d80b25a8e9f5374eeadc

std.testing: make `failPrint*` functions public

Also adds this doc comment to each of them: `/// Helper function for printing test failure information.`

1 files changed, 8 insertions(+), 4 deletions(-)

lib/std/testing.zig+8-4
......@@ -41,7 +41,8 @@ pub const backend_can_print = switch (builtin.zig_backend) {
4141 else => true,
4242};
4343
44fn failPrint(comptime fmt: []const u8, args: anytype) void {
44/// Helper function for printing test failure information.
45pub fn failPrint(comptime fmt: []const u8, args: anytype) void {
4546 if (@inComptime()) {
4647 @compileError(std.fmt.comptimePrint(fmt, args));
4748 } else if (backend_can_print) {
......@@ -998,7 +999,8 @@ test "expectEqualDeep composite type" {
998999 );
9991000}
10001001
1001fn failPrintIndicatorLine(source: []const u8, indicator_index: usize) void {
1002/// Helper function for printing test failure information.
1003pub fn failPrintIndicatorLine(source: []const u8, indicator_index: usize) void {
10021004 const line_begin_index = if (std.mem.findScalarLast(u8, source[0..indicator_index], '\n')) |line_begin|
10031005 line_begin + 1
10041006 else
......@@ -1017,7 +1019,8 @@ fn failPrintIndicatorLine(source: []const u8, indicator_index: usize) void {
10171019 failPrint("^ ('\\x{x:0>2}')\n", .{source[indicator_index]});
10181020}
10191021
1020fn failPrintWithVisibleNewlines(source: []const u8) void {
1022/// Helper function for printing test failure information.
1023pub fn failPrintWithVisibleNewlines(source: []const u8) void {
10211024 var i: usize = 0;
10221025 while (std.mem.findScalar(u8, source[i..], '\n')) |nl| : (i += nl + 1) {
10231026 failPrintLine(source[i..][0..nl]);
......@@ -1025,7 +1028,8 @@ fn failPrintWithVisibleNewlines(source: []const u8) void {
10251028 failPrint("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)
10261029}
10271030
1028fn failPrintLine(line: []const u8) void {
1031/// Helper function for printing test failure information.
1032pub fn failPrintLine(line: []const u8) void {
10291033 if (line.len != 0) switch (line[line.len - 1]) {
10301034 ' ', '\t' => return failPrint("{s}⏎\n", .{line}), // Return symbol
10311035 else => {},