From c2db077574be841da586fa62d67619c901dd535d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 8 Feb 2019 18:18:47 -0500 Subject: std.debug.assert: remove special case for test builds Previously, std.debug.assert would `@panic` in test builds, if the assertion failed. Now, it's always `unreachable`. This makes release mode test builds more accurately test the actual code that will be run. However this requires tests to call `std.testing.expect` rather than `std.debug.assert` to make sure output is correct. Here is the explanation of when to use either one, copied from the assert doc comments: Inside a test block, it is best to use the `std.testing` module rather than assert, because assert may not detect a test failure in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert is the correct function to use. closes #1304 --- std/math/log2.zig | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'std/math/log2.zig') diff --git a/std/math/log2.zig b/std/math/log2.zig index 555c0bdf18..1bb51bf9f9 100644 --- a/std/math/log2.zig +++ b/std/math/log2.zig @@ -7,7 +7,7 @@ const std = @import("../index.zig"); const math = std.math; -const assert = std.debug.assert; +const expect = std.testing.expect; const builtin = @import("builtin"); const TypeId = builtin.TypeId; const maxInt = std.math.maxInt; @@ -169,40 +169,40 @@ pub fn log2_64(x_: f64) f64 { } test "math.log2" { - assert(log2(f32(0.2)) == log2_32(0.2)); - assert(log2(f64(0.2)) == log2_64(0.2)); + expect(log2(f32(0.2)) == log2_32(0.2)); + expect(log2(f64(0.2)) == log2_64(0.2)); } test "math.log2_32" { const epsilon = 0.000001; - assert(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon)); - assert(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon)); - assert(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon)); - assert(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon)); - assert(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon)); + expect(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon)); + expect(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon)); + expect(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon)); + expect(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon)); + expect(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon)); } test "math.log2_64" { const epsilon = 0.000001; - assert(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon)); - assert(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon)); - assert(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon)); - assert(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon)); - assert(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon)); + expect(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon)); + expect(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon)); + expect(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon)); + expect(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon)); + expect(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon)); } test "math.log2_32.special" { - assert(math.isPositiveInf(log2_32(math.inf(f32)))); - assert(math.isNegativeInf(log2_32(0.0))); - assert(math.isNan(log2_32(-1.0))); - assert(math.isNan(log2_32(math.nan(f32)))); + expect(math.isPositiveInf(log2_32(math.inf(f32)))); + expect(math.isNegativeInf(log2_32(0.0))); + expect(math.isNan(log2_32(-1.0))); + expect(math.isNan(log2_32(math.nan(f32)))); } test "math.log2_64.special" { - assert(math.isPositiveInf(log2_64(math.inf(f64)))); - assert(math.isNegativeInf(log2_64(0.0))); - assert(math.isNan(log2_64(-1.0))); - assert(math.isNan(log2_64(math.nan(f64)))); + expect(math.isPositiveInf(log2_64(math.inf(f64)))); + expect(math.isNegativeInf(log2_64(0.0))); + expect(math.isNan(log2_64(-1.0))); + expect(math.isNan(log2_64(math.nan(f64)))); } -- cgit v1.2.3