From 5c8f7f81cdd10d4cc4c30e46cf37006a2f74f829 Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Fri, 6 Nov 2020 22:36:18 +0100 Subject: [PATCH 1/2] change debug.assert to testing.expect in tests --- lib/std/heap.zig | 2 +- lib/std/heap/logging_allocator.zig | 2 +- lib/std/io/test.zig | 6 +---- lib/std/math/exp.zig | 35 +++++++++++++++--------------- lib/std/rand.zig | 2 +- test/stage1/behavior/bugs/421.zig | 4 ++-- test/standalone/use_alias/main.zig | 4 ++-- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 3e74db386e..50a943c451 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -736,7 +736,7 @@ test "WasmPageAllocator internals" { if (comptime std.Target.current.isWasm()) { const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size; const initial = try page_allocator.alloc(u8, mem.page_size); - 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. + 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. var inplace = try page_allocator.realloc(initial, 1); testing.expectEqual(initial.ptr, inplace.ptr); diff --git a/lib/std/heap/logging_allocator.zig b/lib/std/heap/logging_allocator.zig index 0e3e460b89..f4e0ada764 100644 --- a/lib/std/heap/logging_allocator.zig +++ b/lib/std/heap/logging_allocator.zig @@ -93,7 +93,7 @@ test "LoggingAllocator" { var a = try allocator.alloc(u8, 10); a = allocator.shrink(a, 5); - std.debug.assert(a.len == 5); + std.testing.expect(a.len == 5); std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20)); allocator.free(a); diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index ad519a9199..584369966b 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -40,11 +40,7 @@ test "write a file, read it, then delete it" { { // Make sure the exclusive flag is honored. - if (tmp.dir.createFile(tmp_file_name, .{ .exclusive = true })) |file| { - unreachable; - } else |err| { - std.debug.assert(err == File.OpenError.PathAlreadyExists); - } + expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true })); } { diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig index 35d26f2a50..87e1031a24 100644 --- a/lib/std/math/exp.zig +++ b/lib/std/math/exp.zig @@ -11,8 +11,7 @@ const std = @import("../std.zig"); const math = std.math; -const assert = std.debug.assert; -const builtin = @import("builtin"); +const expect = std.testing.expect; /// Returns e raised to the power of x (e^x). /// @@ -188,36 +187,36 @@ fn exp64(x_: f64) f64 { } test "math.exp" { - assert(exp(@as(f32, 0.0)) == exp32(0.0)); - assert(exp(@as(f64, 0.0)) == exp64(0.0)); + expect(exp(@as(f32, 0.0)) == exp32(0.0)); + expect(exp(@as(f64, 0.0)) == exp64(0.0)); } test "math.exp32" { const epsilon = 0.000001; - assert(exp32(0.0) == 1.0); - assert(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon)); - assert(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon)); - assert(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon)); - assert(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon)); + expect(exp32(0.0) == 1.0); + expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon)); + expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon)); + expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon)); + expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon)); } test "math.exp64" { const epsilon = 0.000001; - assert(exp64(0.0) == 1.0); - assert(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon)); - assert(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon)); - assert(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon)); - assert(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon)); + expect(exp64(0.0) == 1.0); + expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon)); + expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon)); + expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon)); + expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon)); } test "math.exp32.special" { - assert(math.isPositiveInf(exp32(math.inf(f32)))); - assert(math.isNan(exp32(math.nan(f32)))); + expect(math.isPositiveInf(exp32(math.inf(f32)))); + expect(math.isNan(exp32(math.nan(f32)))); } test "math.exp64.special" { - assert(math.isPositiveInf(exp64(math.inf(f64)))); - assert(math.isNan(exp64(math.nan(f64)))); + expect(math.isPositiveInf(exp64(math.inf(f64)))); + expect(math.isNan(exp64(math.nan(f64)))); } diff --git a/lib/std/rand.zig b/lib/std/rand.zig index 2c390ff41a..61aa2dac31 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -1152,7 +1152,7 @@ test "CSPRNG" { const a = csprng.random.int(u64); const b = csprng.random.int(u64); const c = csprng.random.int(u64); - assert(a ^ b ^ c != 0); + expect(a ^ b ^ c != 0); } test "" { diff --git a/test/stage1/behavior/bugs/421.zig b/test/stage1/behavior/bugs/421.zig index a618876e00..748cb3a62d 100644 --- a/test/stage1/behavior/bugs/421.zig +++ b/test/stage1/behavior/bugs/421.zig @@ -1,4 +1,4 @@ -const assert = @import("std").debug.assert; +const expect = @import("std").testing.expect; test "bitCast to array" { comptime testBitCastArray(); @@ -6,7 +6,7 @@ test "bitCast to array" { } fn testBitCastArray() void { - assert(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef); + expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef); } fn extractOne64(a: u128) u64 { diff --git a/test/standalone/use_alias/main.zig b/test/standalone/use_alias/main.zig index 873393cef7..75a8b5e81a 100644 --- a/test/standalone/use_alias/main.zig +++ b/test/standalone/use_alias/main.zig @@ -1,10 +1,10 @@ const c = @import("c.zig"); -const assert = @import("std").debug.assert; +const expect = @import("std").testing.expect; test "symbol exists" { var foo = c.Foo{ .a = 1, .b = 1, }; - assert(foo.a + foo.b == 2); + expect(foo.a + foo.b == 2); } From c9fa57541bdf7c41b1bb914a9ce10a09013392a4 Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Fri, 6 Nov 2020 22:58:58 +0100 Subject: [PATCH 2/2] remove outdated comment --- src/libc_installation.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libc_installation.zig b/src/libc_installation.zig index b016589f4d..7dd99273f1 100644 --- a/src/libc_installation.zig +++ b/src/libc_installation.zig @@ -14,8 +14,6 @@ const log = std.log.scoped(.libc_installation); usingnamespace @import("windows_sdk.zig"); -// TODO https://github.com/ziglang/zig/issues/6345 - /// See the render function implementation for documentation of the fields. pub const LibCInstallation = struct { include_dir: ?[]const u8 = null,