From 2f98a7e2032715409891e6d2c9f8529cfed59569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 17 Dec 2024 02:17:07 +0100 Subject: [PATCH] Append `env::consts::OS` to snapshot filenames --- .../snapshots/creates_a_new_task-linux.sha256 | 1 + .../todos/snapshots/creates_a_new_task.sha256 | 1 - examples/todos/src/main.rs | 3 +- test/Cargo.toml | 2 -- test/src/lib.rs | 28 +++++++++++-------- 5 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 examples/todos/snapshots/creates_a_new_task-linux.sha256 delete mode 100644 examples/todos/snapshots/creates_a_new_task.sha256 diff --git a/examples/todos/snapshots/creates_a_new_task-linux.sha256 b/examples/todos/snapshots/creates_a_new_task-linux.sha256 new file mode 100644 index 0000000000..9291711e44 --- /dev/null +++ b/examples/todos/snapshots/creates_a_new_task-linux.sha256 @@ -0,0 +1 @@ +e0b1f2e0c0af6324eb45fde8e82384d16acc2a80a9e157bdf3f42ac6548181cf \ No newline at end of file diff --git a/examples/todos/snapshots/creates_a_new_task.sha256 b/examples/todos/snapshots/creates_a_new_task.sha256 deleted file mode 100644 index 75d5f2ce1e..0000000000 --- a/examples/todos/snapshots/creates_a_new_task.sha256 +++ /dev/null @@ -1 +0,0 @@ -b41c73d214894bf5f94f787e5f265cff6500822b2d4a29a4ac0c847a71db7123 \ No newline at end of file diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 0b80f00271..1cc4778219 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -594,12 +594,11 @@ mod tests { use iced_test::{selector, Error, Simulator}; fn simulator(todos: &Todos) -> Simulator { - Simulator::with_size( + Simulator::with_settings( Settings { fonts: vec![Todos::ICON_FONT.into()], ..Settings::default() }, - (512.0, 512.0), todos.view(), ) } diff --git a/test/Cargo.toml b/test/Cargo.toml index ff6cb38a37..47e9be11ac 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -15,9 +15,7 @@ workspace = true [dependencies] iced_runtime.workspace = true - iced_renderer.workspace = true -iced_renderer.features = ["fira-sans"] png.workspace = true sha2.workspace = true diff --git a/test/src/lib.rs b/test/src/lib.rs index 00126e643e..fa802dea3f 100644 --- a/test/src/lib.rs +++ b/test/src/lib.rs @@ -16,16 +16,15 @@ use crate::core::theme; use crate::core::time; use crate::core::widget; use crate::core::window; -use crate::core::{ - Element, Event, Font, Point, Rectangle, Settings, Size, SmolStr, -}; +use crate::core::{Element, Event, Point, Rectangle, Settings, Size, SmolStr}; use crate::runtime::user_interface; use crate::runtime::UserInterface; use std::borrow::Cow; +use std::env; use std::fs; use std::io; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::sync::Arc; pub fn simulator<'a, Message, Theme, Renderer>( @@ -89,17 +88,12 @@ where ) -> Self { let size = size.into(); - let default_font = match settings.default_font { - Font::DEFAULT => Font::with_name("Fira Sans"), - _ => settings.default_font, - }; - for font in settings.fonts { load_font(font).expect("Font must be valid"); } let mut renderer = - Renderer::new(default_font, settings.default_text_size); + Renderer::new(settings.default_font, settings.default_text_size); let raw = UserInterface::build( element, @@ -369,7 +363,7 @@ pub struct Snapshot { impl Snapshot { pub fn matches_image(&self, path: impl AsRef) -> Result { - let path = path.as_ref().with_extension("png"); + let path = snapshot_path(path, "png"); if path.exists() { let file = fs::File::open(&path)?; @@ -405,7 +399,7 @@ impl Snapshot { pub fn matches_hash(&self, path: impl AsRef) -> Result { use sha2::{Digest, Sha256}; - let path = path.as_ref().with_extension("sha256"); + let path = snapshot_path(path, "sha256"); let hash = { let mut hasher = Sha256::new(); @@ -497,3 +491,13 @@ impl From for Error { Self::PngEncodingFailed(Arc::new(error)) } } + +fn snapshot_path(path: impl AsRef, extension: &str) -> PathBuf { + let path = path.as_ref(); + + path.with_file_name(format!( + "{file_stem}-{os}.{extension}", + file_stem = path.file_stem().unwrap_or_default().to_string_lossy(), + os = env::consts::OS, + )) +}