authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-17 17:23:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-17 17:23:22-07:00
log9ed3eb9cded4fce2a2ca121ac079af65032347f6
treece0f172f1425dedaf6ae52466d1cc4bab128bf9e
parent73e51133c3a143b8838e7f7fed599a33aca1b1f1

std.testing: fix incorrect docs that mentioned aborting

At some point we changed these functions to return errors instead of aborting.

1 files changed, 7 insertions(+), 7 deletions(-)

lib/std/testing.zig+7-7
......@@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn;
2323pub var zig_exe_path: []const u8 = undefined;
2424
2525/// This function is intended to be used only in tests. It prints diagnostics to stderr
26/// and then aborts when actual_error_union is not expected_error.
26/// and then returns a test failure error when actual_error_union is not expected_error.
2727pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
2828 if (actual_error_union) |actual_payload| {
2929 std.debug.print("expected error.{s}, found {any}\n", .{ @errorName(expected_error), actual_payload });
......@@ -41,7 +41,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void
4141
4242/// This function is intended to be used only in tests. When the two values are not
4343/// equal, prints diagnostics to stderr to show exactly how they are not equal,
44/// then aborts.
44/// then returns a test failure error.
4545/// `actual` is casted to the type of `expected`.
4646pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
4747 switch (@typeInfo(@TypeOf(actual))) {
......@@ -212,7 +212,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
212212
213213/// This function is intended to be used only in tests. When the actual value is
214214/// not approximately equal to the expected value, prints diagnostics to stderr
215/// to show exactly how they are not equal, then aborts.
215/// to show exactly how they are not equal, then returns a test failure error.
216216/// See `math.approxEqAbs` for more informations on the tolerance parameter.
217217/// The types must be floating point
218218pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
......@@ -244,7 +244,7 @@ test "expectApproxEqAbs" {
244244
245245/// This function is intended to be used only in tests. When the actual value is
246246/// not approximately equal to the expected value, prints diagnostics to stderr
247/// to show exactly how they are not equal, then aborts.
247/// to show exactly how they are not equal, then returns a test failure error.
248248/// See `math.approxEqRel` for more informations on the tolerance parameter.
249249/// The types must be floating point
250250pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
......@@ -279,7 +279,7 @@ test "expectApproxEqRel" {
279279
280280/// This function is intended to be used only in tests. When the two slices are not
281281/// equal, prints diagnostics to stderr to show exactly how they are not equal,
282/// then aborts.
282/// then returns a test failure error.
283283/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
284284pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
285285 // TODO better printing of the difference
......@@ -341,8 +341,8 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s
341341 }
342342}
343343
344/// This function is intended to be used only in tests. When `ok` is false, the test fails.
345/// A message is printed to stderr and then abort is called.
344/// This function is intended to be used only in tests.
345/// When `ok` is false, returns a test failure error.
346346pub fn expect(ok: bool) !void {
347347 if (!ok) return error.TestUnexpectedResult;
348348}