From c59f6ac686c0564fba02203539e46e4d18e2bc90 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Mon, 3 Jan 2022 15:56:17 +0300 Subject: [PATCH] Update the tests (with reference feature on/off) --- Cargo.toml | 1 + tests/test_ref.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 99630b0..c0f61ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ members = ["qoi-bench"] anyhow = "1.0" png = "0.17" walkdir = "2.3" +cfg-if = "1.0" [lib] name = "qoi_fast" diff --git a/tests/test_ref.rs b/tests/test_ref.rs index e35eb28..1fd301e 100644 --- a/tests/test_ref.rs +++ b/tests/test_ref.rs @@ -2,6 +2,7 @@ use std::fs::{self, File}; use std::path::{Path, PathBuf}; use anyhow::{bail, Result}; +use cfg_if::cfg_if; use walkdir::{DirEntry, WalkDir}; use qoi_fast::{qoi_decode_to_vec, qoi_encode_to_vec}; @@ -97,9 +98,15 @@ fn test_reference_images() -> Result<()> { println!("{} {} {} {}", png_name, img.width, img.height, img.channels); let encoded = qoi_encode_to_vec(&img.data, img.width, img.height)?; let expected = fs::read(qoi_path)?; - compare_slices(&png_name, "encoding", &encoded, &expected)?; - let (_header, decoded) = qoi_decode_to_vec(&expected)?; - compare_slices(&png_name, "decoding", &decoded, &img.data)?; + cfg_if! { + if #[cfg(feature = "reference")] { + compare_slices(&png_name, "encoding", &encoded, &expected)?; + } + } + let (_header1, decoded1) = qoi_decode_to_vec(&encoded)?; + let (_header2, decoded2) = qoi_decode_to_vec(&expected)?; + compare_slices(&png_name, "decoding [1]", &decoded1, &img.data)?; + compare_slices(&png_name, "decoding [2]", &decoded2, &img.data)?; } Ok(())