egui_kittest: more ergonomic functions taking `Impl Into<String>` (#7307)
This commit is contained in:
parent
b11b77e85f
commit
09596a5e7b
|
|
@ -69,6 +69,6 @@ fn test_demo_app() {
|
||||||
// Can't use Harness::run because fractal clock keeps requesting repaints
|
// Can't use Harness::run because fractal clock keeps requesting repaints
|
||||||
harness.run_steps(4);
|
harness.run_steps(4);
|
||||||
|
|
||||||
results.add(harness.try_snapshot(&anchor.to_string()));
|
results.add(harness.try_snapshot(anchor.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -416,7 +416,7 @@ mod tests {
|
||||||
options = options.threshold(OsThreshold::new(0.0).linux(2.1));
|
options = options.threshold(OsThreshold::new(0.0).linux(2.1));
|
||||||
}
|
}
|
||||||
|
|
||||||
results.add(harness.try_snapshot_options(&format!("demos/{name}"), &options));
|
results.add(harness.try_snapshot_options(format!("demos/{name}"), &options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ mod tests {
|
||||||
harness.fit_contents();
|
harness.fit_contents();
|
||||||
harness.run();
|
harness.run();
|
||||||
|
|
||||||
harness.snapshot(&format!("tessellation_test/{name}"));
|
harness.snapshot(format!("tessellation_test/{name}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -745,7 +745,7 @@ mod tests {
|
||||||
|
|
||||||
harness.fit_contents();
|
harness.fit_contents();
|
||||||
|
|
||||||
results.add(harness.try_snapshot(&format!("rendering_test/dpi_{dpi:.2}")));
|
results.add(harness.try_snapshot(format!("rendering_test/dpi_{dpi:.2}")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,15 @@ fn should_update_snapshots() -> bool {
|
||||||
/// reading or writing the snapshot.
|
/// reading or writing the snapshot.
|
||||||
pub fn try_image_snapshot_options(
|
pub fn try_image_snapshot_options(
|
||||||
new: &image::RgbaImage,
|
new: &image::RgbaImage,
|
||||||
name: &str,
|
name: impl Into<String>,
|
||||||
|
options: &SnapshotOptions,
|
||||||
|
) -> SnapshotResult {
|
||||||
|
try_image_snapshot_options_impl(new, name.into(), options)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_image_snapshot_options_impl(
|
||||||
|
new: &image::RgbaImage,
|
||||||
|
name: String,
|
||||||
options: &SnapshotOptions,
|
options: &SnapshotOptions,
|
||||||
) -> SnapshotResult {
|
) -> SnapshotResult {
|
||||||
let SnapshotOptions {
|
let SnapshotOptions {
|
||||||
|
|
@ -319,7 +327,7 @@ pub fn try_image_snapshot_options(
|
||||||
failed_pixel_count_threshold,
|
failed_pixel_count_threshold,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
let parent_path = if let Some(parent) = PathBuf::from(name).parent() {
|
let parent_path = if let Some(parent) = PathBuf::from(&name).parent() {
|
||||||
output_path.join(parent)
|
output_path.join(parent)
|
||||||
} else {
|
} else {
|
||||||
output_path.clone()
|
output_path.clone()
|
||||||
|
|
@ -385,7 +393,7 @@ pub fn try_image_snapshot_options(
|
||||||
return update_snapshot();
|
return update_snapshot();
|
||||||
} else {
|
} else {
|
||||||
return Err(SnapshotError::SizeMismatch {
|
return Err(SnapshotError::SizeMismatch {
|
||||||
name: name.to_owned(),
|
name,
|
||||||
expected: previous.dimensions(),
|
expected: previous.dimensions(),
|
||||||
actual: new.dimensions(),
|
actual: new.dimensions(),
|
||||||
});
|
});
|
||||||
|
|
@ -412,7 +420,7 @@ pub fn try_image_snapshot_options(
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(SnapshotError::Diff {
|
Err(SnapshotError::Diff {
|
||||||
name: name.to_owned(),
|
name,
|
||||||
diff: num_wrong_pixels,
|
diff: num_wrong_pixels,
|
||||||
diff_path,
|
diff_path,
|
||||||
})
|
})
|
||||||
|
|
@ -435,7 +443,7 @@ pub fn try_image_snapshot_options(
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns a [`SnapshotError`] if the image does not match the snapshot or if there was an error
|
/// Returns a [`SnapshotError`] if the image does not match the snapshot or if there was an error
|
||||||
/// reading or writing the snapshot.
|
/// reading or writing the snapshot.
|
||||||
pub fn try_image_snapshot(current: &image::RgbaImage, name: &str) -> SnapshotResult {
|
pub fn try_image_snapshot(current: &image::RgbaImage, name: impl Into<String>) -> SnapshotResult {
|
||||||
try_image_snapshot_options(current, name, &SnapshotOptions::default())
|
try_image_snapshot_options(current, name, &SnapshotOptions::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -456,7 +464,11 @@ pub fn try_image_snapshot(current: &image::RgbaImage, name: &str) -> SnapshotRes
|
||||||
/// Panics if the image does not match the snapshot or if there was an error reading or writing the
|
/// Panics if the image does not match the snapshot or if there was an error reading or writing the
|
||||||
/// snapshot.
|
/// snapshot.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn image_snapshot_options(current: &image::RgbaImage, name: &str, options: &SnapshotOptions) {
|
pub fn image_snapshot_options(
|
||||||
|
current: &image::RgbaImage,
|
||||||
|
name: impl Into<String>,
|
||||||
|
options: &SnapshotOptions,
|
||||||
|
) {
|
||||||
match try_image_snapshot_options(current, name, options) {
|
match try_image_snapshot_options(current, name, options) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -475,7 +487,7 @@ pub fn image_snapshot_options(current: &image::RgbaImage, name: &str, options: &
|
||||||
/// Panics if the image does not match the snapshot or if there was an error reading or writing the
|
/// Panics if the image does not match the snapshot or if there was an error reading or writing the
|
||||||
/// snapshot.
|
/// snapshot.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn image_snapshot(current: &image::RgbaImage, name: &str) {
|
pub fn image_snapshot(current: &image::RgbaImage, name: impl Into<String>) {
|
||||||
match try_image_snapshot(current, name) {
|
match try_image_snapshot(current, name) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -506,13 +518,13 @@ impl<State> Harness<'_, State> {
|
||||||
/// error reading or writing the snapshot, if the rendering fails or if no default renderer is available.
|
/// error reading or writing the snapshot, if the rendering fails or if no default renderer is available.
|
||||||
pub fn try_snapshot_options(
|
pub fn try_snapshot_options(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &str,
|
name: impl Into<String>,
|
||||||
options: &SnapshotOptions,
|
options: &SnapshotOptions,
|
||||||
) -> SnapshotResult {
|
) -> SnapshotResult {
|
||||||
let image = self
|
let image = self
|
||||||
.render()
|
.render()
|
||||||
.map_err(|err| SnapshotError::RenderError { err })?;
|
.map_err(|err| SnapshotError::RenderError { err })?;
|
||||||
try_image_snapshot_options(&image, name, options)
|
try_image_snapshot_options(&image, name.into(), options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render an image using the setup [`crate::TestRenderer`] and compare it to the snapshot.
|
/// Render an image using the setup [`crate::TestRenderer`] and compare it to the snapshot.
|
||||||
|
|
@ -523,7 +535,7 @@ impl<State> Harness<'_, State> {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns a [`SnapshotError`] if the image does not match the snapshot, if there was an
|
/// Returns a [`SnapshotError`] if the image does not match the snapshot, if there was an
|
||||||
/// error reading or writing the snapshot, if the rendering fails or if no default renderer is available.
|
/// error reading or writing the snapshot, if the rendering fails or if no default renderer is available.
|
||||||
pub fn try_snapshot(&mut self, name: &str) -> SnapshotResult {
|
pub fn try_snapshot(&mut self, name: impl Into<String>) -> SnapshotResult {
|
||||||
let image = self
|
let image = self
|
||||||
.render()
|
.render()
|
||||||
.map_err(|err| SnapshotError::RenderError { err })?;
|
.map_err(|err| SnapshotError::RenderError { err })?;
|
||||||
|
|
@ -549,7 +561,7 @@ impl<State> Harness<'_, State> {
|
||||||
/// Panics if the image does not match the snapshot, if there was an error reading or writing the
|
/// Panics if the image does not match the snapshot, if there was an error reading or writing the
|
||||||
/// snapshot, if the rendering fails or if no default renderer is available.
|
/// snapshot, if the rendering fails or if no default renderer is available.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn snapshot_options(&mut self, name: &str, options: &SnapshotOptions) {
|
pub fn snapshot_options(&mut self, name: impl Into<String>, options: &SnapshotOptions) {
|
||||||
match self.try_snapshot_options(name, options) {
|
match self.try_snapshot_options(name, options) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -567,7 +579,7 @@ impl<State> Harness<'_, State> {
|
||||||
/// Panics if the image does not match the snapshot, if there was an error reading or writing the
|
/// Panics if the image does not match the snapshot, if there was an error reading or writing the
|
||||||
/// snapshot, if the rendering fails or if no default renderer is available.
|
/// snapshot, if the rendering fails or if no default renderer is available.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn snapshot(&mut self, name: &str) {
|
pub fn snapshot(&mut self, name: impl Into<String>) {
|
||||||
match self.try_snapshot(name) {
|
match self.try_snapshot(name) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -588,7 +600,7 @@ impl<State> Harness<'_, State> {
|
||||||
)]
|
)]
|
||||||
pub fn try_wgpu_snapshot_options(
|
pub fn try_wgpu_snapshot_options(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &str,
|
name: impl Into<String>,
|
||||||
options: &SnapshotOptions,
|
options: &SnapshotOptions,
|
||||||
) -> SnapshotResult {
|
) -> SnapshotResult {
|
||||||
self.try_snapshot_options(name, options)
|
self.try_snapshot_options(name, options)
|
||||||
|
|
@ -598,7 +610,7 @@ impl<State> Harness<'_, State> {
|
||||||
since = "0.31.0",
|
since = "0.31.0",
|
||||||
note = "Use `try_snapshot` instead. This function will be removed in 0.32"
|
note = "Use `try_snapshot` instead. This function will be removed in 0.32"
|
||||||
)]
|
)]
|
||||||
pub fn try_wgpu_snapshot(&mut self, name: &str) -> SnapshotResult {
|
pub fn try_wgpu_snapshot(&mut self, name: impl Into<String>) -> SnapshotResult {
|
||||||
self.try_snapshot(name)
|
self.try_snapshot(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -606,7 +618,7 @@ impl<State> Harness<'_, State> {
|
||||||
since = "0.31.0",
|
since = "0.31.0",
|
||||||
note = "Use `snapshot_options` instead. This function will be removed in 0.32"
|
note = "Use `snapshot_options` instead. This function will be removed in 0.32"
|
||||||
)]
|
)]
|
||||||
pub fn wgpu_snapshot_options(&mut self, name: &str, options: &SnapshotOptions) {
|
pub fn wgpu_snapshot_options(&mut self, name: impl Into<String>, options: &SnapshotOptions) {
|
||||||
self.snapshot_options(name, options);
|
self.snapshot_options(name, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,6 @@ fn test_variants(
|
||||||
harness.fit_contents();
|
harness.fit_contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
results.add(harness.try_snapshot(&format!("sides/{name}_{variant_name}")));
|
results.add(harness.try_snapshot(format!("sides/{name}_{variant_name}")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ fn test_widget_layout(name: &str, mut w: impl FnMut(&mut Ui) -> Response) -> Sna
|
||||||
});
|
});
|
||||||
|
|
||||||
harness.fit_contents();
|
harness.fit_contents();
|
||||||
harness.try_snapshot(&format!("layout/{name}"))
|
harness.try_snapshot(format!("layout/{name}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Utility to create a snapshot test of the different states of a egui widget.
|
/// Utility to create a snapshot test of the different states of a egui widget.
|
||||||
|
|
@ -370,7 +370,7 @@ impl<'a> VisualTests<'a> {
|
||||||
|
|
||||||
harness.fit_contents();
|
harness.fit_contents();
|
||||||
|
|
||||||
harness.try_snapshot(&format!("visuals/{}", self.name))
|
harness.try_snapshot(format!("visuals/{}", self.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue