| ... | ... | @@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn; |
| 23 | 23 | pub var zig_exe_path: []const u8 = undefined; |
| 24 | 24 | |
| 25 | 25 | /// 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. |
| 27 | 27 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { |
| 28 | 28 | if (actual_error_union) |actual_payload| { |
| 29 | 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 | 41 | |
| 42 | 42 | /// This function is intended to be used only in tests. When the two values are not |
| 43 | 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 | 45 | /// `actual` is casted to the type of `expected`. |
| 46 | 46 | pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void { |
| 47 | 47 | switch (@typeInfo(@TypeOf(actual))) { |
| ... | ... | @@ -212,7 +212,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt |
| 212 | 212 | |
| 213 | 213 | /// This function is intended to be used only in tests. When the actual value is |
| 214 | 214 | /// 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 | 216 | /// See `math.approxEqAbs` for more informations on the tolerance parameter. |
| 217 | 217 | /// The types must be floating point |
| 218 | 218 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| ... | ... | @@ -244,7 +244,7 @@ test "expectApproxEqAbs" { |
| 244 | 244 | |
| 245 | 245 | /// This function is intended to be used only in tests. When the actual value is |
| 246 | 246 | /// 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 | 248 | /// See `math.approxEqRel` for more informations on the tolerance parameter. |
| 249 | 249 | /// The types must be floating point |
| 250 | 250 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| ... | ... | @@ -279,7 +279,7 @@ test "expectApproxEqRel" { |
| 279 | 279 | |
| 280 | 280 | /// This function is intended to be used only in tests. When the two slices are not |
| 281 | 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 | 283 | /// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead. |
| 284 | 284 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { |
| 285 | 285 | // TODO better printing of the difference |
| ... | ... | @@ -341,8 +341,8 @@ pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:s |
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 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. |
| 346 | 346 | pub fn expect(ok: bool) !void { |
| 347 | 347 | if (!ok) return error.TestUnexpectedResult; |
| 348 | 348 | } |