Skip to content

Commit 5430642

Browse files
authored
Merge pull request #7008 from xackus/minor-fixes
change debug.assert to testing.expect in tests
2 parents 67ea47b + c9fa575 commit 5430642

File tree

8 files changed

+25
-32
lines changed

8 files changed

+25
-32
lines changed

lib/std/heap.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ test "WasmPageAllocator internals" {
736736
if (comptime std.Target.current.isWasm()) {
737737
const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
738738
const initial = try page_allocator.alloc(u8, mem.page_size);
739-
std.debug.assert(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
739+
testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
740740

741741
var inplace = try page_allocator.realloc(initial, 1);
742742
testing.expectEqual(initial.ptr, inplace.ptr);

lib/std/heap/logging_allocator.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test "LoggingAllocator" {
9393

9494
var a = try allocator.alloc(u8, 10);
9595
a = allocator.shrink(a, 5);
96-
std.debug.assert(a.len == 5);
96+
std.testing.expect(a.len == 5);
9797
std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
9898
allocator.free(a);
9999

lib/std/io/test.zig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ test "write a file, read it, then delete it" {
4040

4141
{
4242
// Make sure the exclusive flag is honored.
43-
if (tmp.dir.createFile(tmp_file_name, .{ .exclusive = true })) |file| {
44-
unreachable;
45-
} else |err| {
46-
std.debug.assert(err == File.OpenError.PathAlreadyExists);
47-
}
43+
expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
4844
}
4945

5046
{

lib/std/math/exp.zig

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
const std = @import("../std.zig");
1313
const math = std.math;
14-
const assert = std.debug.assert;
15-
const builtin = @import("builtin");
14+
const expect = std.testing.expect;
1615

1716
/// Returns e raised to the power of x (e^x).
1817
///
@@ -188,36 +187,36 @@ fn exp64(x_: f64) f64 {
188187
}
189188

190189
test "math.exp" {
191-
assert(exp(@as(f32, 0.0)) == exp32(0.0));
192-
assert(exp(@as(f64, 0.0)) == exp64(0.0));
190+
expect(exp(@as(f32, 0.0)) == exp32(0.0));
191+
expect(exp(@as(f64, 0.0)) == exp64(0.0));
193192
}
194193

195194
test "math.exp32" {
196195
const epsilon = 0.000001;
197196

198-
assert(exp32(0.0) == 1.0);
199-
assert(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
200-
assert(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
201-
assert(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
202-
assert(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
197+
expect(exp32(0.0) == 1.0);
198+
expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199+
expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200+
expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201+
expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
203202
}
204203

205204
test "math.exp64" {
206205
const epsilon = 0.000001;
207206

208-
assert(exp64(0.0) == 1.0);
209-
assert(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
210-
assert(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
211-
assert(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
212-
assert(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
207+
expect(exp64(0.0) == 1.0);
208+
expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209+
expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210+
expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211+
expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
213212
}
214213

215214
test "math.exp32.special" {
216-
assert(math.isPositiveInf(exp32(math.inf(f32))));
217-
assert(math.isNan(exp32(math.nan(f32))));
215+
expect(math.isPositiveInf(exp32(math.inf(f32))));
216+
expect(math.isNan(exp32(math.nan(f32))));
218217
}
219218

220219
test "math.exp64.special" {
221-
assert(math.isPositiveInf(exp64(math.inf(f64))));
222-
assert(math.isNan(exp64(math.nan(f64))));
220+
expect(math.isPositiveInf(exp64(math.inf(f64))));
221+
expect(math.isNan(exp64(math.nan(f64))));
223222
}

lib/std/rand.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ test "CSPRNG" {
11521152
const a = csprng.random.int(u64);
11531153
const b = csprng.random.int(u64);
11541154
const c = csprng.random.int(u64);
1155-
assert(a ^ b ^ c != 0);
1155+
expect(a ^ b ^ c != 0);
11561156
}
11571157

11581158
test "" {

src/libc_installation.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const log = std.log.scoped(.libc_installation);
1414

1515
usingnamespace @import("windows_sdk.zig");
1616

17-
// TODO https://github.com/ziglang/zig/issues/6345
18-
1917
/// See the render function implementation for documentation of the fields.
2018
pub const LibCInstallation = struct {
2119
include_dir: ?[]const u8 = null,

test/stage1/behavior/bugs/421.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const assert = @import("std").debug.assert;
1+
const expect = @import("std").testing.expect;
22

33
test "bitCast to array" {
44
comptime testBitCastArray();
55
testBitCastArray();
66
}
77

88
fn testBitCastArray() void {
9-
assert(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
9+
expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
1010
}
1111

1212
fn extractOne64(a: u128) u64 {

test/standalone/use_alias/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const c = @import("c.zig");
2-
const assert = @import("std").debug.assert;
2+
const expect = @import("std").testing.expect;
33

44
test "symbol exists" {
55
var foo = c.Foo{
66
.a = 1,
77
.b = 1,
88
};
9-
assert(foo.a + foo.b == 2);
9+
expect(foo.a + foo.b == 2);
1010
}

0 commit comments

Comments
 (0)