diff --git a/Justfile b/Justfile index 352903d..953a57b 100644 --- a/Justfile +++ b/Justfile @@ -23,4 +23,5 @@ ci-test: source <(cargo llvm-cov show-env --export-prefix) cargo llvm-cov clean --workspace cargo nextest run --all-features --profile ci + ONE_BYTE_READ=1 cargo nextest run --all-features --release --profile ci cargo llvm-cov report --lcov --output-path coverage.lcov diff --git a/rc-zip-sync/tests/integration_tests.rs b/rc-zip-sync/tests/integration_tests.rs index 3df5500..f07225b 100644 --- a/rc-zip-sync/tests/integration_tests.rs +++ b/rc-zip-sync/tests/integration_tests.rs @@ -3,9 +3,12 @@ use rc_zip::{ error::Error, parse::Archive, }; -use rc_zip_sync::{ArchiveHandle, HasCursor, ReadZip, ReadZipStreaming}; +use rc_zip_sync::{ArchiveHandle, HasCursor, ReadZip, ReadZipStreaming, ReadZipWithSize}; -use std::{fs::File, io::Read}; +use std::{ + fs::File, + io::{self, Read}, +}; fn check_case(test: &Case, archive: Result, Error>) { corpus::check_case(test, archive.as_ref().map(|ar| -> &Archive { ar })); @@ -49,8 +52,15 @@ fn real_world_files() { let guarded_path = case.absolute_path(); let file = File::open(&guarded_path.path).unwrap(); - let archive = file.read_zip().map_err(Error::from); - check_case(&case, archive); + if let Ok("1") = std::env::var("ONE_BYTE_READ").as_deref() { + let size = file.metadata().unwrap().len(); + let file = OneByteReadWrapper(file); + let archive = file.read_zip_with_size(size).map_err(Error::from); + check_case(&case, archive); + } else { + let archive = file.read_zip().map_err(Error::from); + check_case(&case, archive); + }; drop(guarded_path) } } @@ -78,3 +88,27 @@ fn streaming() { drop(guarded_path) } } + +// This helps find bug in state machines! + +struct OneByteReadWrapper(R); + +impl io::Read for OneByteReadWrapper +where + R: io::Read, +{ + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0.read(&mut buf[..1]) + } +} + +impl HasCursor for OneByteReadWrapper +where + R: HasCursor, +{ + type Cursor<'a> = OneByteReadWrapper> where R: 'a; + + fn cursor_at(&self, offset: u64) -> Self::Cursor<'_> { + OneByteReadWrapper(self.0.cursor_at(offset)) + } +}