| ... | @@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn; | ... | @@ -23,7 +23,7 @@ pub var log_level = std.log.Level.warn; |
| 23 | pub var zig_exe_path: []const u8 = undefined; | 23 | pub var zig_exe_path: []const u8 = undefined; |
| 24 | | 24 | |
| 25 | /// This function is intended to be used only in tests. It prints diagnostics to stderr | 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 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { | 27 | pub 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 |
| 41 | | 41 | |
| 42 | /// This function is intended to be used only in tests. When the two values are not | 42 | /// 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`. |
| 46 | pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void { | 46 | pub 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 |
| 212 | | 212 | |
| 213 | /// This function is intended to be used only in tests. When the actual value is | 213 | /// 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 stderr | 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 | /// 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 point | 217 | /// The types must be floating point |
| 218 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | 218 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| ... | @@ -244,7 +244,7 @@ test "expectApproxEqAbs" { | ... | @@ -244,7 +244,7 @@ test "expectApproxEqAbs" { |
| 244 | | 244 | |
| 245 | /// This function is intended to be used only in tests. When the actual value is | 245 | /// 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 stderr | 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 | /// 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 point | 249 | /// The types must be floating point |
| 250 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | 250 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { |
| ... | @@ -279,7 +279,7 @@ test "expectApproxEqRel" { | ... | @@ -279,7 +279,7 @@ test "expectApproxEqRel" { |
| 279 | | 279 | |
| 280 | /// This function is intended to be used only in tests. When the two slices are not | 280 | /// 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. |
| 284 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { | 284 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { |
| 285 | // TODO better printing of the difference | 285 | // 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 | } |
| 343 | | 343 | |
| 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. |
| 346 | pub fn expect(ok: bool) !void { | 346 | pub fn expect(ok: bool) !void { |
| 347 | if (!ok) return error.TestUnexpectedResult; | 347 | if (!ok) return error.TestUnexpectedResult; |
| 348 | } | 348 | } |