BurntSushi / aho-corasick

A fast implementation of Aho-Corasick in Rust.
The Unlicense
1.03k stars 93 forks source link

AhoCorasick::memory_usage doctests fail on i686 (and possibly most 32-bit architectures) #116

Closed decathorpe closed 1 year ago

decathorpe commented 1 year ago

I'm maintaining the Fedora Linux package for this crate, and upon the update from v0.7 to v1.0, I see new test failure on 32-bit x86 (i.e. i686-unknown-linux-gnu) related to AhoCorasick::memory_usage:

---- src/ahocorasick.rs - ahocorasick::AhoCorasick::memory_usage (line 1977) stdout ----
Test executable failed (exit status: 101).
stderr:
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `5632`,
 right: `5584`', src/ahocorasick.rs:10:1

The failure itself looks harmless (i.e. the memory usage is lower than the expected one, which isn't unexpected on 32-bit systems (as types like usize / isize etc. are half the size on i686 than they are on x86_64), but I wanted to report this nonetheless.

For now I'm going to ignore these tests on 32-bit systems, but maybe it might make sense to make the comparison <= expected instead of ==expected, or to gate the assertions in the AhoCorasick::memory_usage doctest with #[cfg(target_pointer_width = "64")]?

BurntSushi commented 1 year ago

So the thing that is perplexing to me is that CI specifically includes a 32-bit target, and yet these tests don't fail.

Playing around locally, it looks like perhaps the doc tests aren't running under cross. Sigh.

BurntSushi commented 1 year ago

It looks like it might be a Cargo issue?

https://github.com/rust-lang/cargo/issues/6460

https://github.com/rust-lang/cargo/issues/4471

https://github.com/rust-lang/rust/issues/44404

https://github.com/rust-lang/rust/issues/64245

https://github.com/rust-lang/cargo/issues/7040

decathorpe commented 1 year ago

Oh, yeah, I did not expect that doctests don't get run in these circumstances ... thanks for investigating + fixing! 👍🏼