tests: Extract TestOptions::read() for parsing a file

This commit is contained in:
Nathan Adams 2023-01-27 17:03:20 +01:00 committed by kmeisthax
parent 316df5b415
commit ff8506d351
4 changed files with 12 additions and 3 deletions

1
Cargo.lock generated
View File

@ -4383,6 +4383,7 @@ dependencies = [
name = "tests"
version = "0.1.0"
dependencies = [
"anyhow",
"approx",
"env_logger",
"futures",

View File

@ -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"

View File

@ -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<P: AsRef<Path>>(path: P) -> Result<Self> {
Ok(toml::from_str(&fs::read_to_string(path)?)?)
}
}
#[derive(Deserialize, Default)]
#[serde(default)]
pub struct Approximations {

View File

@ -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)