aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-17 17:23:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-17 17:23:22 -0700
commit9ed3eb9cded4fce2a2ca121ac079af65032347f6 (patch)
treece0f172f1425dedaf6ae52466d1cc4bab128bf9e
parent73e51133c3a143b8838e7f7fed599a33aca1b1f1 (diff)
downloadzig-9ed3eb9cded4fce2a2ca121ac079af65032347f6.tar.gz
zig-9ed3eb9cded4fce2a2ca121ac079af65032347f6.zip
std.testing: fix incorrect docs that mentioned aborting
At some point we changed these functions to return errors instead of aborting.
-rw-r--r--lib/std/testing.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index acd76ab1df..c35de990ef 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn;
pub var zig_exe_path: []const u8 = undefined;
/// This function is intended to be used only in tests. It prints diagnostics to stderr
-/// and then aborts when actual_error_union is not expected_error.
+/// and then returns a test failure error when actual_error_union is not expected_error.
pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
if (actual_error_union) |actual_payload| {
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
/// This function is intended to be used only in tests. When the two values are not
/// equal, prints diagnostics to stderr to show exactly how they are not equal,
-/// then aborts.
+/// then returns a test failure error.
/// `actual` is casted to the type of `expected`.
pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
switch (@typeInfo(@TypeOf(actual))) {
@@ -212,7 +212,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
/// This function is intended to be used only in tests. When the actual value is
/// not approximately equal to the expected value, prints diagnostics to stderr
-/// to show exactly how they are not equal, then aborts.
+/// to show exactly how they are not equal, then returns a test failure error.
/// See `math.approxEqAbs` for more informations on the tolerance parameter.
/// The types must be floating point
pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
@@ -244,7 +244,7 @@ test "expectApproxEqAbs" {
/// This function is intended to be used only in tests. When the actual value is
/// not approximately equal to the expected value, prints diagnostics to stderr
-/// to show exactly how they are not equal, then aborts.
+/// to show exactly how they are not equal, then returns a test failure error.
/// See `math.approxEqRel` for more informations on the tolerance parameter.
/// The types must be floating point
pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
@@ -279,7 +279,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,
-/// then aborts.
+/// then returns a test failure error.
/// 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 {
// TODO better printing of the difference
@@ -341,8 +341,8 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s
}
}
-/// This function is intended to be used only in tests. When `ok` is false, the test fails.
-/// A message is printed to stderr and then abort is called.
+/// This function is intended to be used only in tests.
+/// When `ok` is false, returns a test failure error.
pub fn expect(ok: bool) !void {
if (!ok) return error.TestUnexpectedResult;
}