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) {...@@ -41,7 +41,8 @@ pub const backend_can_print = switch (builtin.zig_backend) {
41 else => true,41 else => true,
42};42};
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 {
45 if (@inComptime()) {46 if (@inComptime()) {
46 @compileError(std.fmt.comptimePrint(fmt, args));47 @compileError(std.fmt.comptimePrint(fmt, args));
47 } else if (backend_can_print) {48 } else if (backend_can_print) {
...@@ -998,7 +999,8 @@ test "expectEqualDeep composite type" {...@@ -998,7 +999,8 @@ test "expectEqualDeep composite type" {
998 );999 );
999}1000}
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 {
1002 const line_begin_index = if (std.mem.findScalarLast(u8, source[0..indicator_index], '\n')) |line_begin|1004 const line_begin_index = if (std.mem.findScalarLast(u8, source[0..indicator_index], '\n')) |line_begin|
1003 line_begin + 11005 line_begin + 1
1004 else1006 else
...@@ -1017,7 +1019,8 @@ fn failPrintIndicatorLine(source: []const u8, indicator_index: usize) void {...@@ -1017,7 +1019,8 @@ fn failPrintIndicatorLine(source: []const u8, indicator_index: usize) void {
1017 failPrint("^ ('\\x{x:0>2}')\n", .{source[indicator_index]});1019 failPrint("^ ('\\x{x:0>2}')\n", .{source[indicator_index]});
1018}1020}
10191021
1020fn failPrintWithVisibleNewlines(source: []const u8) void {1022/// Helper function for printing test failure information.
1023pub fn failPrintWithVisibleNewlines(source: []const u8) void {
1021 var i: usize = 0;1024 var i: usize = 0;
1022 while (std.mem.findScalar(u8, source[i..], '\n')) |nl| : (i += nl + 1) {1025 while (std.mem.findScalar(u8, source[i..], '\n')) |nl| : (i += nl + 1) {
1023 failPrintLine(source[i..][0..nl]);1026 failPrintLine(source[i..][0..nl]);
...@@ -1025,7 +1028,8 @@ fn failPrintWithVisibleNewlines(source: []const u8) void {...@@ -1025,7 +1028,8 @@ fn failPrintWithVisibleNewlines(source: []const u8) void {
1025 failPrint("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)1028 failPrint("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)
1026}1029}
10271030
1028fn failPrintLine(line: []const u8) void {1031/// Helper function for printing test failure information.
1032pub fn failPrintLine(line: []const u8) void {
1029 if (line.len != 0) switch (line[line.len - 1]) {1033 if (line.len != 0) switch (line[line.len - 1]) {
1030 ' ', '\t' => return failPrint("{s}⏎\n", .{line}), // Return symbol1034 ' ', '\t' => return failPrint("{s}⏎\n", .{line}), // Return symbol
1031 else => {},1035 else => {},