Merge pull request #10374 from dotCooCoo/fix/swallowed-regression-guards

Tests: guards check the environment, not the output under test
This commit is contained in:
.CooCoo
2026-12-01 14:10:23 -08:00
committed by GitHub
10 changed files with 75 additions and 50 deletions
+1 -2
View File
@@ -654,8 +654,7 @@ mod tests {
let held = rss_mb();
drop(buffer);
let (Some((held, _)), Some((now, peak))) = (held, rss_mb()) else {
eprintln!("no memory reading (Linux without `ps`): nothing to check");
return;
panic!("rss_mb gave no memory reading");
};
assert!(peak.is_some_and(|peak| peak > held - 16.0), "holding 64 MB: {held:.1} MB, after freeing it: {now:.1} MB, peak {peak:?}");
}
+16 -4
View File
@@ -1035,10 +1035,11 @@ fn a_baked_group_with_type_keeps_a_shadow_on_each_copy() {
use vectorcraft_doc::text::{CharStyle, TextObject};
let style = CharStyle { size: 40.0, fill: Paint::solid(Color::BLACK), ..Default::default() };
let words = Node::new(NodeId(161), vectorcraft_doc::NodeKind::Text(Box::new(TextObject::point(Point::new(5.0, 60.0), "IIII", style))));
if !crate::outline_text(&words).is_some_and(|o| paths_in(&o) > 0) {
if !fonts() {
eprintln!("skipped: built without fonts (enable vectorcraft-text's bundled-fonts to run it)");
return;
}
assert!(crate::outline_text(&words).is_some_and(|o| paths_in(&o) > 0), "the type outlines to paths");
let g = group(160, vec![words, square(162, vec![])], vec![shadow(10.0, 0.0, 0.0), transform(json!({"moveH": 150, "copies": 1}))]);
let b = baked(g);
assert!(near(&shadows_in(&b), &[(10.0, 0.0), (10.0, 0.0)]), "{:?}", shadows_in(&b));
@@ -1640,6 +1641,17 @@ fn type_node(id: u64, effects: Vec<Effect>) -> Node {
n
}
/// Whether the face of the default character style is installed, so that type lays out glyphs.
/// When it is, `type_node`'s type must outline to paths.
fn fonts() -> bool {
let style = vectorcraft_doc::text::CharStyle::default();
if vectorcraft_text::FontDb::global().face(&style.font_family, &style.font_style).is_none() {
return false;
}
assert!(crate::outline_text(&type_node(95, vec![])).is_some_and(|o| paths_in(&o) > 0), "{}: the type outlines to paths", style.font_family);
true
}
/// An instance at (50, 50) with `effects` of a symbol, and the symbol's art: a black 20 pt square
/// centered on its origin.
fn instance(id: u64, effects: Vec<Effect>) -> (Node, Node) {
@@ -1660,7 +1672,7 @@ fn instance(id: u64, effects: Vec<Effect>) -> (Node, Node) {
/// image and the instance are checked.
#[test]
fn each_copy_of_type_an_image_or_a_symbol_instance_carries_the_shadow_listed_before_it() {
let fonts = crate::outline_text(&type_node(95, vec![])).is_some_and(|o| paths_in(&o) > 0);
let fonts = fonts();
if !fonts {
eprintln!("type skipped: built without fonts (enable vectorcraft-text's bundled-fonts to run it)");
}
@@ -1702,7 +1714,7 @@ fn each_copy_of_type_an_image_or_a_symbol_instance_carries_the_shadow_listed_bef
/// listed before that effect, as the canvas draws it, rather than staying type under one shadow.
#[test]
fn baked_type_whose_transform_moves_its_copies_keeps_a_shadow_on_each() {
if !crate::outline_text(&type_node(99, vec![])).is_some_and(|o| paths_in(&o) > 0) {
if !fonts() {
eprintln!("skipped: built without fonts (enable vectorcraft-text's bundled-fonts to run it)");
return;
}
@@ -1738,7 +1750,7 @@ fn type_carries_its_fills_shadow_on_each_copy() {
n
};
let copying = vec![shadow(10.0, 0.0, 0.0), transform(json!({"moveH": 100, "copies": 1}))];
if !crate::outline_text(&type_node(95, vec![])).is_some_and(|o| paths_in(&o) > 0) {
if !fonts() {
eprintln!("type skipped: built without fonts (enable vectorcraft-text's bundled-fonts to run it)");
return;
}
+4 -2
View File
@@ -445,11 +445,13 @@ fn each_copys_shadow_on_type_expands_as_the_canvas_draws_it() {
let shadow = json!({"x": 20, "y": 0, "blur": 0, "opacity": 100, "mode": "normal", "color": "#00ff00"});
run(&mut s, "effect.apply", json!({"effect": "stylize.dropShadow", "params": shadow}));
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "params": {"scaleH": 200, "scaleV": 200, "moveV": 80, "copies": 1}}));
let before = render(&s);
if !(0..100u32).any(|y| (0..200u32).any(|x| before.pixel(x, y) == [255, 0, 0, 255])) {
let style = vectorcraft_doc::text::CharStyle::default();
if vectorcraft_text::FontDb::global().face(&style.font_family, &style.font_style).is_none() {
eprintln!("skipped: built without a font that draws the type");
return;
}
let before = render(&s);
assert!((0..100u32).any(|y| (0..200u32).any(|x| before.pixel(x, y) == [255, 0, 0, 255])), "the type draws in red");
// The rightmost red pixel of the copy, below the type, and 38 pt right of it the copy's shadow.
let red =
(100..200u32).flat_map(|y| (0..200u32).map(move |x| (x, y))).filter(|&(x, y)| before.pixel(x, y) == [255, 0, 0, 255]).max_by_key(|p| p.0);
+5 -9
View File
@@ -68,20 +68,16 @@ problem;
#[test]
fn json2_polyfill_round_trips_with_the_built_in_json() {
let mut realm = Realm::new();
match realm.run(NEEDS) {
Ok(JsValue::Bool(true)) => {}
other => panic!("json2: the interpreter lacks Date, String.prototype.replace or RegExp, which json2.js uses: {other:?}"),
}
let Some(path) = json2_file() else {
println!("json2: SKIPPED (no json2.js; run cargo xtask test262)");
return;
};
let source = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
let mut realm = Realm::new();
match realm.run(NEEDS) {
Ok(JsValue::Bool(true)) => {}
Ok(JsValue::Bool(false)) => {
println!("json2: SKIPPED (the interpreter lacks Date, String.prototype.replace or RegExp, which json2.js uses)");
return;
}
other => panic!("json2: the built-in check failed: {other:?}"),
}
match realm.run(&format!("{BEFORE}\n{source}\n{ROUND_TRIP}")) {
Ok(JsValue::String(s)) if s == "ok" => println!("json2: the polyfill and the built-in JSON agree on every sample"),
other => panic!("json2: {other:?}"),
+3 -3
View File
@@ -503,13 +503,13 @@ fn arabic_ligatures_keep_their_letters_in_order() {
let t = TextObject::point(kurbo::Point::ORIGIN, "لا", style);
vectorcraft_text::layout(db, &t).glyphs.len() == 1
};
// An installed Arabic font with a lam-alef ligature whose glyphs come back as live type.
// An installed Arabic font with a lam-alef ligature. The test checks that its type comes
// back, so the choice of font does not depend on the import.
let Some(face) = preferred
.iter()
.chain(&db.families())
.filter_map(|f| db.face(f, "Regular"))
.filter(|f| f.covers('\u{0644}') && f.covers('\u{0627}') && ligates(f))
.find(|f| !imported_texts(f, "بب").is_empty())
.find(|f| f.covers('\u{0644}') && f.covers('\u{0627}') && ligates(f))
else {
return; // No such font on this host.
};
+7 -11
View File
@@ -202,8 +202,7 @@ fn line_break_hyphens_of_right_to_left_lines_are_written_as_text_where_the_canva
/// The kashidas of justified Arabic type (Insert Kashidas), which stand for no character either,
/// are drawn as paths: reopened, the type holds its letters and no hyphen or tatweel. Skipped
/// without an OpenType font that covers Arabic and the tatweel, when the layout adds no kashida,
/// or when PDF text import returns no strings on this platform.
/// without an OpenType font that covers Arabic and the tatweel.
#[test]
fn kashidas_are_not_written_as_hyphens() {
let db = FontDb::global();
@@ -221,20 +220,17 @@ fn kashidas_are_not_written_as_hyphens() {
t.para.justify = vectorcraft_doc::Justify::JustifyAll;
t.para.kashida = vectorcraft_doc::text::Kashida::Medium;
let tatweel = face.glyph_for('\u{0640}');
if !vectorcraft_text::layout(db, &t).glyphs.iter().any(|g| g.len == 0 && g.gid == tatweel) {
return;
}
assert!(
vectorcraft_text::layout(db, &t).glyphs.iter().any(|g| g.len == 0 && g.gid == tatweel),
"{}: justified layout inserts a kashida",
face.family
);
let back = texts(&import_as(&pdf(&doc(vec![t]), false).bytes, TextAs::Text));
if back.is_empty() {
return;
}
assert!(!back.is_empty(), "{}: the PDF's type comes back", face.family);
assert!(!back.concat().contains(['-', '\u{2010}', '\u{0640}']), "{back:?}");
// Every letter comes back, at least as often as the text holds it (the justified words may
// come back as type objects of their own).
let all = back.concat();
if all.is_empty() {
return;
}
let count = |s: &str, c: char| s.chars().filter(|&x| x == c).count();
for c in text.chars().filter(|c| c.is_alphabetic()) {
assert!(count(&all, c) >= count(text, c), "{c}: {back:?}");
+4 -4
View File
@@ -228,11 +228,10 @@ fn narrow_arabic_area_wrap_keeps_base_and_mark_together_when_supported() {
let levels = bidi.as_ref().map_or(&[][..], |info| &info.levels);
let mut shaped = Vec::new();
shape_range(db, text, 0..text.len(), &[(0..text.len(), &style)], &[], &OtFeatures::default(), levels, &mut shaped);
let Some(first) = shaped.first() else { return };
let first = shaped.first().expect("the text shapes to glyphs");
let first_end = shaped.iter().take_while(|g| g.byte == first.byte).count();
if first.byte != 0 || first_end < 2 || first_end >= shaped.len() {
return;
}
assert_eq!(first.byte, 0, "{}: the first cluster starts the text: {shaped:?}", face.family);
assert!(first_end >= 2 && first_end < shaped.len(), "{}: the base and its mark are one cluster of two glyphs: {shaped:?}", face.family);
// Pick a narrow width that fits glyphs before one positive-advance glyph but not that next
// glyph. This ensures the old per-glyph loop would have returned inside the first cluster.
let mut prefix = shaped.first().map_or(0.0, |g| g.adv);
@@ -245,6 +244,7 @@ fn narrow_arabic_area_wrap_keeps_base_and_mark_together_when_supported() {
None
}
});
// A face whose mark has no advance gives no width that splits the cluster.
let Some(width) = width else { return };
let mut object = TextObject::point(Point::ZERO, text, style);
+1 -12
View File
@@ -183,12 +183,7 @@ fn type_arrows_keep_devanagari_clusters_across_wrapped_lines() {
let split_width: f64 = hindi_glyphs.iter().filter(|g| g.byte == split).map(|g| g.advance).sum();
assert!(prefix_width.is_finite() && prefix_width > 0.0, "setup: prefix has positive finite advance");
assert!(split_width.is_finite(), "setup: the internal raw-group advance is finite");
if split_width <= 0.0 {
eprintln!(
"SKIPPED: type_arrows_keep_devanagari_clusters_across_wrapped_lines; layout capability: the selected face has no positive-advance raw group at internal byte {split}"
);
return;
}
assert!(split_width > 0.0, "setup: {} lays out a positive-advance raw group at internal byte {split}", face.family);
let width = prefix_width + split_width * 0.5;
assert!(width.is_finite() && width > prefix_width && width < prefix_width + split_width, "setup: one measured width separates the raw groups");
@@ -205,12 +200,6 @@ fn type_arrows_keep_devanagari_clusters_across_wrapped_lines() {
assert_eq!(edit::prev_cluster(text, hindi.len()), second, "setup: logical cluster start is 6");
assert_eq!(edit::prev_cluster(text, split), second, "setup: raw line endpoint 12 is inside the grapheme");
assert_eq!(edit::next_cluster(text, split), hindi.len(), "setup: raw line endpoint 12 is not its end");
if lay.lines.len() < 2 || (lay.lines[0].start, lay.lines[0].end, lay.lines[1].start) != (0, split, split) {
eprintln!(
"SKIPPED: type_arrows_keep_devanagari_clusters_across_wrapped_lines; layout capability: the measured frame does not expose adjacent wrapped endpoints at internal byte {split}"
);
return;
}
assert!(lay.lines.len() >= 2, "setup: actual wrapping occurred");
assert_eq!(
(lay.lines[0].start, lay.lines[0].end, lay.lines[1].start),
+32 -1
View File
@@ -855,7 +855,38 @@ mod tests {
let mut app = selected_text();
let Some((st, _)) = text_style(&app) else { panic!("no text style") };
let sets = set_entries(&app, &st);
// Builds without the bundled fonts have no face that offers sets.
// With the bundled fonts, the text's face offers sets. Without them, an installed face may.
assert!(!cfg!(feature = "bundled-fonts") || !sets.is_empty(), "the bundled face of the text offers stylistic sets");
// The submenu lists the `ss01` to `ss20` sets that the text's face offers, read here from
// the face itself, so the test returns early only when the face offers none.
let db = FontDb::global();
let available = db.has_family(&db.canonical(&st.font_family, &st.font_style).0);
let face_sets = if available { db.style_face(&st).map(|face| face.stylistic_sets()).unwrap_or_default() } else { Vec::new() };
let expected: Vec<String> = face_sets.iter().filter(|set| (1..=20).contains(&set.number)).map(|set| format!("ss{:02}", set.number)).collect();
let listed: Vec<String> = sets.iter().map(|(_, flag, _)| flag.tag().unwrap_or_default().to_string()).collect();
assert_eq!(listed, expected, "the submenu lists the stylistic sets of the text's face");
let rows = menu_rows(&app);
if expected.is_empty() {
assert!(!rows.iter().any(|row| matches!(row, PanelRow::Submenu(..))), "the submenu is left out when the face offers no sets");
} else {
let submenu = rows.iter().find_map(|row| match row {
PanelRow::Submenu(_, sub) if (1..=20).any(|number| has_row(sub, &toggle_ref(&format!("ss{number:02}")))) => Some(sub),
_ => None,
});
let actual: Vec<&str> = submenu
.expect("the menu has a Stylistic Sets submenu")
.iter()
.filter_map(|row| match row {
PanelRow::Command(c) if c.id == TOGGLE => Some(c.params["tag"].as_str().expect("a toggle has a tag")),
_ => None,
})
.collect();
assert_eq!(actual, expected, "the submenu toggle tags match the face's sets in order");
}
for tag in &expected {
let r = toggle_ref(tag);
assert!(rows.iter().any(|row| matches!(row, PanelRow::Submenu(_, sub) if has_row(sub, &r))), "the submenu has a row for {tag}");
}
let Some((first, flag, _)) = sets.first() else { return };
let (label, tag) = (set_label(first), flag.tag().unwrap());
set(&mut app, OtFeatures { small_caps: true, ..Default::default() });
+2 -2
View File
@@ -214,7 +214,7 @@ mod tests {
#[test]
fn jobs_come_back_newest_last_per_slot() {
let Some(w) = ThumbWorker::<u8, u32>::start(&crate::testing::ui_context(), "test") else { return };
let w = ThumbWorker::<u8, u32>::start(&crate::testing::ui_context(), "test").expect("the worker thread starts");
let job = |n: u32| -> JobFn { Box::new(move |_| Some(Rendered { width: n, height: 1, pixels: vec![0; 4] })) };
for k in 1..=3 {
assert!(w.submit(0, k, job(k)));
@@ -238,7 +238,7 @@ mod tests {
#[test]
fn discarded_jobs_do_not_run_and_the_running_one_finishes() {
let Some(w) = ThumbWorker::<u8, u32>::start(&crate::testing::ui_context(), "test") else { return };
let w = ThumbWorker::<u8, u32>::start(&crate::testing::ui_context(), "test").expect("the worker thread starts");
let job = |n: u32| -> JobFn { Box::new(move |_| Some(Rendered { width: n, height: 1, pixels: vec![0; 4] })) };
// A job that holds the thread until it is let go, so the others queue behind it.
let (started, running) = channel::<()>();