Skip to content

Commit 86653d7

Browse files
committed
24361: reduce usage of expectEqual in behavior tests
1 parent 5b4e982 commit 86653d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+711
-723
lines changed

test/behavior/align.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const std = @import("std");
22
const expect = std.testing.expect;
3+
const assert = std.debug.assert;
34
const builtin = @import("builtin");
45
const native_arch = builtin.target.cpu.arch;
5-
const assert = std.debug.assert;
66

77
var foo: u8 align(4) = 100;
88

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

578-
try std.testing.expectEqual(nothing_ptr, nothing_ptr2);
578+
try std.testing.expect(nothing_ptr == nothing_ptr2);
579579
}
580580

581581
test "function pointer align mask" {

test/behavior/array.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const testing = std.testing;
43
const mem = std.mem;
54
const assert = std.debug.assert;
65
const expect = testing.expect;
76
const expectEqual = testing.expectEqual;
7+
const builtin = @import("builtin");
88

99
test "array to slice" {
1010
const a: u32 align(4) = 3;
@@ -1054,10 +1054,10 @@ test "@splat array with sentinel" {
10541054
fn doTheTest(comptime T: type, x: T, comptime s: T) !void {
10551055
const arr: [10:s]T = @splat(x);
10561056
for (arr) |elem| {
1057-
try expectEqual(x, elem);
1057+
try expect(x == elem);
10581058
}
10591059
const ptr: [*]const T = &arr;
1060-
try expectEqual(s, ptr[10]); // sentinel correct
1060+
try expect(s == ptr[10]); // sentinel correct
10611061
}
10621062
};
10631063

test/behavior/asm.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const expect = std.testing.expect;
4-
const expectEqual = std.testing.expectEqual;
3+
const builtin = @import("builtin");
54

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

@@ -174,7 +173,7 @@ test "rw constraint (x86_64)" {
174173
: [b] "r" (@as(i32, 13)),
175174
: "flags"
176175
);
177-
try expectEqual(@as(i32, 18), res);
176+
try expect(@as(i32, 18) == res);
178177
}
179178

180179
test "asm modifiers (AArch64)" {
@@ -189,5 +188,5 @@ test "asm modifiers (AArch64)" {
189188
: [ret] "=r" (-> u32),
190189
: [in] "r" (x),
191190
);
192-
try expectEqual(2 * x, double);
191+
try expect(2 * x == double);
193192
}

test/behavior/atomics.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const expect = std.testing.expect;
4-
const expectEqual = std.testing.expectEqual;
3+
const builtin = @import("builtin");
54

65
const supports_128_bit_atomics = switch (builtin.cpu.arch) {
76
// TODO: Ideally this could be sync'd with the logic in Sema.

test/behavior/bit_shifting.zig

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const std = @import("std");
22
const expect = std.testing.expect;
3-
const expectEqual = std.testing.expectEqual;
43
const builtin = @import("builtin");
54

65
fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
@@ -179,7 +178,7 @@ test "Saturating Shift Left" {
179178
inline while (true) : (rhs += 1) {
180179
comptime var lhs: T = std.math.minInt(T);
181180
inline while (true) : (lhs += 1) {
182-
try expectEqual(lhs <<| rhs, shlSat(lhs, rhs));
181+
try expect(lhs <<| rhs == shlSat(lhs, rhs));
183182
if (lhs == std.math.maxInt(T)) break;
184183
}
185184
if (rhs == @bitSizeOf(T) - 1) break;
@@ -194,12 +193,12 @@ test "Saturating Shift Left" {
194193
try S.testType(u4);
195194
try S.testType(i4);
196195

197-
try expectEqual(0xfffffffffffffff0fffffffffffffff0, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
198-
try expectEqual(0xffffffffffffffffffffffffffffffff, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
199-
try expectEqual(-0x80000000000000000000000000000000, S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
196+
try expect(0xfffffffffffffff0fffffffffffffff0 == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
197+
try expect(0xffffffffffffffffffffffffffffffff == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
198+
try expect(-0x80000000000000000000000000000000 == S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
200199

201-
try expectEqual(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583, S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
202-
try expectEqual(-57896044618658097711785492504343953926634992332820282019728792003956564819968, S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
203-
try expectEqual(170141183460469231731687303715884105727, S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
204-
try expectEqual(0, S.shlSat(@as(i128, 0), 127));
200+
try expect(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583 == S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
201+
try expect(-57896044618658097711785492504343953926634992332820282019728792003956564819968 == S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
202+
try expect(170141183460469231731687303715884105727 == S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
203+
try expect(0 == S.shlSat(@as(i128, 0), 127));
205204
}

test/behavior/bool.zig

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const expect = std.testing.expect;
4-
const expectEqual = std.testing.expectEqual;
3+
const builtin = @import("builtin");
54

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

1514
const t = true;
1615
const f = false;
17-
try expectEqual(@as(u32, 1), @intFromBool(t));
18-
try expectEqual(@as(u32, 0), @intFromBool(f));
19-
try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t))));
20-
try expectEqual(0, @as(i1, @bitCast(@intFromBool(f))));
21-
try expectEqual(u1, @TypeOf(@intFromBool(t)));
22-
try expectEqual(u1, @TypeOf(@intFromBool(f)));
16+
try expect(@as(u32, 1) == @intFromBool(t));
17+
try expect(@as(u32, 0) == @intFromBool(f));
18+
try expect(-1 == @as(i1, @bitCast(@intFromBool(t))));
19+
try expect(0 == @as(i1, @bitCast(@intFromBool(f))));
20+
try expect(u1 == @TypeOf(@intFromBool(t)));
21+
try expect(u1 == @TypeOf(@intFromBool(f)));
2322
try nonConstCastIntFromBool(t, f);
2423
}
2524

2625
fn nonConstCastIntFromBool(t: bool, f: bool) !void {
27-
try expectEqual(@as(u32, 1), @intFromBool(t));
28-
try expectEqual(@as(u32, 0), @intFromBool(f));
29-
try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t))));
30-
try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f))));
31-
try expectEqual(u1, @TypeOf(@intFromBool(t)));
32-
try expectEqual(u1, @TypeOf(@intFromBool(f)));
26+
try expect(@as(u32, 1) == @intFromBool(t));
27+
try expect(@as(u32, 0) == @intFromBool(f));
28+
try expect(@as(i1, -1) == @as(i1, @bitCast(@intFromBool(t))));
29+
try expect(@as(i1, 0) == @as(i1, @bitCast(@intFromBool(f))));
30+
try expect(u1 == @TypeOf(@intFromBool(t)));
31+
try expect(u1 == @TypeOf(@intFromBool(f)));
3332
}
3433

3534
test "bool cmp" {
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
2-
const builtin = @import("builtin");
32
const testing = std.testing;
3+
const builtin = @import("builtin");
44

55
var x: u8 = 1;
66

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

1515
var val: u8 = undefined;
16-
try testing.expectEqual({}, @atomicStore(u8, &val, 0, .unordered));
17-
try testing.expectEqual(void, @TypeOf(@breakpoint()));
18-
try testing.expectEqual({}, @export(&x, .{ .name = "x" }));
19-
try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
20-
try testing.expectEqual({}, @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
21-
try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
22-
try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
23-
try testing.expectEqual({}, @prefetch(&val, .{}));
24-
try testing.expectEqual({}, @setEvalBranchQuota(0));
25-
try testing.expectEqual({}, @setFloatMode(.optimized));
26-
try testing.expectEqual({}, @setRuntimeSafety(true));
16+
try testing.expect({} == @atomicStore(u8, &val, 0, .unordered));
17+
try testing.expect(void == @TypeOf(@breakpoint()));
18+
try testing.expect({} == @export(&x, .{ .name = "x" }));
19+
try testing.expect({} == @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
20+
try testing.expect({} == @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
21+
try testing.expect({} == @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
22+
try testing.expect(noreturn == @TypeOf(if (true) @panic("") else {}));
23+
try testing.expect({} == @prefetch(&val, .{}));
24+
try testing.expect({} == @setEvalBranchQuota(0));
25+
try testing.expect({} == @setFloatMode(.optimized));
26+
try testing.expect({} == @setRuntimeSafety(true));
2727
}

test/behavior/call.zig

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const builtin = @import("builtin");
21
const std = @import("std");
32
const assert = std.debug.assert;
43
const expect = std.testing.expect;
5-
const expectEqual = std.testing.expectEqual;
4+
const builtin = @import("builtin");
65

76
test "super basic invocations" {
87
const foo = struct {
@@ -434,8 +433,8 @@ test "method call as parameter type" {
434433
return u64;
435434
}
436435
};
437-
try expectEqual(@as(u64, 123), S.foo(S{}, 123));
438-
try expectEqual(@as(u64, 500), S.foo(S{}, 500));
436+
try expect(@as(u64, 123) == S.foo(S{}, 123));
437+
try expect(@as(u64, 500) == S.foo(S{}, 500));
439438
}
440439

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

446445
const S = struct {
447446
fn f(comptime T: type, y: T) !void {
448-
try expectEqual(@as(T, 123), y);
447+
try expect(@as(T, 123) == y);
449448
}
450449

451450
fn g(x: anytype, y: @TypeOf(x)) !void {
452-
try expectEqual(@as(@TypeOf(x), 0x222), y);
451+
try expect(@as(@TypeOf(x), 0x222) == y);
453452
}
454453
};
455454

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

617616
const s2 = U.S(U{ .T = u64 }).tag();
618-
try std.testing.expectEqual(u64, s2);
617+
try std.testing.expect(u64 == s2);
619618
}
620619

621620
test "function call with cast to anyopaque pointer" {

test/behavior/cast.zig

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const builtin = @import("builtin");
21
const std = @import("std");
32
const assert = std.debug.assert;
43
const expect = std.testing.expect;
54
const expectEqual = std.testing.expectEqual;
65
const expectEqualSlices = std.testing.expectEqualSlices;
76
const mem = std.mem;
87
const maxInt = std.math.maxInt;
8+
const builtin = @import("builtin");
9+
910
const native_endian = builtin.target.cpu.arch.endian();
1011

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

17391740
const T = @TypeOf(r1);
17401741

1741-
try expectEqual(@as(T, 100.0), r1);
1742-
try expectEqual(@as(T, 1.234), r2);
1742+
try expect(@as(T, 100.0) == r1);
1743+
try expect(@as(T, 1.234) == r2);
17431744
}
17441745

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

18801881
const T = @TypeOf(r1);
18811882

1882-
try expectEqual(@as(T, 0x1000), r1);
1883-
try expectEqual(@as(T, null), r2);
1883+
try expect(@as(T, 0x1000) == r1);
1884+
try expect(@as(T, null) == r2);
18841885
}
18851886

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

19701971
const T = @TypeOf(r1);
19711972

1972-
try expectEqual(@as(T, 42), r1);
1973-
try expectEqual(@as(T, 50), r2);
1973+
try expect(@as(T, 42) == r1);
1974+
try expect(@as(T, 50) == r2);
19741975
}
19751976

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

2227-
try expectEqual(@as(u32, 1), r1[0]);
2228-
try expectEqual(@as(i16, 2), r1[1]);
2228+
try expect(@as(u32, 1) == r1[0]);
2229+
try expect(@as(i16, 2) == r1[1]);
22292230

2230-
try expectEqual(@as(u32, 3), r2[0]);
2231-
try expectEqual(@as(i16, 4), r2[1]);
2231+
try expect(@as(u32, 3) == r2[0]);
2232+
try expect(@as(i16, 4) == r2[1]);
22322233
}
22332234

22342235
test "peer type resolution: C pointer and many pointer" {
@@ -2626,7 +2627,7 @@ test "numeric coercions with undefined" {
26262627
var to: f32 = from;
26272628
to = @floatFromInt(from);
26282629
to = 42.0;
2629-
try expectEqual(@as(f32, 42.0), to);
2630+
try expect(@as(f32, 42.0) == to);
26302631
}
26312632

26322633
test "15-bit int to float" {
@@ -2711,7 +2712,7 @@ test "bitcast vector" {
27112712

27122713
const zerox32: u8x32 = [_]u8{0} ** 32;
27132714
const bigsum: u32x8 = @bitCast(zerox32);
2714-
try std.testing.expectEqual(0, @reduce(.Add, bigsum));
2715+
try std.testing.expect(0 == @reduce(.Add, bigsum));
27152716
}
27162717

27172718
test "peer type resolution: slice of sentinel-terminated array" {

0 commit comments

Comments
 (0)