Append env::consts::OS to snapshot filenames
This commit is contained in:
parent
0ad40d0338
commit
2f98a7e203
5 changed files with 18 additions and 17 deletions
1
examples/todos/snapshots/creates_a_new_task-linux.sha256
Normal file
1
examples/todos/snapshots/creates_a_new_task-linux.sha256
Normal file
|
|
@ -0,0 +1 @@
|
|||
e0b1f2e0c0af6324eb45fde8e82384d16acc2a80a9e157bdf3f42ac6548181cf
|
||||
|
|
@ -1 +0,0 @@
|
|||
b41c73d214894bf5f94f787e5f265cff6500822b2d4a29a4ac0c847a71db7123
|
||||
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<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)?;
|
||||
|
|
@ -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();
|
||||
|
|
@ -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,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue