From 1534440b0baecc1515c17d1871e86b1ee7b8596e Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 12 Jan 2024 20:56:10 +0000 Subject: [PATCH] Move tests out of published package Fixes #51 --- Cargo.toml | 27 +-------------------------- src/lib.rs | 18 ------------------ src/reader/mod.rs | 22 +--------------------- tests/check_testimages.rs | 1 + tests/crashtest.rs | 2 ++ tests/decode.rs | 21 +++++++++++++++++++++ tests/roundtrip.rs | 19 +++++++++++++++++++ tests/stall.rs | 2 ++ 8 files changed, 47 insertions(+), 65 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11542ab..71b1ac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,7 @@ homepage = "https://github.com/image-rs/image-gif" repository = "https://github.com/image-rs/image-gif" documentation = "https://docs.rs/gif" edition = "2021" -exclude = [ - "tests/crashtest/*", - "tests/samples/*", - "benches/*.gif", - "gif-afl/*", -] +include = ["src/**", "LICENSE-*", "README.md", "benches/*.rs"] [lib] bench = false @@ -37,26 +32,6 @@ color_quant = ["dep:color_quant"] # Reservation for a feature turning off std std = [] -[[test]] -name = "check_testimages" -required-features = ["std"] - -[[test]] -name = "crashtest" -required-features = ["std"] - -[[test]] -name = "decode" -required-features = ["std"] - -[[test]] -name = "stall" -required-features = ["std"] - -[[test]] -name = "roundtrip" -required-features = ["std"] - [[bench]] name = "decode" harness = false diff --git a/src/lib.rs b/src/lib.rs index 0221b06..1a845e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,24 +131,6 @@ pub mod streaming_decoder { pub use crate::reader::{StreamingDecoder, OutputBuffer, Decoded, FrameDataType}; } -#[cfg(test)] -#[test] -fn round_trip() { - use std::io::prelude::*; - use std::fs::File; - let mut data = vec![]; - File::open("tests/samples/sample_1.gif").unwrap().read_to_end(&mut data).unwrap(); - let mut decoder = Decoder::new(&*data).unwrap(); - let palette: Vec = decoder.palette().unwrap().into(); - let frame = decoder.read_next_frame().unwrap().unwrap(); - let mut data2 = vec![]; - { - let mut encoder = Encoder::new(&mut data2, frame.width, frame.height, &palette).unwrap(); - encoder.write_frame(frame).unwrap(); - } - assert_eq!(&data[..], &data2[..]); -} - macro_rules! insert_as_doc { { $content:expr } => { #[allow(unused_doc_comments)] diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 1293b3d..1d0f7dd 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -637,27 +637,7 @@ impl iter::Iterator for InterlaceIterator { #[cfg(test)] mod test { - use std::fs::File; - - use super::{Decoder, InterlaceIterator}; - - #[test] - fn test_simple_indexed() { - let mut decoder = Decoder::new(File::open("tests/samples/sample_1.gif").unwrap()).unwrap(); - let frame = decoder.read_next_frame().unwrap().unwrap(); - assert_eq!(&*frame.buffer, &[ - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, - 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, - 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, - 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, - 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, - 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 1, 1, 1, 1, 1 - ][..]); - } + use super::InterlaceIterator; #[test] fn test_interlace_iterator() { diff --git a/tests/check_testimages.rs b/tests/check_testimages.rs index 831381c..58733c0 100644 --- a/tests/check_testimages.rs +++ b/tests/check_testimages.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "std")] use std::collections::HashMap; use std::fs::File; diff --git a/tests/crashtest.rs b/tests/crashtest.rs index ef67cb3..a67b3bd 100644 --- a/tests/crashtest.rs +++ b/tests/crashtest.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "std")] + use std::{fs, io}; use gif::DecodeOptions; diff --git a/tests/decode.rs b/tests/decode.rs index 5977fa8..f56f6bd 100644 --- a/tests/decode.rs +++ b/tests/decode.rs @@ -1,4 +1,25 @@ +#![cfg(feature = "std")] + use gif::{Decoder, DecodeOptions, DisposalMethod, Encoder, Frame}; +use std::fs::File; + +#[test] +fn test_simple_indexed() { + let mut decoder = Decoder::new(File::open("tests/samples/sample_1.gif").unwrap()).unwrap(); + let frame = decoder.read_next_frame().unwrap().unwrap(); + assert_eq!(&*frame.buffer, &[ + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, + 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, + 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, + 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1 + ][..]); +} #[test] fn frame_consistency_is_configurable() { diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index 2d56aa1..008355e 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -1,5 +1,24 @@ +#![cfg(feature = "std")] + use gif::{ColorOutput, Decoder, Encoder, Frame}; +#[test] +fn round_trip() { + use std::io::prelude::*; + use std::fs::File; + let mut data = vec![]; + File::open("tests/samples/sample_1.gif").unwrap().read_to_end(&mut data).unwrap(); + let mut decoder = Decoder::new(&*data).unwrap(); + let palette: Vec = decoder.palette().unwrap().into(); + let frame = decoder.read_next_frame().unwrap().unwrap(); + let mut data2 = vec![]; + { + let mut encoder = Encoder::new(&mut data2, frame.width, frame.height, &palette).unwrap(); + encoder.write_frame(frame).unwrap(); + } + assert_eq!(&data[..], &data2[..]); +} + #[test] fn encode_roundtrip() { const ORIGINAL: &[u8] = include_bytes!("samples/2x2.gif"); diff --git a/tests/stall.rs b/tests/stall.rs index 3d51a17..1e58d65 100644 --- a/tests/stall.rs +++ b/tests/stall.rs @@ -1,3 +1,5 @@ +#![cfg(feature = "std")] + use std::{fs, sync::mpsc, thread, time::Duration}; #[test]