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
This commit is contained in:
Andrew Kelley
2019-02-08 18:18:47 -05:00
parent be6d022257
commit c2db077574
239 changed files with 4084 additions and 3938 deletions

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -14,5 +14,5 @@ const epsilon = 0.0001;
test "complex.cabs" {
const a = Complex(f32).new(5, 3);
const c = abs(a);
debug.assert(math.approxEq(f32, c, 5.83095, epsilon));
testing.expect(math.approxEq(f32, c, 5.83095, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -16,6 +16,6 @@ test "complex.cacos" {
const a = Complex(f32).new(5, 3);
const c = acos(a);
debug.assert(math.approxEq(f32, c.re, 0.546975, epsilon));
debug.assert(math.approxEq(f32, c.im, -2.452914, epsilon));
testing.expect(math.approxEq(f32, c.re, 0.546975, epsilon));
testing.expect(math.approxEq(f32, c.im, -2.452914, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -16,6 +16,6 @@ test "complex.cacosh" {
const a = Complex(f32).new(5, 3);
const c = acosh(a);
debug.assert(math.approxEq(f32, c.re, 2.452914, epsilon));
debug.assert(math.approxEq(f32, c.im, 0.546975, epsilon));
testing.expect(math.approxEq(f32, c.re, 2.452914, epsilon));
testing.expect(math.approxEq(f32, c.im, 0.546975, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -14,5 +14,5 @@ const epsilon = 0.0001;
test "complex.carg" {
const a = Complex(f32).new(5, 3);
const c = arg(a);
debug.assert(math.approxEq(f32, c, 0.540420, epsilon));
testing.expect(math.approxEq(f32, c, 0.540420, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -22,6 +22,6 @@ test "complex.casin" {
const a = Complex(f32).new(5, 3);
const c = asin(a);
debug.assert(math.approxEq(f32, c.re, 1.023822, epsilon));
debug.assert(math.approxEq(f32, c.im, 2.452914, epsilon));
testing.expect(math.approxEq(f32, c.re, 1.023822, epsilon));
testing.expect(math.approxEq(f32, c.im, 2.452914, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -17,6 +17,6 @@ test "complex.casinh" {
const a = Complex(f32).new(5, 3);
const c = asinh(a);
debug.assert(math.approxEq(f32, c.re, 2.459831, epsilon));
debug.assert(math.approxEq(f32, c.im, 0.533999, epsilon));
testing.expect(math.approxEq(f32, c.re, 2.459831, epsilon));
testing.expect(math.approxEq(f32, c.im, 0.533999, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -117,14 +117,14 @@ test "complex.catan32" {
const a = Complex(f32).new(5, 3);
const c = atan(a);
debug.assert(math.approxEq(f32, c.re, 1.423679, epsilon));
debug.assert(math.approxEq(f32, c.im, 0.086569, epsilon));
testing.expect(math.approxEq(f32, c.re, 1.423679, epsilon));
testing.expect(math.approxEq(f32, c.im, 0.086569, epsilon));
}
test "complex.catan64" {
const a = Complex(f64).new(5, 3);
const c = atan(a);
debug.assert(math.approxEq(f64, c.re, 1.423679, epsilon));
debug.assert(math.approxEq(f64, c.im, 0.086569, epsilon));
testing.expect(math.approxEq(f64, c.re, 1.423679, epsilon));
testing.expect(math.approxEq(f64, c.im, 0.086569, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -17,6 +17,6 @@ test "complex.catanh" {
const a = Complex(f32).new(5, 3);
const c = atanh(a);
debug.assert(math.approxEq(f32, c.re, 0.146947, epsilon));
debug.assert(math.approxEq(f32, c.im, 1.480870, epsilon));
testing.expect(math.approxEq(f32, c.re, 0.146947, epsilon));
testing.expect(math.approxEq(f32, c.im, 1.480870, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -13,5 +13,5 @@ test "complex.conj" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
debug.assert(c.re == 5 and c.im == -3);
testing.expect(c.re == 5 and c.im == -3);
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -16,6 +16,6 @@ test "complex.ccos" {
const a = Complex(f32).new(5, 3);
const c = cos(a);
debug.assert(math.approxEq(f32, c.re, 2.855815, epsilon));
debug.assert(math.approxEq(f32, c.im, 9.606383, epsilon));
testing.expect(math.approxEq(f32, c.re, 2.855815, epsilon));
testing.expect(math.approxEq(f32, c.im, 9.606383, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -152,14 +152,14 @@ test "complex.ccosh32" {
const a = Complex(f32).new(5, 3);
const c = cosh(a);
debug.assert(math.approxEq(f32, c.re, -73.467300, epsilon));
debug.assert(math.approxEq(f32, c.im, 10.471557, epsilon));
testing.expect(math.approxEq(f32, c.re, -73.467300, epsilon));
testing.expect(math.approxEq(f32, c.im, 10.471557, epsilon));
}
test "complex.ccosh64" {
const a = Complex(f64).new(5, 3);
const c = cosh(a);
debug.assert(math.approxEq(f64, c.re, -73.467300, epsilon));
debug.assert(math.approxEq(f64, c.im, 10.471557, epsilon));
testing.expect(math.approxEq(f64, c.re, -73.467300, epsilon));
testing.expect(math.approxEq(f64, c.im, 10.471557, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -118,14 +118,14 @@ test "complex.cexp32" {
const a = Complex(f32).new(5, 3);
const c = exp(a);
debug.assert(math.approxEq(f32, c.re, -146.927917, epsilon));
debug.assert(math.approxEq(f32, c.im, 20.944065, epsilon));
testing.expect(math.approxEq(f32, c.re, -146.927917, epsilon));
testing.expect(math.approxEq(f32, c.im, 20.944065, epsilon));
}
test "complex.cexp64" {
const a = Complex(f64).new(5, 3);
const c = exp(a);
debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon));
debug.assert(math.approxEq(f64, c.im, 20.944065, epsilon));
testing.expect(math.approxEq(f64, c.re, -146.927917, epsilon));
testing.expect(math.approxEq(f64, c.im, 20.944065, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
pub const abs = @import("abs.zig").abs;
@@ -97,7 +97,7 @@ test "complex.add" {
const b = Complex(f32).new(2, 7);
const c = a.add(b);
debug.assert(c.re == 7 and c.im == 10);
testing.expect(c.re == 7 and c.im == 10);
}
test "complex.sub" {
@@ -105,7 +105,7 @@ test "complex.sub" {
const b = Complex(f32).new(2, 7);
const c = a.sub(b);
debug.assert(c.re == 3 and c.im == -4);
testing.expect(c.re == 3 and c.im == -4);
}
test "complex.mul" {
@@ -113,7 +113,7 @@ test "complex.mul" {
const b = Complex(f32).new(2, 7);
const c = a.mul(b);
debug.assert(c.re == -11 and c.im == 41);
testing.expect(c.re == -11 and c.im == 41);
}
test "complex.div" {
@@ -121,7 +121,7 @@ test "complex.div" {
const b = Complex(f32).new(2, 7);
const c = a.div(b);
debug.assert(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
}
@@ -129,14 +129,14 @@ test "complex.conjugate" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
debug.assert(c.re == 5 and c.im == -3);
testing.expect(c.re == 5 and c.im == -3);
}
test "complex.reciprocal" {
const a = Complex(f32).new(5, 3);
const c = a.reciprocal();
debug.assert(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
}
@@ -144,7 +144,7 @@ test "complex.magnitude" {
const a = Complex(f32).new(5, 3);
const c = a.magnitude();
debug.assert(math.approxEq(f32, c, 5.83095, epsilon));
testing.expect(math.approxEq(f32, c, 5.83095, epsilon));
}
test "complex.cmath" {

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -18,6 +18,6 @@ test "complex.clog" {
const a = Complex(f32).new(5, 3);
const c = log(a);
debug.assert(math.approxEq(f32, c.re, 1.763180, epsilon));
debug.assert(math.approxEq(f32, c.im, 0.540419, epsilon));
testing.expect(math.approxEq(f32, c.re, 1.763180, epsilon));
testing.expect(math.approxEq(f32, c.im, 0.540419, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -17,6 +17,6 @@ test "complex.cpow" {
const b = Complex(f32).new(2.3, -1.3);
const c = pow(Complex(f32), a, b);
debug.assert(math.approxEq(f32, c.re, 58.049110, epsilon));
debug.assert(math.approxEq(f32, c.im, -101.003433, epsilon));
testing.expect(math.approxEq(f32, c.re, 58.049110, epsilon));
testing.expect(math.approxEq(f32, c.im, -101.003433, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -20,5 +20,5 @@ test "complex.cproj" {
const a = Complex(f32).new(5, 3);
const c = proj(a);
debug.assert(c.re == 5 and c.im == 3);
testing.expect(c.re == 5 and c.im == 3);
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -17,6 +17,6 @@ test "complex.csin" {
const a = Complex(f32).new(5, 3);
const c = sin(a);
debug.assert(math.approxEq(f32, c.re, -9.654126, epsilon));
debug.assert(math.approxEq(f32, c.im, 2.841692, epsilon));
testing.expect(math.approxEq(f32, c.re, -9.654126, epsilon));
testing.expect(math.approxEq(f32, c.im, 2.841692, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -151,14 +151,14 @@ test "complex.csinh32" {
const a = Complex(f32).new(5, 3);
const c = sinh(a);
debug.assert(math.approxEq(f32, c.re, -73.460617, epsilon));
debug.assert(math.approxEq(f32, c.im, 10.472508, epsilon));
testing.expect(math.approxEq(f32, c.re, -73.460617, epsilon));
testing.expect(math.approxEq(f32, c.im, 10.472508, epsilon));
}
test "complex.csinh64" {
const a = Complex(f64).new(5, 3);
const c = sinh(a);
debug.assert(math.approxEq(f64, c.re, -73.460617, epsilon));
debug.assert(math.approxEq(f64, c.im, 10.472508, epsilon));
testing.expect(math.approxEq(f64, c.re, -73.460617, epsilon));
testing.expect(math.approxEq(f64, c.im, 10.472508, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -125,14 +125,14 @@ test "complex.csqrt32" {
const a = Complex(f32).new(5, 3);
const c = sqrt(a);
debug.assert(math.approxEq(f32, c.re, 2.327117, epsilon));
debug.assert(math.approxEq(f32, c.im, 0.644574, epsilon));
testing.expect(math.approxEq(f32, c.re, 2.327117, epsilon));
testing.expect(math.approxEq(f32, c.im, 0.644574, epsilon));
}
test "complex.csqrt64" {
const a = Complex(f64).new(5, 3);
const c = sqrt(a);
debug.assert(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));
debug.assert(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));
testing.expect(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));
testing.expect(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -17,6 +17,6 @@ test "complex.ctan" {
const a = Complex(f32).new(5, 3);
const c = tan(a);
debug.assert(math.approxEq(f32, c.re, -0.002708233, epsilon));
debug.assert(math.approxEq(f32, c.im, 1.004165, epsilon));
testing.expect(math.approxEq(f32, c.re, -0.002708233, epsilon));
testing.expect(math.approxEq(f32, c.im, 1.004165, epsilon));
}

View File

@@ -1,5 +1,5 @@
const std = @import("../../index.zig");
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const cmath = math.complex;
const Complex = cmath.Complex;
@@ -100,14 +100,14 @@ test "complex.ctanh32" {
const a = Complex(f32).new(5, 3);
const c = tanh(a);
debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon));
debug.assert(math.approxEq(f32, c.im, -0.000025, epsilon));
testing.expect(math.approxEq(f32, c.re, 0.999913, epsilon));
testing.expect(math.approxEq(f32, c.im, -0.000025, epsilon));
}
test "complex.ctanh64" {
const a = Complex(f64).new(5, 3);
const c = tanh(a);
debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon));
debug.assert(math.approxEq(f64, c.im, -0.000025, epsilon));
testing.expect(math.approxEq(f64, c.re, 0.999913, epsilon));
testing.expect(math.approxEq(f64, c.im, -0.000025, epsilon));
}