From 7120dd34e74a3aa465103a48c3024d7dbb02e39f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 15:51:37 -0800 Subject: [PATCH] Tests: panel readout copy cases hold the language guard The integration binary from #8826 draws the Links panel's Location case in French and German, and in an integration binary the UI language is one value for the whole process. Under `cargo test`, which runs the cases on threads of one process, the other five cases drew frames in French or German, or reset the language to English under the Location case. Taps then missed the moved readouts, and two cases failed on each run (on the Location case and on the first-click copy cases). nextest runs each case in its own process, so CI passed them. Each App now holds the same language guard as control_bar_corners.rs and selection_tools_toggle.rs: the cases run one at a time and the previous language comes back when the app drops. --- crates/ui-egui/tests/panel_readout_copy.rs | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/tests/panel_readout_copy.rs b/crates/ui-egui/tests/panel_readout_copy.rs index f86e93f895..5b5e048d09 100644 --- a/crates/ui-egui/tests/panel_readout_copy.rs +++ b/crates/ui-egui/tests/panel_readout_copy.rs @@ -4,7 +4,7 @@ use std::io::Cursor; use std::path::PathBuf; -use std::sync::{Arc, Mutex, mpsc}; +use std::sync::{Arc, Mutex, MutexGuard, mpsc}; use std::time::Duration; use craft::platform::clipboard::{Clipboard, ClipboardBackend, ClipboardError, ClipboardImage, Flavor}; @@ -13,11 +13,33 @@ use craft::ui::shell::embed; use egui::{Event, Modifiers, PointerButton, Pos2, Rect, Shape, vec2}; use serde_json::{Value, json}; use vectorcraft_engine::Session; -use vectorcraft_ui_egui::{Services, VectorcraftApp, background}; +use vectorcraft_ui_egui::{Services, VectorcraftApp, background, i18n}; const COPIED: &str = "Copied the value"; const LENGTH: &str = "234 pt"; +static CASE: Mutex<()> = Mutex::new(()); + +// Integration binaries use a process-wide locale, and the Location case draws in French and +// German. Each app holds the guard, so cases run one at a time, and restores the language. +struct Language { + _lock: MutexGuard<'static, ()>, + previous: i18n::Lang, +} +impl Language { + fn english() -> Self { + let lock = CASE.lock().unwrap_or_else(|e| e.into_inner()); + let previous = i18n::current(); + i18n::set_current(i18n::Lang::EN); + Self { _lock: lock, previous } + } +} +impl Drop for Language { + fn drop(&mut self) { + i18n::set_current(self.previous); + } +} + type ClipboardOffers = Arc>>>; struct Board(ClipboardOffers); @@ -57,10 +79,12 @@ struct App { app: VectorcraftApp, ctx: egui::Context, time: f64, + _language: Language, } impl App { fn new() -> Self { + let language = Language::english(); let mut app = VectorcraftApp::new(Session::new(), Services::default()); app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); app.run("shape.rectangle", json!({"x": 200, "y": 150, "width": 20, "height": 20})).unwrap(); @@ -68,7 +92,7 @@ impl App { let ctx = egui::Context::default(); ctx.enable_accesskit(); embed::install(&ctx, craft::ui::testing::install_spec(), &vectorcraft_ui_egui::ui_fonts()).unwrap(); - let mut a = Self { app, ctx, time: 0.0 }; + let mut a = Self { app, ctx, time: 0.0, _language: language }; a.settle(); a }