Skip to content

Commit 5a7c557

Browse files
committed
compress: remove sha256 checks from tests
Read bytes to check expected values instead of reading and hashing them. Hashing is a waste of time when we can just read and compare. This also removes a dependency on std.crypto.hash.sha2.Sha256 for tests.
1 parent cd594d1 commit 5a7c557

File tree

3 files changed

+697
-45
lines changed

3 files changed

+697
-45
lines changed

lib/std/compress/gzip.zig

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,9 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
165165
// Read and decompress the whole file
166166
const buf = try gzip_stream.reader().readAllAlloc(testing.allocator, std.math.maxInt(usize));
167167
defer testing.allocator.free(buf);
168-
// Calculate its SHA256 hash and check it against the reference
169-
var hash: [32]u8 = undefined;
170-
std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
171168

172-
try assertEqual(expected, &hash);
173-
}
174-
175-
// Assert `expected` == `input` where `input` is a bytestring.
176-
pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
177-
var expected_bytes: [expected.len / 2]u8 = undefined;
178-
for (expected_bytes) |*r, i| {
179-
r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
180-
}
181-
182-
try testing.expectEqualSlices(u8, &expected_bytes, input);
169+
// Check against the reference
170+
try testing.expectEqualSlices(u8, buf, expected);
183171
}
184172

185173
// All the test cases are obtained by compressing the RFC1952 text
@@ -189,7 +177,7 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
189177
test "compressed data" {
190178
try testReader(
191179
@embedFile("rfc1952.txt.gz"),
192-
"164ef0897b4cbec63abf1b57f069f3599bd0fb7c72c2a4dee21bd7e03ec9af67",
180+
@embedFile("rfc1952.txt"),
193181
);
194182
}
195183

0 commit comments

Comments
 (0)