mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 14:06:09 +00:00
tests: Type tool layout counts no longer race tests that add fonts
The tests that count the layouts the Type tool keeps read vectorcraft_text::layout_inputs() through its cache key. Tests in the same binary that add a font or change the hyphenation exceptions bump it, so a count running beside one saw every frame laid out again (type_overlays_keep_at_most_frame_layouts_max: 2051 instead of 2). Counting tests now hold a shared test-only lock for reading and tests that change those inputs hold it for writing.
This commit is contained in:
@@ -674,6 +674,19 @@ pub(crate) mod testutil {
|
||||
global_edit: &[],
|
||||
}
|
||||
}
|
||||
|
||||
/// Held for reading by tests that count the layouts the Type tool keeps, and for writing by
|
||||
/// tests that change what layout reads (fonts, hyphenation exceptions): tests run in parallel,
|
||||
/// and a count must not include a refresh another test caused.
|
||||
static LAYOUT_INPUTS: std::sync::RwLock<()> = std::sync::RwLock::new(());
|
||||
|
||||
pub fn steady_layout_inputs() -> std::sync::RwLockReadGuard<'static, ()> {
|
||||
LAYOUT_INPUTS.read().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
pub fn changing_layout_inputs() -> std::sync::RwLockWriteGuard<'static, ()> {
|
||||
LAYOUT_INPUTS.write().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1327,6 +1327,7 @@ fn area_type_drag_measure_labels_honor_preference() {
|
||||
|
||||
#[test]
|
||||
fn layout_cache_follows_fonts_added_later() {
|
||||
let _inputs = crate::testutil::changing_layout_inputs();
|
||||
// Other tests can load system fonts; this assertion needs its own process-wide database.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if std::env::var("VECTORCRAFT_FONT_CACHE_TEST_CHILD").as_deref() != Ok("1") {
|
||||
@@ -1542,6 +1543,7 @@ fn selected_type_shows_its_ports_in_each_state() {
|
||||
/// Preferences › Hyphenation › Exceptions change, the selected type is laid out again.
|
||||
#[test]
|
||||
fn the_out_port_follows_the_hyphenation_exceptions() {
|
||||
let _inputs = crate::testutil::changing_layout_inputs();
|
||||
struct Clear;
|
||||
impl Drop for Clear {
|
||||
fn drop(&mut self) {
|
||||
@@ -1690,6 +1692,7 @@ const OVERFLOWS: &str = "This text is far too long to fit in a frame of one hund
|
||||
/// overlays as a tool that lays every frame out afresh.
|
||||
#[test]
|
||||
fn type_overlays_keep_the_selected_frames_layouts() {
|
||||
let _inputs = crate::testutil::steady_layout_inputs();
|
||||
let (d, ids) = area_frames(&["One", "Two words", "Three words here", OVERFLOWS]);
|
||||
let (mut sel, p) = (Selection::default(), paint());
|
||||
sel.set(ids.iter().copied());
|
||||
@@ -1721,6 +1724,7 @@ fn type_overlays_keep_the_selected_frames_layouts() {
|
||||
/// out again on the next frame.
|
||||
#[test]
|
||||
fn type_overlays_keep_a_selected_storys_layouts() {
|
||||
let _inputs = crate::testutil::steady_layout_inputs();
|
||||
let (mut d, ids) = area_frames(&["Story one ", "story two ", "story three ", "story four"]);
|
||||
d.text_threads.push(ids.clone());
|
||||
let (mut sel, p) = (Selection::default(), paint());
|
||||
@@ -1749,6 +1753,7 @@ fn type_overlays_keep_a_selected_storys_layouts() {
|
||||
/// longer drawn is dropped, and choosing another tool drops them all.
|
||||
#[test]
|
||||
fn type_overlays_lay_out_again_only_the_frames_that_changed() {
|
||||
let _inputs = crate::testutil::steady_layout_inputs();
|
||||
let (mut d, ids) = area_frames(&["One", "Two", "Three", OVERFLOWS]);
|
||||
let (mut sel, p) = (Selection::default(), paint());
|
||||
sel.set(ids.iter().copied());
|
||||
@@ -1786,6 +1791,7 @@ fn type_overlays_lay_out_again_only_the_frames_that_changed() {
|
||||
/// each call, and draws what laying every frame out afresh draws.
|
||||
#[test]
|
||||
fn type_overlays_keep_at_most_frame_layouts_max() {
|
||||
let _inputs = crate::testutil::steady_layout_inputs();
|
||||
let texts = vec!["a "; FRAME_LAYOUTS_MAX + 3];
|
||||
let (mut d, ids) = area_frames(&texts);
|
||||
d.text_threads.push(ids.clone());
|
||||
@@ -1806,6 +1812,7 @@ fn type_overlays_keep_at_most_frame_layouts_max() {
|
||||
|
||||
#[test]
|
||||
fn frame_layouts_follow_fonts_and_hyphenation_exceptions() {
|
||||
let _inputs = crate::testutil::changing_layout_inputs();
|
||||
// Other tests can load system fonts; this assertion needs its own process-wide database.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if std::env::var("VECTORCRAFT_FONT_CACHE_TEST_CHILD").as_deref() != Ok("1") {
|
||||
@@ -1848,6 +1855,7 @@ fn frame_layouts_follow_fonts_and_hyphenation_exceptions() {
|
||||
#[test]
|
||||
#[ignore = "timing, run by hand"]
|
||||
fn type_overlays_timing() {
|
||||
let _inputs = crate::testutil::steady_layout_inputs();
|
||||
use std::time::Instant;
|
||||
let words = "The quick brown fox jumps over the lazy dog while seven wizards box. ".repeat(6);
|
||||
let texts: Vec<String> = (0..200).map(|i| format!("{i} {words}")).collect();
|
||||
|
||||
@@ -470,6 +470,7 @@ fn the_tool_is_made_by_its_id() {
|
||||
|
||||
#[test]
|
||||
fn touch_type_rtl_middle_character_can_drag_and_nudge_along_its_line() {
|
||||
let _inputs = crate::testutil::changing_layout_inputs();
|
||||
use vectorcraft_text::test_fonts::{RIGHT_TO_LEFT_OPTICAL_FAMILY, right_to_left_optical_font};
|
||||
|
||||
// The process-wide database deduplicates the same synthetic face across tests.
|
||||
|
||||
Reference in New Issue
Block a user