Skip to content

Commit e4fb29c

Browse files
committed
24361: reduce usage of expectEqual in behavior tests
1 parent afdd043 commit e4fb29c

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

+690
-696
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

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

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

562562
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

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

165164
test "asm modifiers (AArch64)" {
@@ -173,5 +172,5 @@ test "asm modifiers (AArch64)" {
173172
: [ret] "=r" (-> u32),
174173
: [in] "r" (x),
175174
);
176-
try expectEqual(2 * x, double);
175+
try expect(2 * x == double);
177176
}

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 {
@@ -172,7 +171,7 @@ test "Saturating Shift Left" {
172171
inline while (true) : (rhs += 1) {
173172
comptime var lhs: T = std.math.minInt(T);
174173
inline while (true) : (lhs += 1) {
175-
try expectEqual(lhs <<| rhs, shlSat(lhs, rhs));
174+
try expect(lhs <<| rhs == shlSat(lhs, rhs));
176175
if (lhs == std.math.maxInt(T)) break;
177176
}
178177
if (rhs == @bitSizeOf(T) - 1) break;
@@ -187,12 +186,12 @@ test "Saturating Shift Left" {
187186
try S.testType(u4);
188187
try S.testType(i4);
189188

190-
try expectEqual(0xfffffffffffffff0fffffffffffffff0, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
191-
try expectEqual(0xffffffffffffffffffffffffffffffff, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
192-
try expectEqual(-0x80000000000000000000000000000000, S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
189+
try expect(0xfffffffffffffff0fffffffffffffff0 == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
190+
try expect(0xffffffffffffffffffffffffffffffff == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
191+
try expect(-0x80000000000000000000000000000000 == S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
193192

194-
try expectEqual(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583, S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
195-
try expectEqual(-57896044618658097711785492504343953926634992332820282019728792003956564819968, S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
196-
try expectEqual(170141183460469231731687303715884105727, S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
197-
try expectEqual(0, S.shlSat(@as(i128, 0), 127));
193+
try expect(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583 == S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
194+
try expect(-57896044618658097711785492504343953926634992332820282019728792003956564819968 == S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
195+
try expect(170141183460469231731687303715884105727 == S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
196+
try expect(0 == S.shlSat(@as(i128, 0), 127));
198197
}

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" {
@@ -1867,8 +1868,8 @@ test "peer type resolution: float and comptime-known fixed-width integer" {
18671868

18681869
const T = @TypeOf(r1);
18691870

1870-
try expectEqual(@as(T, 100.0), r1);
1871-
try expectEqual(@as(T, 1.234), r2);
1871+
try expect(@as(T, 100.0) == r1);
1872+
try expect(@as(T, 1.234) == r2);
18721873
}
18731874

18741875
test "peer type resolution: same array type with sentinel" {
@@ -2007,8 +2008,8 @@ test "peer type resolution: C pointer and @TypeOf(null)" {
20072008

20082009
const T = @TypeOf(r1);
20092010

2010-
try expectEqual(@as(T, 0x1000), r1);
2011-
try expectEqual(@as(T, null), r2);
2011+
try expect(@as(T, 0x1000) == r1);
2012+
try expect(@as(T, null) == r2);
20122013
}
20132014

20142015
test "peer type resolution: three-way resolution combines error set and optional" {
@@ -2095,8 +2096,8 @@ test "peer type resolution: optional fixed-width int and comptime_int" {
20952096

20962097
const T = @TypeOf(r1);
20972098

2098-
try expectEqual(@as(T, 42), r1);
2099-
try expectEqual(@as(T, 50), r2);
2099+
try expect(@as(T, 42) == r1);
2100+
try expect(@as(T, 50) == r2);
21002101
}
21012102

21022103
test "peer type resolution: array and tuple" {
@@ -2345,11 +2346,11 @@ test "peer type resolution: tuples with comptime fields" {
23452346
const r1 = if (t) a else b;
23462347
const r2 = if (t) b else a;
23472348

2348-
try expectEqual(@as(u32, 1), r1[0]);
2349-
try expectEqual(@as(i16, 2), r1[1]);
2349+
try expect(@as(u32, 1) == r1[0]);
2350+
try expect(@as(i16, 2) == r1[1]);
23502351

2351-
try expectEqual(@as(u32, 3), r2[0]);
2352-
try expectEqual(@as(i16, 4), r2[1]);
2352+
try expect(@as(u32, 3) == r2[0]);
2353+
try expect(@as(i16, 4) == r2[1]);
23532354
}
23542355

23552356
test "peer type resolution: C pointer and many pointer" {
@@ -2742,7 +2743,7 @@ test "numeric coercions with undefined" {
27422743
var to: f32 = from;
27432744
to = @floatFromInt(from);
27442745
to = 42.0;
2745-
try expectEqual(@as(f32, 42.0), to);
2746+
try expect(@as(f32, 42.0) == to);
27462747
}
27472748

27482749
test "15-bit int to float" {
@@ -2824,7 +2825,7 @@ test "bitcast vector" {
28242825

28252826
const zerox32: u8x32 = [_]u8{0} ** 32;
28262827
const bigsum: u32x8 = @bitCast(zerox32);
2827-
try std.testing.expectEqual(0, @reduce(.Add, bigsum));
2828+
try std.testing.expect(0 == @reduce(.Add, bigsum));
28282829
}
28292830

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

0 commit comments

Comments
 (0)