Skip to content

Commit

Permalink
Append env::consts::OS to snapshot filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Dec 17, 2024
1 parent 0ad40d0 commit 2f98a7e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions examples/todos/snapshots/creates_a_new_task-linux.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e0b1f2e0c0af6324eb45fde8e82384d16acc2a80a9e157bdf3f42ac6548181cf
1 change: 0 additions & 1 deletion examples/todos/snapshots/creates_a_new_task.sha256

This file was deleted.

3 changes: 1 addition & 2 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,11 @@ mod tests {
use iced_test::{selector, Error, Simulator};

fn simulator(todos: &Todos) -> Simulator<Message> {
Simulator::with_size(
Simulator::with_settings(
Settings {
fonts: vec![Todos::ICON_FONT.into()],
..Settings::default()
},
(512.0, 512.0),
todos.view(),
)
}
Expand Down
2 changes: 0 additions & 2 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 16 additions & 12 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -369,7 +363,7 @@ pub struct Snapshot {

impl Snapshot {
pub fn matches_image(&self, path: impl AsRef<Path>) -> Result<bool, Error> {
let path = path.as_ref().with_extension("png");
let path = snapshot_path(path, "png");

if path.exists() {
let file = fs::File::open(&path)?;
Expand Down Expand Up @@ -405,7 +399,7 @@ impl Snapshot {
pub fn matches_hash(&self, path: impl AsRef<Path>) -> Result<bool, Error> {
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();
Expand Down Expand Up @@ -497,3 +491,13 @@ impl From<png::EncodingError> for Error {
Self::PngEncodingFailed(Arc::new(error))
}
}

fn snapshot_path(path: impl AsRef<Path>, 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,
))
}

0 comments on commit 2f98a7e

Please sign in to comment.