Skip to content

reduce usage of expectEqual in behavior tests #24389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/behavior/align.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const expect = std.testing.expect;
const assert = std.debug.assert;
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
const assert = std.debug.assert;

var foo: u8 align(4) = 100;

Expand Down Expand Up @@ -575,7 +575,7 @@ test "function pointer @intFromPtr/@ptrFromInt roundtrip" {
const nothing_int: usize = @intFromPtr(nothing_ptr);
const nothing_ptr2: *const fn () callconv(.c) void = @ptrFromInt(nothing_int);

try std.testing.expectEqual(nothing_ptr, nothing_ptr2);
try std.testing.expect(nothing_ptr == nothing_ptr2);
}

test "function pointer align mask" {
Expand Down
6 changes: 3 additions & 3 deletions test/behavior/array.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const mem = std.mem;
const assert = std.debug.assert;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
const builtin = @import("builtin");

test "array to slice" {
const a: u32 align(4) = 3;
Expand Down Expand Up @@ -1054,10 +1054,10 @@ test "@splat array with sentinel" {
fn doTheTest(comptime T: type, x: T, comptime s: T) !void {
const arr: [10:s]T = @splat(x);
for (arr) |elem| {
try expectEqual(x, elem);
try expect(x == elem);
}
const ptr: [*]const T = &arr;
try expectEqual(s, ptr[10]); // sentinel correct
try expect(s == ptr[10]); // sentinel correct
}
};

Expand Down
7 changes: 3 additions & 4 deletions test/behavior/asm.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

const is_x86_64_linux = builtin.cpu.arch == .x86_64 and builtin.os.tag == .linux;

Expand Down Expand Up @@ -174,7 +173,7 @@ test "rw constraint (x86_64)" {
: [b] "r" (@as(i32, 13)),
: "flags"
);
try expectEqual(@as(i32, 18), res);
try expect(@as(i32, 18) == res);
}

test "asm modifiers (AArch64)" {
Expand All @@ -189,5 +188,5 @@ test "asm modifiers (AArch64)" {
: [ret] "=r" (-> u32),
: [in] "r" (x),
);
try expectEqual(2 * x, double);
try expect(2 * x == double);
}
3 changes: 1 addition & 2 deletions test/behavior/atomics.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

const supports_128_bit_atomics = switch (builtin.cpu.arch) {
// TODO: Ideally this could be sync'd with the logic in Sema.
Expand Down
17 changes: 8 additions & 9 deletions test/behavior/bit_shifting.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
Expand Down Expand Up @@ -179,7 +178,7 @@ test "Saturating Shift Left" {
inline while (true) : (rhs += 1) {
comptime var lhs: T = std.math.minInt(T);
inline while (true) : (lhs += 1) {
try expectEqual(lhs <<| rhs, shlSat(lhs, rhs));
try expect(lhs <<| rhs == shlSat(lhs, rhs));
if (lhs == std.math.maxInt(T)) break;
}
if (rhs == @bitSizeOf(T) - 1) break;
Expand All @@ -194,12 +193,12 @@ test "Saturating Shift Left" {
try S.testType(u4);
try S.testType(i4);

try expectEqual(0xfffffffffffffff0fffffffffffffff0, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
try expectEqual(0xffffffffffffffffffffffffffffffff, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
try expectEqual(-0x80000000000000000000000000000000, S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
try expect(0xfffffffffffffff0fffffffffffffff0 == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
try expect(0xffffffffffffffffffffffffffffffff == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
try expect(-0x80000000000000000000000000000000 == S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));

try expectEqual(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583, S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
try expectEqual(-57896044618658097711785492504343953926634992332820282019728792003956564819968, S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
try expectEqual(170141183460469231731687303715884105727, S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
try expectEqual(0, S.shlSat(@as(i128, 0), 127));
try expect(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583 == S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
try expect(-57896044618658097711785492504343953926634992332820282019728792003956564819968 == S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
try expect(170141183460469231731687303715884105727 == S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
try expect(0 == S.shlSat(@as(i128, 0), 127));
}
27 changes: 13 additions & 14 deletions test/behavior/bool.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

test "bool literals" {
try expect(true);
Expand All @@ -14,22 +13,22 @@ test "cast bool to int" {

const t = true;
const f = false;
try expectEqual(@as(u32, 1), @intFromBool(t));
try expectEqual(@as(u32, 0), @intFromBool(f));
try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t))));
try expectEqual(0, @as(i1, @bitCast(@intFromBool(f))));
try expectEqual(u1, @TypeOf(@intFromBool(t)));
try expectEqual(u1, @TypeOf(@intFromBool(f)));
try expect(@as(u32, 1) == @intFromBool(t));
try expect(@as(u32, 0) == @intFromBool(f));
try expect(-1 == @as(i1, @bitCast(@intFromBool(t))));
try expect(0 == @as(i1, @bitCast(@intFromBool(f))));
try expect(u1 == @TypeOf(@intFromBool(t)));
try expect(u1 == @TypeOf(@intFromBool(f)));
try nonConstCastIntFromBool(t, f);
}

fn nonConstCastIntFromBool(t: bool, f: bool) !void {
try expectEqual(@as(u32, 1), @intFromBool(t));
try expectEqual(@as(u32, 0), @intFromBool(f));
try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t))));
try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f))));
try expectEqual(u1, @TypeOf(@intFromBool(t)));
try expectEqual(u1, @TypeOf(@intFromBool(f)));
try expect(@as(u32, 1) == @intFromBool(t));
try expect(@as(u32, 0) == @intFromBool(f));
try expect(@as(i1, -1) == @as(i1, @bitCast(@intFromBool(t))));
try expect(@as(i1, 0) == @as(i1, @bitCast(@intFromBool(f))));
try expect(u1 == @TypeOf(@intFromBool(t)));
try expect(u1 == @TypeOf(@intFromBool(f)));
}

test "bool cmp" {
Expand Down
24 changes: 12 additions & 12 deletions test/behavior/builtin_functions_returning_void_or_noreturn.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const builtin = @import("builtin");

var x: u8 = 1;

Expand All @@ -13,15 +13,15 @@ test {
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;

var val: u8 = undefined;
try testing.expectEqual({}, @atomicStore(u8, &val, 0, .unordered));
try testing.expectEqual(void, @TypeOf(@breakpoint()));
try testing.expectEqual({}, @export(&x, .{ .name = "x" }));
try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expectEqual({}, @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
try testing.expectEqual({}, @prefetch(&val, .{}));
try testing.expectEqual({}, @setEvalBranchQuota(0));
try testing.expectEqual({}, @setFloatMode(.optimized));
try testing.expectEqual({}, @setRuntimeSafety(true));
try testing.expect({} == @atomicStore(u8, &val, 0, .unordered));
try testing.expect(void == @TypeOf(@breakpoint()));
try testing.expect({} == @export(&x, .{ .name = "x" }));
try testing.expect({} == @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expect({} == @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expect({} == @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
try testing.expect(noreturn == @TypeOf(if (true) @panic("") else {}));
try testing.expect({} == @prefetch(&val, .{}));
try testing.expect({} == @setEvalBranchQuota(0));
try testing.expect({} == @setFloatMode(.optimized));
try testing.expect({} == @setRuntimeSafety(true));
}
15 changes: 7 additions & 8 deletions test/behavior/call.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const builtin = @import("builtin");
const std = @import("std");
const assert = std.debug.assert;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

test "super basic invocations" {
const foo = struct {
Expand Down Expand Up @@ -434,8 +433,8 @@ test "method call as parameter type" {
return u64;
}
};
try expectEqual(@as(u64, 123), S.foo(S{}, 123));
try expectEqual(@as(u64, 500), S.foo(S{}, 500));
try expect(@as(u64, 123) == S.foo(S{}, 123));
try expect(@as(u64, 500) == S.foo(S{}, 500));
}

test "non-anytype generic parameters provide result type" {
Expand All @@ -445,11 +444,11 @@ test "non-anytype generic parameters provide result type" {

const S = struct {
fn f(comptime T: type, y: T) !void {
try expectEqual(@as(T, 123), y);
try expect(@as(T, 123) == y);
}

fn g(x: anytype, y: @TypeOf(x)) !void {
try expectEqual(@as(@TypeOf(x), 0x222), y);
try expect(@as(@TypeOf(x), 0x222) == y);
}
};

Expand Down Expand Up @@ -612,10 +611,10 @@ test "call with union with zero sized field is not memorized incorrectly" {
}
};
const s1 = U.S(U{ .T = u32 }).tag();
try std.testing.expectEqual(u32, s1);
try std.testing.expect(u32 == s1);

const s2 = U.S(U{ .T = u64 }).tag();
try std.testing.expectEqual(u64, s2);
try std.testing.expect(u64 == s2);
}

test "function call with cast to anyopaque pointer" {
Expand Down
27 changes: 14 additions & 13 deletions test/behavior/cast.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const builtin = @import("builtin");
const std = @import("std");
const assert = std.debug.assert;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const expectEqualSlices = std.testing.expectEqualSlices;
const mem = std.mem;
const maxInt = std.math.maxInt;
const builtin = @import("builtin");

const native_endian = builtin.target.cpu.arch.endian();

test "int to ptr cast" {
Expand Down Expand Up @@ -1738,8 +1739,8 @@ test "peer type resolution: float and comptime-known fixed-width integer" {

const T = @TypeOf(r1);

try expectEqual(@as(T, 100.0), r1);
try expectEqual(@as(T, 1.234), r2);
try expect(@as(T, 100.0) == r1);
try expect(@as(T, 1.234) == r2);
}

test "peer type resolution: same array type with sentinel" {
Expand Down Expand Up @@ -1879,8 +1880,8 @@ test "peer type resolution: C pointer and @TypeOf(null)" {

const T = @TypeOf(r1);

try expectEqual(@as(T, 0x1000), r1);
try expectEqual(@as(T, null), r2);
try expect(@as(T, 0x1000) == r1);
try expect(@as(T, null) == r2);
}

test "peer type resolution: three-way resolution combines error set and optional" {
Expand Down Expand Up @@ -1969,8 +1970,8 @@ test "peer type resolution: optional fixed-width int and comptime_int" {

const T = @TypeOf(r1);

try expectEqual(@as(T, 42), r1);
try expectEqual(@as(T, 50), r2);
try expect(@as(T, 42) == r1);
try expect(@as(T, 50) == r2);
}

test "peer type resolution: array and tuple" {
Expand Down Expand Up @@ -2224,11 +2225,11 @@ test "peer type resolution: tuples with comptime fields" {
const r1 = if (t) a else b;
const r2 = if (t) b else a;

try expectEqual(@as(u32, 1), r1[0]);
try expectEqual(@as(i16, 2), r1[1]);
try expect(@as(u32, 1) == r1[0]);
try expect(@as(i16, 2) == r1[1]);

try expectEqual(@as(u32, 3), r2[0]);
try expectEqual(@as(i16, 4), r2[1]);
try expect(@as(u32, 3) == r2[0]);
try expect(@as(i16, 4) == r2[1]);
}

test "peer type resolution: C pointer and many pointer" {
Expand Down Expand Up @@ -2626,7 +2627,7 @@ test "numeric coercions with undefined" {
var to: f32 = from;
to = @floatFromInt(from);
to = 42.0;
try expectEqual(@as(f32, 42.0), to);
try expect(@as(f32, 42.0) == to);
}

test "15-bit int to float" {
Expand Down Expand Up @@ -2711,7 +2712,7 @@ test "bitcast vector" {

const zerox32: u8x32 = [_]u8{0} ** 32;
const bigsum: u32x8 = @bitCast(zerox32);
try std.testing.expectEqual(0, @reduce(.Add, bigsum));
try std.testing.expect(0 == @reduce(.Add, bigsum));
}

test "peer type resolution: slice of sentinel-terminated array" {
Expand Down
Loading
Loading