aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2022-07-11 04:17:48 -0700
committerVeikka Tuominen <git@vexu.eu>2022-07-16 12:32:20 +0300
commit43770c010321d965aba716d717e8470ae0ae966d (patch)
tree187ed372da78f8732180622e41e0f784faf38915 /lib/std/testing.zig
parentb2486fbc5e83cca2ce31a6a16b2ad4ff8df170df (diff)
downloadzig-43770c010321d965aba716d717e8470ae0ae966d.tar.gz
zig-43770c010321d965aba716d717e8470ae0ae966d.zip
Fix checkAllAllocationFailures being too strict when checking arg types
Before this would fail to compile: ``` fn testFn(alloc: std.mem.Allocator, arr: []const u8) !void { _ = alloc; _ = arr; } test "checkAll" { var arr = [_]u8{ 1, 2, 3 }; try std.testing.checkAllAllocationFailures(std.testing.allocator, testFn, .{arr[0..]}); } ``` with the error `error: Unexpected type for extra argument at index 0: expected []const u8, found *[3]u8` By removing this strict equality check, we allow the type checking to be done during the `@field(args, arg_i_str) = @field(extra_args, field.name);` instead, which then allows for things like type coercion to work, but still will give a compile error if the types are incorrect. So, after this change, the above succeeds (because `*[3]u8` can be coerced to `[]const u8`). The new compile error when providing an incorrect type that can't be coerced looks like this: ``` zig/lib/std/testing.zig:639:35: error: expected type '[]const u8', found '*[3]u32' @field(args, arg_i_str) = @field(extra_args, field.name); ^ ```
Diffstat (limited to 'lib/std/testing.zig')
-rw-r--r--lib/std/testing.zig4
1 files changed, 0 insertions, 4 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 97274533df..1deccce68b 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -664,10 +664,6 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
// the failing allocator in field @"0" before each @call)
var args: ArgsTuple = undefined;
inline for (@typeInfo(@TypeOf(extra_args)).Struct.fields) |field, i| {
- const expected_type = fn_args_fields[i + 1].field_type;
- if (expected_type != field.field_type) {
- @compileError("Unexpected type for extra argument at index " ++ (comptime std.fmt.comptimePrint("{d}", .{i})) ++ ": expected " ++ @typeName(expected_type) ++ ", found " ++ @typeName(field.field_type));
- }
const arg_i_str = comptime str: {
var str_buf: [100]u8 = undefined;
const args_i = i + 1;