/// read all images in a directory.
/// does not check any content, just checks whether a read error or panic happened.
read all images in a directory.
does not check any content, just checks whether a read error or panic happened.
read all images in a directory . does not check any content just checks whether a read error or panic happened .
fn check_files<T>(
    ignore: Vec<PathBuf>,
    operation: impl Sync + std::panic::RefUnwindSafe + Fn(&Path) -> exr::error::Result<T>
) {
    #[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
    enum Result { Ok, Skipped, Unsupported(String), Error(String) }
    let files: Vec<PathBuf> = exr_files().collect();
    let mut results: Vec<(PathBuf, Result)> = files.into_par_iter()
        .map(|file| {
            if ignore.contains(&file) {
                return (file, Result::Skipped);
            }
            let result = catch_unwind(||{
                let prev_hook = panic::take_hook();
                panic::set_hook(Box::new(|_| (/* do not println panics */)));
                let result = operation(&file);
                panic::set_hook(prev_hook);
                result
            });
            let result = match result {
                Ok(Ok(_)) => Result::Ok,
                Ok(Err(Error::NotSupported(message))) => Result::Unsupported(message.to_string()),
                Ok(Err(Error::Io(io))) => Result::Error(format!("IoError: {:?}", io)),
                Ok(Err(Error::Invalid(message))) => Result::Error(format!("Invalid: {:?}", message)),
                Ok(Err(Error::Aborted)) => panic!("a test produced `Error::Abort`"),
                Err(_) => Result::Error("Panic".to_owned()),
            };
            match &result {
                Result::Error(_) => println!("✗ Error when processing {:?}", file),
                _ => println!("✓ No error when processing {:?}", file)
            };
            (file, result)
        })
        .collect();
    results.sort_by(|(_, a), (_, b)| a.cmp(b));
    println!("{:#?}", results.iter().map(|(path, result)| {
        format!("{:?}: {}", result, path.to_str().unwrap())
    }).collect::<Vec<_>>());
    assert!(results.len() > 80, "Not enough files were tested!");
    if let Result::Error(_) = results.last().unwrap().1 {
        panic!("A file triggered a panic");
    }
}
fn check_files < T > ( ignore : Vec < PathBuf > , operation : impl Sync + std :: panic :: RefUnwindSafe + Fn ( & Path ) -> exr :: error :: Result < T > ) { # [ derive ( Debug Eq PartialEq Ord PartialOrd ) ] enum Result { Ok , Skipped , Unsupported ( String ) , Error ( String ) } let files : Vec < PathBuf > = exr_files ( ) . collect ( ) ; let mut results : Vec < ( PathBuf , Result ) > = files . into_par_iter ( ) . map ( | file | { if ignore . contains ( & file ) { return ( file , Result :: Skipped ) ; } let result = catch_unwind ( | | { let prev_hook = panic :: take_hook ( ) ; panic :: set_hook ( Box :: new ( | _ | ( /* do not println panics */ ) ) ) ; let result = operation ( & file ) ; panic :: set_hook ( prev_hook ) ; result } ) ; let result = match result { Ok ( Ok ( _ ) ) => Result :: Ok , Ok ( Err ( Error :: NotSupported ( message ) ) ) => Result :: Unsupported ( message . to_string ( ) ) , Ok ( Err ( Error :: Io ( io ) ) ) => Result :: Error ( format ! ( " " io ) ) , Ok ( Err ( Error :: Invalid ( message ) ) ) => Result :: Error ( format ! ( " " message ) ) , Ok ( Err ( Error :: Aborted ) ) => panic ! ( " " ) , Err ( _ ) => Result :: Error ( " " . to_owned ( ) ) , } ; match & result { Result :: Error ( _ ) => println ! ( " le), _ => println ! ( " le) } ; ( file , result ) } ) . collect ( ) ; results . sort_by ( | ( _ , a ) , ( _ , b ) | a . cmp ( b ) ) ; println ! ( " " results iter ( ) map ( ( path result ) { format ( " " result path to_str ( ) unwrap ( ) ) } ) collect Vec ( ) ) ; assert ! ( results len ( ) 80 " " ) ; if let Result :: Error ( _ ) = results . last ( ) . unwrap ( ) . 1 { panic ! ( " " ) ; } }
read all images in a directory.
read all images in a directory .
ignore
Vec<PathBuf>
operation
impl Sync + std::panic::RefUnwindSafe + Fn(&Path) -> exr::error::Result<T>