fix tests on BE arches

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
epel9
Igor Gnatenko 7 years ago
parent a22b43c653
commit ce8b624a5a

@ -0,0 +1,52 @@
From 403638e8d7ca2b0cd24034976c7a164bbd15b4dd Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
Date: Mon, 13 Nov 2017 11:26:47 -0800
Subject: [PATCH] Fix prop_ext_[u]int_*::native_endian on BE targets
The similar `big_endian` tests were using an offset to read from the
end of the written `u64`, but the `native_endian` tests were reading
directly, just like the `little_endian` tests. That's of course only
correct when the target actually is little endian.
That `big_endian` offset is now sliced directly, instead of cloning into
another vector, and then this logic is also used in the `native_endian`
test, depending on the current `#[cfg(target_endian)]`.
Fixes #102.
---
src/lib.rs | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
index b60fe7c..35c0069 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2865,9 +2865,8 @@ mod stdtests {
fn prop(n: $ty_int) -> bool {
let mut wtr = vec![];
wtr.$write::<BigEndian>(n.clone()).unwrap();
- let mut rdr = Vec::new();
- rdr.extend(wtr[wtr.len()-$bytes..].iter().map(|&x| x));
- let mut rdr = Cursor::new(rdr);
+ let offset = wtr.len() - $bytes;
+ let mut rdr = Cursor::new(&mut wtr[offset..]);
n == rdr.$read::<BigEndian>($bytes).unwrap()
}
qc_sized(prop as fn($ty_int) -> bool, $max);
@@ -2889,7 +2888,12 @@ mod stdtests {
fn prop(n: $ty_int) -> bool {
let mut wtr = vec![];
wtr.$write::<NativeEndian>(n.clone()).unwrap();
- let mut rdr = Cursor::new(wtr);
+ let offset = if cfg!(target_endian = "big") {
+ wtr.len() - $bytes
+ } else {
+ 0
+ };
+ let mut rdr = Cursor::new(&mut wtr[offset..]);
n == rdr.$read::<NativeEndian>($bytes).unwrap()
}
qc_sized(prop as fn($ty_int) -> bool, $max);
--
2.15.0

@ -12,6 +12,8 @@ Summary: Library for reading/writing numbers in big-endian and little-end
License: Unlicense or MIT
URL: https://crates.io/crates/byteorder
Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
# https://github.com/BurntSushi/byteorder/pull/104
Patch0: 0001-Fix-prop_ext_-u-int_-native_endian-on-BE-targets.patch
ExclusiveArch: %{rust_arches}

Loading…
Cancel
Save