diff --git a/Cargo.lock b/Cargo.lock index 74d1f9353..e5a2618f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4383,6 +4383,7 @@ dependencies = [ name = "tests" version = "0.1.0" dependencies = [ + "anyhow", "approx", "env_logger", "futures", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 215b2f919..a9235f474 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -29,6 +29,7 @@ serde = "1.0" toml = "0.5.10" libtest-mimic = "0.6.0" walkdir = "2.3.2" +anyhow = "1.0" [[test]] name = "tests" diff --git a/tests/tests/options.rs b/tests/tests/options.rs index d79a6ff76..d900e6120 100644 --- a/tests/tests/options.rs +++ b/tests/tests/options.rs @@ -1,7 +1,10 @@ +use anyhow::Result; use approx::assert_relative_eq; use regex::Regex; use ruffle_core::{Player, ViewportDimensions}; use serde::Deserialize; +use std::fs; +use std::path::Path; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -29,6 +32,12 @@ impl Default for TestOptions { } } +impl TestOptions { + pub fn read>(path: P) -> Result { + Ok(toml::from_str(&fs::read_to_string(path)?)?) + } +} + #[derive(Deserialize, Default)] #[serde(default)] pub struct Approximations { diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index 9e16aa5b1..6380afe25 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -25,7 +25,6 @@ use ruffle_render_wgpu::backend::WgpuRenderBackend; use ruffle_render_wgpu::{target::TextureTarget, wgpu}; use std::cell::RefCell; use std::collections::BTreeMap; -use std::fs; use std::path::Path; use std::rc::Rc; use std::sync::{Arc, Mutex}; @@ -701,8 +700,7 @@ fn main() { .map(Result::unwrap) .filter(|entry| entry.file_type().is_file() && entry.file_name() == "test.toml") .map(|file| { - let options: TestOptions = - toml::from_str(&fs::read_to_string(&file.path()).unwrap()).unwrap(); + let options = TestOptions::read(file.path()).unwrap(); let test_dir = file.path().parent().unwrap().to_owned(); let name = test_dir .strip_prefix(root)