Skip to content

Commit 1eec42e

Browse files
committed
Fix size_of_hasher test for 32-bit Windows
Due to ABI differences between different 32-bit targets, the `size_of_hasher` test wrongly failed on `i686-pc-windows-msvc`. Although the test case with that name was introduced in GitoxideLabs#1915, the failure is actually long-standing, in that an analogous faiure occurred in the old `size_of_sha1` test that preceded it and on which it is based. That failure only happened when the old `fast-sha1` feature was enabled, and not with the old `rustsha1` feature. It was not detected earlier as that target is irregularly tested, and built with `--no-default-features --features max-pure` more often than other targets due to difficulties building some other non-Rust dependencies for it. Since GitoxideLabs#1915, the failure happens more often, since we now use only one SHA-1 implementation, `sha1-checked`, so the test always fails on `i686-pc-windows-msvc`. This changes the test to use `gix_testtools::size_ok`, which makes a `==` comparison on 64-bit targets but a `<=` comparison on 32-bit targets where there tends to be more variation in data structures' sizes. This is similar to the fixes in GitoxideLabs#1687 (77c3c59, fc13fc3).
1 parent cfb9bea commit 1eec42e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

gix-hash/tests/hash/hasher.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use gix_hash::{Hasher, ObjectId};
2+
use gix_testtools::size_ok;
23

34
#[test]
45
fn size_of_hasher() {
5-
assert_eq!(
6-
std::mem::size_of::<Hasher>(),
7-
if cfg!(target_arch = "x86") { 820 } else { 824 },
8-
"The size of this type may be relevant when hashing millions of objects,\
9-
and shouldn't change unnoticed. The DetectionState alone clocks in at 724 bytes."
6+
let actual = std::mem::size_of::<Hasher>();
7+
let expected = 824;
8+
assert!(
9+
size_ok(actual, expected),
10+
"The size of this type may be relevant when hashing millions of objects, and shouldn't\
11+
change unnoticed: {actual} <~ {expected}\
12+
(The DetectionState alone clocked in at 724 bytes when last examined.)"
1013
);
1114
}
1215

0 commit comments

Comments
 (0)