Skip to content

Commit 6f5299a

Browse files
committed
24361: reduce usage of expectEqual in behavior tests
1 parent 7ee6dab commit 6f5299a

Some content is hidden

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

42 files changed

+710
-721
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

@@ -557,7 +557,7 @@ test "function pointer @intFromPtr/@ptrFromInt roundtrip" {
557557
const nothing_int: usize = @intFromPtr(nothing_ptr);
558558
const nothing_ptr2: *const fn () callconv(.c) void = @ptrFromInt(nothing_int);
559559

560-
try std.testing.expectEqual(nothing_ptr, nothing_ptr2);
560+
try std.testing.expect(nothing_ptr == nothing_ptr2);
561561
}
562562

563563
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;
@@ -1020,10 +1020,10 @@ test "@splat array with sentinel" {
10201020
fn doTheTest(comptime T: type, x: T, comptime s: T) !void {
10211021
const arr: [10:s]T = @splat(x);
10221022
for (arr) |elem| {
1023-
try expectEqual(x, elem);
1023+
try expect(x == elem);
10241024
}
10251025
const ptr: [*]const T = &arr;
1026-
try expectEqual(s, ptr[10]); // sentinel correct
1026+
try expect(s == ptr[10]); // sentinel correct
10271027
}
10281028
};
10291029

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

@@ -158,7 +157,7 @@ test "rw constraint (x86_64)" {
158157
: [a] "+r" (res),
159158
: [b] "r" (@as(i32, 13)),
160159
: .{ .flags = true });
161-
try expectEqual(@as(i32, 18), res);
160+
try expect(@as(i32, 18) == res);
162161
}
163162

164163
test "asm modifiers (AArch64)" {
@@ -172,5 +171,5 @@ test "asm modifiers (AArch64)" {
172171
: [ret] "=r" (-> u32),
173172
: [in] "r" (x),
174173
);
175-
try expectEqual(2 * x, double);
174+
try expect(2 * x == double);
176175
}

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 {
@@ -178,7 +177,7 @@ test "Saturating Shift Left" {
178177
inline while (true) : (rhs += 1) {
179178
comptime var lhs: T = std.math.minInt(T);
180179
inline while (true) : (lhs += 1) {
181-
try expectEqual(lhs <<| rhs, shlSat(lhs, rhs));
180+
try expect(lhs <<| rhs == shlSat(lhs, rhs));
182181
if (lhs == std.math.maxInt(T)) break;
183182
}
184183
if (rhs == @bitSizeOf(T) - 1) break;
@@ -193,12 +192,12 @@ test "Saturating Shift Left" {
193192
try S.testType(u4);
194193
try S.testType(i4);
195194

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

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

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

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

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

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 {
@@ -431,8 +430,8 @@ test "method call as parameter type" {
431430
return u64;
432431
}
433432
};
434-
try expectEqual(@as(u64, 123), S.foo(S{}, 123));
435-
try expectEqual(@as(u64, 500), S.foo(S{}, 500));
433+
try expect(@as(u64, 123) == S.foo(S{}, 123));
434+
try expect(@as(u64, 500) == S.foo(S{}, 500));
436435
}
437436

438437
test "non-anytype generic parameters provide result type" {
@@ -441,11 +440,11 @@ test "non-anytype generic parameters provide result type" {
441440

442441
const S = struct {
443442
fn f(comptime T: type, y: T) !void {
444-
try expectEqual(@as(T, 123), y);
443+
try expect(@as(T, 123) == y);
445444
}
446445

447446
fn g(x: anytype, y: @TypeOf(x)) !void {
448-
try expectEqual(@as(@TypeOf(x), 0x222), y);
447+
try expect(@as(@TypeOf(x), 0x222) == y);
449448
}
450449
};
451450

@@ -605,10 +604,10 @@ test "call with union with zero sized field is not memorized incorrectly" {
605604
}
606605
};
607606
const s1 = U.S(U{ .T = u32 }).tag();
608-
try std.testing.expectEqual(u32, s1);
607+
try std.testing.expect(u32 == s1);
609608

610609
const s2 = U.S(U{ .T = u64 }).tag();
611-
try std.testing.expectEqual(u64, s2);
610+
try std.testing.expect(u64 == s2);
612611
}
613612

614613
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" {
@@ -1672,8 +1673,8 @@ test "peer type resolution: float and comptime-known fixed-width integer" {
16721673

16731674
const T = @TypeOf(r1);
16741675

1675-
try expectEqual(@as(T, 100.0), r1);
1676-
try expectEqual(@as(T, 1.234), r2);
1676+
try expect(@as(T, 100.0) == r1);
1677+
try expect(@as(T, 1.234) == r2);
16771678
}
16781679

16791680
test "peer type resolution: same array type with sentinel" {
@@ -1811,8 +1812,8 @@ test "peer type resolution: C pointer and @TypeOf(null)" {
18111812

18121813
const T = @TypeOf(r1);
18131814

1814-
try expectEqual(@as(T, 0x1000), r1);
1815-
try expectEqual(@as(T, null), r2);
1815+
try expect(@as(T, 0x1000) == r1);
1816+
try expect(@as(T, null) == r2);
18161817
}
18171818

18181819
test "peer type resolution: three-way resolution combines error set and optional" {
@@ -1899,8 +1900,8 @@ test "peer type resolution: optional fixed-width int and comptime_int" {
18991900

19001901
const T = @TypeOf(r1);
19011902

1902-
try expectEqual(@as(T, 42), r1);
1903-
try expectEqual(@as(T, 50), r2);
1903+
try expect(@as(T, 42) == r1);
1904+
try expect(@as(T, 50) == r2);
19041905
}
19051906

19061907
test "peer type resolution: array and tuple" {
@@ -2149,11 +2150,11 @@ test "peer type resolution: tuples with comptime fields" {
21492150
const r1 = if (t) a else b;
21502151
const r2 = if (t) b else a;
21512152

2152-
try expectEqual(@as(u32, 1), r1[0]);
2153-
try expectEqual(@as(i16, 2), r1[1]);
2153+
try expect(@as(u32, 1) == r1[0]);
2154+
try expect(@as(i16, 2) == r1[1]);
21542155

2155-
try expectEqual(@as(u32, 3), r2[0]);
2156-
try expectEqual(@as(i16, 4), r2[1]);
2156+
try expect(@as(u32, 3) == r2[0]);
2157+
try expect(@as(i16, 4) == r2[1]);
21572158
}
21582159

21592160
test "peer type resolution: C pointer and many pointer" {
@@ -2546,7 +2547,7 @@ test "numeric coercions with undefined" {
25462547
var to: f32 = from;
25472548
to = @floatFromInt(from);
25482549
to = 42.0;
2549-
try expectEqual(@as(f32, 42.0), to);
2550+
try expect(@as(f32, 42.0) == to);
25502551
}
25512552

25522553
test "15-bit int to float" {
@@ -2628,7 +2629,7 @@ test "bitcast vector" {
26282629

26292630
const zerox32: u8x32 = [_]u8{0} ** 32;
26302631
const bigsum: u32x8 = @bitCast(zerox32);
2631-
try std.testing.expectEqual(0, @reduce(.Add, bigsum));
2632+
try std.testing.expect(0 == @reduce(.Add, bigsum));
26322633
}
26332634

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

0 commit comments

Comments
 (0)