mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Enforce consistent snapshot updates (#7744)
* Closes https://github.com/emilk/egui/issues/7647 This collects SnapshotResults within the Harness and adds a check to enforce snapshot results are merged in case multiple Harnesses are constructed within a test. This should make snapshot updates via kitdiff/accept_snapshots.sh way more useful since it should now always update all snapshots instead of only the first one per test.
This commit is contained in:
@@ -357,11 +357,13 @@ fn rect_shape_ui(ui: &mut egui::Ui, shape: &mut RectShape) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::View as _;
|
||||
use egui_kittest::SnapshotResults;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn snapshot_tessellation_test() {
|
||||
let mut results = SnapshotResults::new();
|
||||
for (name, shape) in TessellationTest::interesting_shapes() {
|
||||
let mut test = TessellationTest {
|
||||
shape,
|
||||
@@ -375,6 +377,7 @@ mod tests {
|
||||
harness.run();
|
||||
|
||||
harness.snapshot(format!("tessellation_test/{name}"));
|
||||
results.extend_harness(&mut harness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::View as _;
|
||||
use egui::Vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::{Harness, SnapshotResults};
|
||||
|
||||
#[test]
|
||||
pub fn should_match_screenshot() {
|
||||
@@ -320,6 +320,8 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut results = SnapshotResults::new();
|
||||
|
||||
for pixels_per_point in [1, 2] {
|
||||
for theme in [egui::Theme::Light, egui::Theme::Dark] {
|
||||
let mut harness = Harness::builder()
|
||||
@@ -339,6 +341,7 @@ mod tests {
|
||||
};
|
||||
let image_name = format!("widget_gallery_{theme_name}_x{pixels_per_point}");
|
||||
harness.snapshot(&image_name);
|
||||
results.extend_harness(&mut harness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use egui_kittest::Harness;
|
||||
|
||||
#[test]
|
||||
fn test_image_blending() {
|
||||
let mut results = egui_kittest::SnapshotResults::new();
|
||||
for pixels_per_point in [1.0, 2.0] {
|
||||
let mut harness = Harness::builder()
|
||||
.with_pixels_per_point(pixels_per_point)
|
||||
@@ -21,5 +22,6 @@ fn test_image_blending() {
|
||||
harness.run();
|
||||
harness.fit_contents();
|
||||
harness.snapshot(format!("image_blending/image_x{pixels_per_point}"));
|
||||
results.extend_harness(&mut harness);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use egui_kittest::{Harness, kittest::Queryable as _};
|
||||
|
||||
#[test]
|
||||
fn test_kerning() {
|
||||
let mut results = egui_kittest::SnapshotResults::new();
|
||||
for pixels_per_point in [1.0, 2.0] {
|
||||
for theme in [egui::Theme::Dark, egui::Theme::Light] {
|
||||
let mut harness = Harness::builder()
|
||||
@@ -24,12 +25,14 @@ fn test_kerning() {
|
||||
egui::Theme::Light => "light",
|
||||
}
|
||||
));
|
||||
results.extend_harness(&mut harness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_italics() {
|
||||
let mut results = egui_kittest::SnapshotResults::new();
|
||||
for pixels_per_point in [1.0, 2.0_f32.sqrt(), 2.0] {
|
||||
for theme in [egui::Theme::Dark, egui::Theme::Light] {
|
||||
let mut harness = Harness::builder()
|
||||
@@ -49,6 +52,7 @@ fn test_italics() {
|
||||
egui::Theme::Light => "light",
|
||||
}
|
||||
));
|
||||
results.extend_harness(&mut harness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user