mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Tests: canvas tests that compare renders keep the proof view while they run
The proof view is process-wide, and the Proof Setup dialog tests turn Proof Colors on while other tests run. A change between two renders of a canvas test made the frames differ, and a_drag_on_the_canvas_draws_raster_effects_at_a_lower_resolution failed in full runs of the crate's tests. The Proof Setup tests' lock is now a read-write lock, and keeping_color_settings holds it for reading.
This commit is contained in:
1 parent
1759064a3e
commit
9c643e302e
2 files changed
+12
-4
No files matched your search
@@ -3059,7 +3059,9 @@ fn the_art_renders_within_the_largest_texture_side() {
|
||||
|
||||
/// Run a test that compares two renders with the color settings that are active when it starts.
|
||||
/// A test on another thread can change the process's active settings; this thread keeps its own.
|
||||
/// The proof view is process-wide, so the tests that change it wait until this one ends.
|
||||
fn keeping_color_settings(test: fn()) {
|
||||
let _view = crate::dialogs::proof_setup::tests::keeping_the_proof_view();
|
||||
vectorcraft_color::cms::with_active(vectorcraft_color::cms::active(), test);
|
||||
}
|
||||
|
||||
|
||||
@@ -492,18 +492,19 @@ pub fn saved_items() -> Vec<Item> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
/// Proof views are process-wide: these tests take turns, and each leaves the default view.
|
||||
static VIEW: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
/// Tests that compare renders hold it for reading ([`keeping_the_proof_view`]).
|
||||
static VIEW: std::sync::RwLock<()> = std::sync::RwLock::new(());
|
||||
|
||||
struct DefaultView<'a>(#[allow(dead_code)] std::sync::MutexGuard<'a, ()>);
|
||||
struct DefaultView<'a>(#[allow(dead_code)] std::sync::RwLockWriteGuard<'a, ()>);
|
||||
|
||||
impl DefaultView<'_> {
|
||||
fn new() -> Self {
|
||||
let g = VIEW.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let g = VIEW.write().unwrap_or_else(|e| e.into_inner());
|
||||
proof::set_view(Default::default());
|
||||
DefaultView(g)
|
||||
}
|
||||
@@ -515,6 +516,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the proof view as it is while the guard lives: the tests here wait to change it.
|
||||
pub(crate) fn keeping_the_proof_view() -> std::sync::RwLockReadGuard<'static, ()> {
|
||||
VIEW.read().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::super::show(app, ui.ctx()));
|
||||
out.textures_delta.clear();
|
||||
|
||||
Reference in new issue
Block a user