| ... | ... | @@ -50,8 +50,8 @@ pub fn failPrint(comptime fmt: []const u8, args: anytype) void { |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | | /// This function is intended to be used only in tests. It prints diagnostics to stderr |
| 54 | | /// and then returns a test failure error when actual_error_union is not expected_error. |
| 53 | /// This function is intended to be used only in tests. When `actual_error_union` is not |
| 54 | /// `expected_error`, it prints diagnostics to stderr, then returns a test failure error. |
| 55 | 55 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { |
| 56 | 56 | if (actual_error_union) |actual_payload| { |
| 57 | 57 | failPrint("expected error.{s}, found {any}\n", .{ @errorName(expected_error), actual_payload }); |
| ... | ... | @@ -358,7 +358,7 @@ test expectApproxEqRel { |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /// This function is intended to be used only in tests. When the two slices are |
| 361 | | /// not equal, prints diagnostics to stderr to show exactly how they are not |
| 361 | /// not equal, it prints diagnostics to stderr to show exactly how they are not |
| 362 | 362 | /// equal (with the differences highlighted in red), then returns a test |
| 363 | 363 | /// failure error. |
| 364 | 364 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { |
| ... | ... | @@ -567,8 +567,10 @@ test { |
| 567 | 567 | ); |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | | /// This function is intended to be used only in tests. Checks that two slices or two arrays are equal, |
| 571 | | /// including that their sentinel (if any) are the same. Will error if given another type. |
| 570 | /// This function is intended to be used only in tests. When the two slices or two arrays are not equal, |
| 571 | /// or their sentinel (if any) are not the same, it prints diagnostics to stderr to show exactly how |
| 572 | /// they are not equal (with the differences highlighted in red), then returns a test failure error. |
| 573 | /// It partially depends on `expectEquaSlices` for printing diagnostics. |
| 572 | 574 | pub fn expectEqualSentinel(comptime T: type, comptime sentinel: T, expected: [:sentinel]const T, actual: [:sentinel]const T) !void { |
| 573 | 575 | try expectEqualSlices(T, expected, actual); |
| 574 | 576 | |
| ... | ... | @@ -654,6 +656,8 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir { |
| 654 | 656 | }; |
| 655 | 657 | } |
| 656 | 658 | |
| 659 | /// This function is intended to be used only in test. When the two strings are not equal, |
| 660 | /// it prints diagnostics to stderr to show how they are not equal, then returns an error. |
| 657 | 661 | pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void { |
| 658 | 662 | if (std.mem.findDiff(u8, actual, expected)) |diff_index| { |
| 659 | 663 | if (@inComptime()) { |
| ... | ... | @@ -683,6 +687,8 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void { |
| 683 | 687 | } |
| 684 | 688 | } |
| 685 | 689 | |
| 690 | /// This function is intended to be used only in test. When the start of `actual` and `expected_starts_with` |
| 691 | /// are not equal, it prints diagnostics to stderr to show how they are not equal, then returns an error. |
| 686 | 692 | pub fn expectStringStartsWith(actual: []const u8, expected_starts_with: []const u8) !void { |
| 687 | 693 | if (std.mem.startsWith(u8, actual, expected_starts_with)) |
| 688 | 694 | return; |
| ... | ... | @@ -703,6 +709,8 @@ pub fn expectStringStartsWith(actual: []const u8, expected_starts_with: []const |
| 703 | 709 | return error.TestExpectedStartsWith; |
| 704 | 710 | } |
| 705 | 711 | |
| 712 | /// This function is intended to be used only in test. When the end of `actual` and `expected_ends_with` |
| 713 | /// are not equal, it prints diagnostics to stderr to show how they are not equal, then returns an error. |
| 706 | 714 | pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void { |
| 707 | 715 | if (std.mem.endsWith(u8, actual, expected_ends_with)) |
| 708 | 716 | return; |