Skip to content

Commit abb3a54

Browse files
committed
make tests no-std-compatible
1 parent eebb2dc commit abb3a54

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

tests/test_ref.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::fs::{self, File};
22
use std::path::{Path, PathBuf};
33

4-
use anyhow::{bail, Result};
54
use cfg_if::cfg_if;
65
use walkdir::{DirEntry, WalkDir};
76

8-
use qoi::{decode_to_vec, encode_to_vec};
7+
use qoi::{decode_to_vec, encode_to_vec, Result};
98

109
fn find_qoi_png_pairs(root: impl AsRef<Path>) -> Vec<(PathBuf, PathBuf)> {
1110
let root = root.as_ref();
@@ -29,7 +28,7 @@ fn find_qoi_png_pairs(root: impl AsRef<Path>) -> Vec<(PathBuf, PathBuf)> {
2928
WalkDir::new(root)
3029
.follow_links(true)
3130
.into_iter()
32-
.filter_map(Result::ok)
31+
.filter_map(std::result::Result::ok)
3332
.map(DirEntry::into_path)
3433
.filter_map(|p| check_qoi_png_pair(&p)),
3534
)
@@ -45,18 +44,18 @@ struct Image {
4544
}
4645

4746
impl Image {
48-
fn from_png(filename: &Path) -> Result<Self> {
49-
let decoder = png::Decoder::new(File::open(filename)?);
50-
let mut reader = decoder.read_info()?;
47+
fn from_png(filename: &Path) -> Self {
48+
let decoder = png::Decoder::new(File::open(filename).unwrap());
49+
let mut reader = decoder.read_info().unwrap();
5150
let mut buf = vec![0; reader.output_buffer_size()];
52-
let info = reader.next_frame(&mut buf)?;
51+
let info = reader.next_frame(&mut buf).unwrap();
5352
let bytes = &buf[..info.buffer_size()];
54-
Ok(Self {
53+
Self {
5554
width: info.width,
5655
height: info.height,
5756
channels: info.color_type.samples() as u8,
5857
data: bytes.to_vec(),
59-
})
58+
}
6059
}
6160
}
6261

@@ -67,7 +66,7 @@ fn compare_slices(name: &str, desc: &str, result: &[u8], expected: &[u8]) -> Res
6766
if let Some(i) =
6867
(0..result.len().min(expected.len())).position(|i| result[i] != expected[i])
6968
{
70-
bail!(
69+
panic!(
7170
"{}: {} mismatch at byte {}: expected {:?}, got {:?}",
7271
name,
7372
desc,
@@ -76,7 +75,7 @@ fn compare_slices(name: &str, desc: &str, result: &[u8], expected: &[u8]) -> Res
7675
&result[i..(i + 4).min(result.len())],
7776
);
7877
} else {
79-
bail!(
78+
panic!(
8079
"{}: {} length mismatch: expected {}, got {}",
8180
name,
8281
desc,
@@ -94,10 +93,10 @@ fn test_reference_images() -> Result<()> {
9493

9594
for (qoi_path, png_path) in &pairs {
9695
let png_name = png_path.file_name().unwrap_or_default().to_string_lossy();
97-
let img = Image::from_png(png_path)?;
96+
let img = Image::from_png(png_path);
9897
println!("{} {} {} {}", png_name, img.width, img.height, img.channels);
9998
let encoded = encode_to_vec(&img.data, img.width, img.height)?;
100-
let expected = fs::read(qoi_path)?;
99+
let expected = fs::read(qoi_path).unwrap();
101100
assert_eq!(encoded.len(), expected.len()); // this should match regardless
102101
cfg_if! {
103102
if #[cfg(feature = "reference")] {

0 commit comments

Comments
 (0)