aboutsummaryrefslogtreecommitdiff
path: root/std/hash/siphash.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-08 18:18:47 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-08 18:23:38 -0500
commitc2db077574be841da586fa62d67619c901dd535d (patch)
treec8eb64846fa7ffb9027fa1ca035dd8ca5712b9d4 /std/hash/siphash.zig
parentbe6d022257d8d7e99bd080823d4d8f0175f320c5 (diff)
downloadzig-c2db077574be841da586fa62d67619c901dd535d.tar.gz
zig-c2db077574be841da586fa62d67619c901dd535d.zip
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
Diffstat (limited to 'std/hash/siphash.zig')
-rw-r--r--std/hash/siphash.zig15
1 files changed, 8 insertions, 7 deletions
diff --git a/std/hash/siphash.zig b/std/hash/siphash.zig
index ee26950272..c9a6128d35 100644
--- a/std/hash/siphash.zig
+++ b/std/hash/siphash.zig
@@ -6,7 +6,8 @@
// https://131002.net/siphash/
const std = @import("../index.zig");
-const debug = std.debug;
+const assert = std.debug.assert;
+const testing = std.testing;
const math = std.math;
const mem = std.mem;
@@ -21,8 +22,8 @@ pub fn SipHash128(comptime c_rounds: usize, comptime d_rounds: usize) type {
}
fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) type {
- debug.assert(T == u64 or T == u128);
- debug.assert(c_rounds > 0 and d_rounds > 0);
+ assert(T == u64 or T == u128);
+ assert(c_rounds > 0 and d_rounds > 0);
return struct {
const Self = @This();
@@ -40,7 +41,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
msg_len: u8,
pub fn init(key: []const u8) Self {
- debug.assert(key.len >= 16);
+ assert(key.len >= 16);
const k0 = mem.readIntSliceLittle(u64, key[0..8]);
const k1 = mem.readIntSliceLittle(u64, key[8..16]);
@@ -119,7 +120,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
}
fn round(d: *Self, b: []const u8) void {
- debug.assert(b.len == 8);
+ assert(b.len == 8);
const m = mem.readIntSliceLittle(u64, b[0..]);
d.v3 ^= m;
@@ -236,7 +237,7 @@ test "siphash64-2-4 sanity" {
buffer[i] = @intCast(u8, i);
const expected = mem.readIntLittle(u64, &vector);
- debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
+ testing.expect(siphash.hash(test_key, buffer[0..i]) == expected);
}
}
@@ -315,6 +316,6 @@ test "siphash128-2-4 sanity" {
buffer[i] = @intCast(u8, i);
const expected = mem.readIntLittle(u128, &vector);
- debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
+ testing.expect(siphash.hash(test_key, buffer[0..i]) == expected);
}
}