lichtung-plot 0.1.0

Strongly typed scientific plotting with deterministic SVG and PNG output
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
use super::super::admission::{ScanReason, TableState};
use super::*;

fn core(fonts: Vec<Vec<u8>>) -> CanonicalFontCore {
    CanonicalFontCore::from_generated(
        fonts,
        &HostGenericNames::default(),
        FontPreparation::new(),
        scalar_presence_map(),
    )
    .unwrap()
}

pub(super) fn tables(bytes: &[u8]) -> Vec<([u8; 4], Vec<u8>)> {
    let raw = ttf_parser::RawFace::parse(bytes, 0).unwrap();
    raw.table_records
        .into_iter()
        .map(|record| {
            (
                record.tag.0.to_be_bytes(),
                raw.table(record.tag).unwrap().to_vec(),
            )
        })
        .collect()
}

#[test]
fn family_without_id6_and_after_bad_record_is_admitted() {
    let mut data = tables(&build_test_font());
    let name = &mut data.iter_mut().find(|(tag, _)| tag == b"name").unwrap().1;
    // First record is out of bounds; ID16 is later and valid; ID6 is absent.
    set_u16(name, 6 + 10, u16::MAX);
    set_u16(name, 6 + 2 * 12 + 6, 2);
    let core = core(vec![build_sfnt(data)]);
    assert_eq!(core.faces().len(), 1);
    assert_eq!(core.faces()[0].names.len(), 1);
    assert_eq!(core.faces()[0].names[0].record_ordinal, 1);
    assert!(core
        .database
        .face(core.faces()[0].database_id)
        .unwrap()
        .post_script_name
        .is_empty());
    assert!(
        core.fonts.issues.is_empty(),
        "unknown record and absent optional ID6 are not scan issues"
    );
    let environment = PreparedFontEnvironment::for_core(core).unwrap();
    let pair = environment
        .resolve_pair(
            0,
            &named_stack(&["Test Sans"]),
            RequestedWeight::Normal,
            &['A'],
        )
        .unwrap();
    assert_eq!(pair.primary.face_index, 0);
    assert!(!environment
        .shape_run(
            pair.primary,
            "A",
            ShapingDirection::LeftToRight,
            rustybuzz::script::LATIN
        )
        .unwrap()
        .glyphs
        .is_empty());
}

#[test]
fn unrelated_bad_or_unsupported_names_do_not_add_scan_requirements() {
    let mut data = tables(&build_test_font());
    let name = &mut data.iter_mut().find(|(tag, _)| tag == b"name").unwrap().1;
    // Valid ID16 remains. A malformed Unicode copyright and a non-Unicode
    // FullName are neither matching keys nor the optional ID6 mirror.
    set_u16(name, 6 + 6, 0);
    set_u16(name, 42, 0xd800);
    set_u16(name, 6 + 2 * 12, 1); // Macintosh, not the supported Unicode encoding.
    set_u16(name, 6 + 2 * 12 + 2, 0);
    set_u16(name, 6 + 2 * 12 + 6, 4);
    let bytes = build_sfnt(data);
    let parsed = ttf_parser::Face::parse(&bytes, 0).unwrap();
    assert!(parsed.names().get(0).unwrap().to_string().is_none());
    assert!(!parsed.names().get(2).unwrap().is_unicode());
    let core = core(vec![bytes]);
    assert!(
        core.fonts.issues.is_empty(),
        "no diagnostics allocated for unconsumed names/defaults"
    );
    assert_eq!(core.faces()[0].names.len(), 1);
    assert_eq!(core.faces()[0].names[0].value, "Test Sans");
    assert_eq!(core.faces()[0].names[0].record_ordinal, 1);
    let mirror = core.database.face(core.faces()[0].database_id).unwrap();
    assert_eq!(mirror.families[0].0, "Test Sans");
    assert!(mirror.post_script_name.is_empty());
    let environment = PreparedFontEnvironment::for_core(core).unwrap();
    let pair = environment
        .resolve_pair(
            0,
            &named_stack(&["Test Sans"]),
            RequestedWeight::Normal,
            &['A'],
        )
        .unwrap();
    assert!(environment
        .shape_run(
            pair.primary,
            "A",
            ShapingDirection::LeftToRight,
            rustybuzz::script::LATIN
        )
        .unwrap()
        .glyphs[0]
        .ink
        .is_some());
}

#[test]
fn rejected_content_keeps_bytes_and_precise_classification() {
    let all = tables(&build_test_font());
    let name_only = all
        .iter()
        .filter(|(tag, _)| tag == b"name")
        .cloned()
        .collect();
    let mut apple = vec![
        (*b"bhed", vec![0; 54]),
        (*b"bdat", vec![0; 4]),
        (*b"bloc", vec![0; 4]),
    ];
    apple.extend(all.iter().filter(|(tag, _)| tag == b"name").cloned());
    let mut bad_head = all.clone();
    bad_head
        .iter_mut()
        .find(|(tag, _)| tag == b"head")
        .unwrap()
        .1
        .truncate(8);
    let mut empty = all;
    empty.retain(|(tag, _)| !matches!(tag, b"glyf" | b"loca"));
    let core = core(vec![
        build_test_font(),
        build_sfnt(name_only),
        build_sfnt(apple),
        build_sfnt(bad_head),
        build_sfnt(empty),
    ]);
    assert_eq!(core.files().len(), 5);
    assert_eq!(core.faces().len(), 2, "all-empty glyphs are not image-only");
    let parser_issues: Vec<_> = core
        .fonts
        .issues
        .iter()
        .filter(|issue| matches!(issue.reason, ScanReason::Parser { .. }))
        .collect();
    assert_eq!(parser_issues.len(), 3);
    for (issue, ordinal, apple_bitmap_tables, head) in [
        (parser_issues[0], 1, false, TableState::Absent),
        (parser_issues[1], 2, true, TableState::Absent),
        (parser_issues[2], 3, false, TableState::Readable),
    ] {
        assert_eq!(issue.file_ordinal, ordinal);
        assert_eq!(issue.face_index, Some(0));
        assert_eq!(
            issue.reason,
            ScanReason::Parser {
                error: ttf_parser::FaceParsingError::NoHeadTable,
                head,
                apple_bitmap_tables,
            }
        );
        assert_eq!(
            core.files()[ordinal].sha256,
            Sha256::digest(core.files()[ordinal].bytes.as_slice()).as_slice()
        );
    }
}

#[test]
fn collection_sibling_failure_preserves_original_index_and_truncated_count_is_bounded() {
    let sfnt = build_test_font();
    let mut collection = b"ttcf\0\x01\0\0\0\0\0\x02".to_vec();
    push_u32(&mut collection, u32::MAX);
    push_u32(&mut collection, 20);
    let mut shifted = sfnt.clone();
    for ordinal in 0..usize::from(u16::from_be_bytes([sfnt[4], sfnt[5]])) {
        let offset = 12 + ordinal * 16 + 8;
        let value = u32::from_be_bytes(sfnt[offset..offset + 4].try_into().unwrap());
        set_u32(&mut shifted, offset, value + 20);
    }
    collection.extend(shifted);
    let truncated = b"ttcf\0\x01\0\0\xff\xff\xff\xff".to_vec();
    let core = core(vec![collection, truncated]);
    assert_eq!(core.faces().len(), 1);
    assert_eq!(core.faces()[0].identity.face_index, 1);
    assert_eq!(
        core.database
            .face(core.faces()[0].database_id)
            .unwrap()
            .index,
        1
    );
    assert!(core
        .fonts
        .issues
        .iter()
        .any(|issue| issue.face_index == Some(0) && issue.file_ordinal == 0));
    assert!(
        core.fonts
            .issues
            .iter()
            .any(|issue| issue.face_index.is_none()
                && issue.reason == ScanReason::TruncatedCollection)
    );
    assert_eq!(
        core.fonts.faces.capacity(),
        1,
        "never reserve the untrusted TTC count"
    );
}

#[test]
fn admission_does_not_absorb_work_resource_or_internal_failures() {
    let mut storage = Vec::<FontScanIssue>::new();
    assert!(matches!(
        reserve_prepared_or_local(&mut storage, usize::MAX, "font scan diagnostics", None),
        Err(FontError::Allocation(_))
    ));
    assert!(matches!(
        CanonicalFontCore::from_generated(
            vec![vec![0; 16]],
            &HostGenericNames::default(),
            FontPreparation::new(),
            Vec::new(),
        ),
        Err(FontError::Arithmetic("Unicode scalar presence map"))
    ));
}

#[cfg(unix)]
#[test]
fn a_discovered_font_target_io_error_is_not_a_smaller_admitted_catalog() {
    let directory = tempfile::tempdir().unwrap();
    fs::write(directory.path().join("good.ttf"), build_test_font()).unwrap();
    std::os::unix::fs::symlink(
        directory.path().join("gone.ttf"),
        directory.path().join("broken.ttf"),
    )
    .unwrap();
    let roots = ordinal_roots(vec![directory.path().to_path_buf()], None).unwrap();
    assert!(matches!(
        discover_indexed_files(&roots, None),
        Err(FontError::Io { .. })
    ));
}

#[test]
fn image_only_declarations_and_optional_defaults_do_not_become_an_outline_sanitizer() {
    let mut image = tables(&build_test_font());
    image.retain(|(tag, _)| !matches!(tag, b"glyf" | b"loca"));
    // A declaration-only classification witness, not a claim of valid sbix data.
    image.push((*b"sbix", vec![0; 8]));
    let mut mixed = tables(&build_test_font());
    mixed.push((*b"sbix", vec![0; 8]));
    let mut optional = tables(&build_test_font());
    optional.retain(|(tag, _)| tag != b"OS/2");
    optional.push((*b"post", vec![0; 4]));
    let core = core(vec![
        build_sfnt(image),
        build_sfnt(mixed),
        build_sfnt(optional),
    ]);
    assert_eq!(
        core.faces().len(),
        2,
        "an optional paint parser None does not reject vectors"
    );
    assert_eq!(
        core.fonts.issues[0].reason,
        ScanReason::UnsupportedImageOnly
    );
    assert_eq!(core.fonts.issues[0].file_ordinal, 0);
    let optional = &core.faces()[1];
    assert_eq!(
        (optional.style, optional.stretch, optional.weight),
        (Style::Normal, Stretch::Normal, 400)
    );
    let mirror = core.database.face(optional.database_id).unwrap();
    assert!(
        !mirror.monospaced,
        "short post is not positive monospaced/italic evidence"
    );
    assert!(
        !core
            .fonts
            .issues
            .iter()
            .any(|issue| issue.file_ordinal == 2),
        "normal optional-field defaults are not invalid-font diagnostics"
    );
}

#[test]
fn required_table_ranges_and_absent_family_have_distinct_local_diagnostics() {
    let mut out_of_bounds = build_test_font();
    let directory = (12..12
        + usize::from(u16::from_be_bytes([out_of_bounds[4], out_of_bounds[5]])) * 16)
        .step_by(16)
        .find(|offset| &out_of_bounds[*offset..*offset + 4] == b"head")
        .unwrap();
    set_u32(&mut out_of_bounds, directory + 8, u32::MAX);
    let mut unaddressable = tables(&build_test_font());
    let names = &mut unaddressable
        .iter_mut()
        .find(|(tag, _)| tag == b"name")
        .unwrap()
        .1;
    set_u16(names, 6 + 6, 2);
    set_u16(names, 6 + 12 + 6, 2);
    let core = core(vec![
        out_of_bounds,
        build_sfnt(unaddressable),
        build_test_font(),
    ]);
    assert_eq!(core.faces().len(), 1);
    assert!(core.fonts.issues.iter().any(|issue| matches!(
        issue.reason,
        ScanReason::Parser {
            head: TableState::OutOfBounds,
            apple_bitmap_tables: false,
            ..
        }
    )));
    assert!(core
        .fonts
        .issues
        .iter()
        .any(|issue| issue.file_ordinal == 1 && issue.reason == ScanReason::MissingFamily));
}

#[test]
fn uninspectable_directories_and_rejected_lookups_are_not_absent_or_out_of_bounds() {
    let missing = build_sfnt(
        tables(&build_test_font())
            .into_iter()
            .filter(|(tag, _)| tag == b"name")
            .collect(),
    );
    let mut invalid_hhea = tables(&build_test_font());
    invalid_hhea
        .iter_mut()
        .find(|(tag, _)| tag == b"hhea")
        .unwrap()
        .1
        .truncate(8);
    let mut unsorted = build_sfnt(invalid_hhea);
    // Put the valid head record where binary search cannot find it. This is
    // adversarial generated input; admission must not reorder or repair it.
    unsorted[12..12 + 4 * 16].rotate_right(16);
    let raw = ttf_parser::RawFace::parse(&unsorted, 0).unwrap();
    assert!(raw.table(ttf_parser::Tag::from_bytes(b"head")).is_none());
    let head = raw
        .table_records
        .into_iter()
        .find(|record| record.tag == ttf_parser::Tag::from_bytes(b"head"))
        .unwrap();
    assert!(usize::try_from(head.offset + head.length).unwrap() <= unsorted.len());
    let originals = vec![missing, vec![0; 16], unsorted];
    let core = core(originals.clone());
    assert!(core.faces().is_empty());
    let observations: Vec<_> = core
        .fonts
        .issues
        .iter()
        .filter_map(|issue| {
            if let ScanReason::Parser { head, .. } = issue.reason {
                Some(head)
            } else {
                None
            }
        })
        .collect();
    assert_eq!(
        observations,
        [
            TableState::Absent,
            TableState::Uninspectable,
            TableState::LookupRejected
        ]
    );
    for (file, original) in core.files().iter().zip(&originals) {
        assert_eq!(file.bytes.as_slice(), original);
    }
}

#[test]
fn family_aliases_preserve_variant_matching_and_coverage_fallback() {
    let mut regular = tables(&build_test_font_with_coverage("Family", &['A']));
    let (_, names) = regular.iter_mut().find(|(tag, _)| tag == b"name").unwrap();
    // Regular advertises only the legacy (ID1) family, as in Arial Regular.
    set_u16(
        names,
        6 + 12 + 6,
        ttf_parser::name_id::TYPOGRAPHIC_SUBFAMILY,
    );
    let regular = build_sfnt(regular);
    let mut heavy = tables(&build_test_font_with_coverage("Family", &['A', 'B']));
    let (_, names) = heavy.iter_mut().find(|(tag, _)| tag == b"name").unwrap();
    // The first string belongs to ID1; ID16 still advertises the shared family.
    names[42..54].copy_from_slice(&utf16_be("Strong"));
    let (_, os2) = heavy.iter_mut().find(|(tag, _)| tag == b"OS/2").unwrap();
    set_u16(os2, 4, 900);
    let heavy = build_sfnt(heavy);
    let regular_id = FaceIdentity {
        sha256: Sha256::digest(&regular).into(),
        face_index: 0,
    };
    let heavy_id = FaceIdentity {
        sha256: Sha256::digest(&heavy).into(),
        face_index: 0,
    };
    let environment = PreparedFontEnvironment::for_core(core(vec![heavy, regular])).unwrap();

    let stack = named_stack(&["Family", "Strong", "Family"]);
    let pair = environment
        .resolve_pair(0, &stack, RequestedWeight::Normal, &['A', 'B'])
        .unwrap();
    assert_eq!(pair.primary, regular_id, "the ID1 match has exact weight");
    assert_eq!(pair.provenance.candidates, [regular_id, heavy_id]);
    assert_eq!(
        pair.selection_for_unit("A", 'A').unwrap(),
        ScalarFaceSelection::Face(regular_id)
    );
    assert_eq!(
        pair.selection_for_unit("B", 'B').unwrap(),
        ScalarFaceSelection::Face(heavy_id),
        "the ID16 match remains available for missing coverage"
    );

    let explicit = named_stack(&["Strong", "Family"]);
    let pair = environment
        .resolve_pair(1, &explicit, RequestedWeight::Normal, &['A'])
        .unwrap();
    assert_eq!(
        pair.primary, heavy_id,
        "an earlier named stack entry still wins"
    );
    assert_eq!(pair.provenance.candidates, [heavy_id, regular_id]);
}

#[test]
fn admission_order_is_not_candidate_order_and_failures_retain_context() {
    let one = build_test_font_with_coverage("Same", &['A']);
    let two = build_test_font_with_coverage("Same", &['A', 'B']);
    let rejected = build_sfnt(
        tables(&one)
            .into_iter()
            .filter(|(tag, _)| tag == b"name")
            .collect(),
    );
    let stack = named_stack(&["Same"]);
    let mut orders = Vec::new();
    for fonts in [
        vec![one.clone(), rejected.clone(), two.clone()],
        vec![two, one, rejected],
    ] {
        let environment = PreparedFontEnvironment::for_core(core(fonts)).unwrap();
        environment
            .admit_text(&stack, RequestedWeight::Normal, "A", None)
            .unwrap();
        orders.push(
            environment
                .prepared_pair(&stack, RequestedWeight::Normal)
                .unwrap()
                .unwrap()
                .provenance
                .candidates,
        );
        let error = environment
            .admit_text(
                &named_stack(&["Not installed"]),
                RequestedWeight::Normal,
                "A",
                None,
            )
            .unwrap_err();
        assert!(matches!(error, FontError::Admission { .. }));
        let message = error.to_string();
        for expected in [
            "Not installed",
            "generated-font.ttf",
            "sha256",
            "NoHeadTable",
            "index=Some(0)",
        ] {
            assert!(message.contains(expected), "{message}");
        }
    }
    assert_eq!(orders[0], orders[1]);
}

// Run real host discovery in child processes: never mutate process-global font
// configuration in the parallel test harness. Only Linux has this fontconfig path.
#[cfg(target_os = "linux")]
#[test]
#[expect(
    clippy::too_many_lines,
    reason = "one child-process witness keeps discovery, two operations and post-deletion replay together"
)]
fn linux_public_api_ignores_unrelated_name_only_and_freezes_output() {
    const CHILD: &str = "LICHTUNG_FONT_ADMISSION_CHILD";
    const FAMILY: &str = "Generated Canvas Sans";
    const TITLE: &str = "Font admission";
    const BODY: &str = "Actual Canvas text";
    if let Some(output) = std::env::var_os(CHILD) {
        let output = PathBuf::from(output);
        let canvas = || {
            crate::Canvas::grid(1, 1)
                .unwrap()
                .text_panel(0, 0, crate::TextPanel::new(TITLE, BODY).unwrap())
                .unwrap()
                .size(640, 320)
        };
        let normal_bytes =
            usize::try_from(fs::metadata(output.join("fonts/normal.ttf")).unwrap().len()).unwrap();
        let matched_bytes = fs::metadata(output.join("fonts/matched.ttf"))
            .map_or(0, |metadata| usize::try_from(metadata.len()).unwrap());
        super::loading::reset_observations();
        let first = canvas().svg(output.join("first.svg")).unwrap();
        let once = super::loading::observations();
        assert_eq!(once.full_bytes, normal_bytes + matched_bytes);
        assert_eq!(once.hash_bytes, once.full_bytes);
        assert_eq!(once.materialized.len(), 1 + usize::from(matched_bytes > 0));
        assert_eq!(once.face_checks.len(), once.materialized.len());
        assert_eq!(once.frozen_files, once.materialized);
        assert!(once.materialized.iter().all(|(path, _)| {
            matches!(
                path.file_name().unwrap().to_str(),
                Some("normal.ttf" | "matched.ttf")
            )
        }));
        if output.join("fonts/unrelated.ttf").exists() {
            let unrelated = fs::canonicalize(output.join("fonts/unrelated.ttf")).unwrap();
            assert!(once.metadata_bytes[&unrelated] < 1024);
        }
        // A second new Canvas operation in this SAME process must index and
        // materialize again. This is not Output replay or a process-global cache.
        let frozen = canvas()
            .svg_preserve_text(output.join("preserved.svg"))
            .unwrap();
        let twice = super::loading::observations();
        super::loading::assert_two_operations(&once, &twice);
        super::loading::print_observations(output.file_name().unwrap().to_str().unwrap(), &once);
        // This Output has not outlined yet. Its first outlining and PNG must
        // still work after source deletion; cached SVG paths cannot mask a reread.
        fs::remove_file(output.join("fonts/normal.ttf")).unwrap();
        if matched_bytes > 0 {
            fs::write(
                output.join("fonts/matched.ttf"),
                b"changed after materialization",
            )
            .unwrap();
        }
        frozen
            .svg(output.join("replay.svg"))
            .unwrap()
            .png(output.join("scene.png"))
            .unwrap();
        assert_eq!(
            fs::read(output.join("first.svg")).unwrap(),
            fs::read(output.join("replay.svg")).unwrap()
        );
        first.svg(output.join("again.svg")).unwrap();
        assert_eq!(super::loading::observations(), twice);
        let svg = fs::read_to_string(output.join("first.svg")).unwrap();
        assert!(
            svg.contains("<path") && !svg.contains("<text"),
            "actual generated glyphs paint paths"
        );
        assert!(fs::metadata(output.join("scene.png")).unwrap().len() > 100);
        return;
    }
    let mut coverage: Vec<_> = TITLE.chars().chain(BODY.chars()).chain(['0']).collect();
    coverage.sort_unstable();
    coverage.dedup();
    // The extra '0' is the actual TextPanel intrinsic ch-width probe.
    let normal = build_test_font_with_coverage(FAMILY, &coverage);
    let directory = tempfile::tempdir().unwrap();
    for mode in ["normal", "mixed", "matched"] {
        let output = directory.path().join(mode);
        fs::create_dir_all(output.join("fonts")).unwrap();
        fs::write(output.join("fonts/normal.ttf"), &normal).unwrap();
        if mode == "mixed" {
            let unrelated = super::loading::name_only("Unused", 2 * 1024 * 1024);
            assert!(matches!(
                ttf_parser::Face::parse(&unrelated, 0),
                Err(ttf_parser::FaceParsingError::NoHeadTable)
            ));
            fs::write(output.join("fonts/unrelated.ttf"), unrelated).unwrap();
            fs::write(output.join("fonts/unaddressable.ttf"), [0; 16]).unwrap();
        } else if mode == "matched" {
            fs::write(
                output.join("fonts/matched.ttf"),
                super::loading::name_only(FAMILY, 0),
            )
            .unwrap();
        }
        let config = output.join("fonts.conf");
        fs::write(&config, format!("<fontconfig><dir>{}</dir><alias><family>sans-serif</family><prefer><family>{FAMILY}</family></prefer></alias><alias><family>serif</family><prefer><family>{FAMILY}</family></prefer></alias><alias><family>monospace</family><prefer><family>{FAMILY}</family></prefer></alias></fontconfig>", output.join("fonts").display())).unwrap();
        let status = std::process::Command::new(std::env::current_exe().unwrap())
            .args(["--exact", "font::canonical::tests::admission::linux_public_api_ignores_unrelated_name_only_and_freezes_output", "--nocapture"])
            .env(CHILD, &output).env("FONTCONFIG_FILE", config).status().unwrap();
        assert!(status.success(), "mode={mode}");
    }
    assert_eq!(
        fs::read(directory.path().join("normal/first.svg")).unwrap(),
        fs::read(directory.path().join("mixed/first.svg")).unwrap()
    );
    assert_eq!(
        fs::read(directory.path().join("normal/first.svg")).unwrap(),
        fs::read(directory.path().join("matched/first.svg")).unwrap()
    );
}