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;...@@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn;
23pub var zig_exe_path: []const u8 = undefined;23pub var zig_exe_path: []const u8 = undefined;
2424
25/// This function is intended to be used only in tests. It prints diagnostics to stderr25/// 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.
27pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {27pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
28 if (actual_error_union) |actual_payload| {28 if (actual_error_union) |actual_payload| {
29 std.debug.print("expected error.{s}, found {any}\n", .{ @errorName(expected_error), actual_payload });29 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...@@ -41,7 +41,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void
4141
42/// This function is intended to be used only in tests. When the two values are not42/// This function is intended to be used only in tests. When the two values are not
43/// equal, prints diagnostics to stderr to show exactly how they are not equal,43/// equal, prints diagnostics to stderr to show exactly how they are not equal,
44/// then aborts.44/// then returns a test failure error.
45/// `actual` is casted to the type of `expected`.45/// `actual` is casted to the type of `expected`.
46pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {46pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
47 switch (@typeInfo(@TypeOf(actual))) {47 switch (@typeInfo(@TypeOf(actual))) {
...@@ -212,7 +212,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt...@@ -212,7 +212,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
212212
213/// This function is intended to be used only in tests. When the actual value is213/// This function is intended to be used only in tests. When the actual value is
214/// not approximately equal to the expected value, prints diagnostics to stderr214/// 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.
216/// See `math.approxEqAbs` for more informations on the tolerance parameter.216/// See `math.approxEqAbs` for more informations on the tolerance parameter.
217/// The types must be floating point217/// The types must be floating point
218pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {218pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
...@@ -244,7 +244,7 @@ test "expectApproxEqAbs" {...@@ -244,7 +244,7 @@ test "expectApproxEqAbs" {
244244
245/// This function is intended to be used only in tests. When the actual value is245/// This function is intended to be used only in tests. When the actual value is
246/// not approximately equal to the expected value, prints diagnostics to stderr246/// 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.
248/// See `math.approxEqRel` for more informations on the tolerance parameter.248/// See `math.approxEqRel` for more informations on the tolerance parameter.
249/// The types must be floating point249/// The types must be floating point
250pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {250pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
...@@ -279,7 +279,7 @@ test "expectApproxEqRel" {...@@ -279,7 +279,7 @@ test "expectApproxEqRel" {
279279
280/// This function is intended to be used only in tests. When the two slices are not280/// This function is intended to be used only in tests. When the two slices are not
281/// equal, prints diagnostics to stderr to show exactly how they are not equal,281/// equal, prints diagnostics to stderr to show exactly how they are not equal,
282/// then aborts.282/// then returns a test failure error.
283/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.283/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
284pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {284pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
285 // TODO better printing of the difference285 // TODO better printing of the difference
...@@ -341,8 +341,8 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s...@@ -341,8 +341,8 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s
341 }341 }
342}342}
343343
344/// This function is intended to be used only in tests. When `ok` is false, the test fails.344/// This function is intended to be used only in tests.
345/// A message is printed to stderr and then abort is called.345/// When `ok` is false, returns a test failure error.
346pub fn expect(ok: bool) !void {346pub fn expect(ok: bool) !void {
347 if (!ok) return error.TestUnexpectedResult;347 if (!ok) return error.TestUnexpectedResult;
348}348}