typg-cli 5.0.19

CLI for typg (made by FontLab https://www.fontlab.com/)
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/// Integration tests for the typg CLI.
///
/// Tests cover the find command and cache subcommands, verifying font discovery
/// by script, name, and feature filters.
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;

use serde_json::Value;
use tempfile::tempdir;

/// Locate the test fonts directory relative to the workspace root.
///
/// First checks the `TYPF_TEST_FONTS` environment variable, then tries
/// known relative paths. Returns `None` if no directory is found, which
/// causes the calling test to skip.
fn fonts_dir() -> Option<PathBuf> {
    if let Ok(env_override) = env::var("TYPF_TEST_FONTS") {
        let path = PathBuf::from(env_override);
        if let Ok(dir) = path.canonicalize() {
            return Some(dir);
        }
    }

    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let candidates = [
        manifest_dir
            .join("..")
            .join("..")
            .join("typf")
            .join("test-fonts"),
        manifest_dir
            .join("..")
            .join("linked")
            .join("typf")
            .join("test-fonts"),
        manifest_dir.join("..").join("..").join("test-fonts"),
    ];

    for candidate in candidates {
        if let Ok(dir) = candidate.canonicalize() {
            return Some(dir);
        }
    }

    None
}

/// Verify that `find --scripts arab` returns exactly one font (NotoNaskhArabic-Regular.ttf).
#[test]
fn find_scripts_arab_outputs_expected_font() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "arab"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(
        output.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    let lines: Vec<&str> = stdout.lines().collect();
    assert_eq!(lines.len(), 1, "stdout:\n{}", stdout);
    assert!(lines[0].ends_with("NotoNaskhArabic-Regular.ttf"));
}

/// Verify that `find --scripts latn --count` outputs a single integer.
#[test]
fn find_count_outputs_number() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "latn", "--count"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(
        output.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    let count: usize = stdout.trim().parse().expect("count should be a number");
    assert!(count > 0, "should find at least one Latin font");
}

/// Verify that `find --variable --json --jobs 1` returns JSON including Kalnia.
#[test]
fn find_variable_json_respects_jobs_flag() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--variable", "--json", "--jobs", "1"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(
        output.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8(output.stdout).expect("utf8 stdout");
    let parsed: Value = serde_json::from_str(&stdout).expect("parse json output");
    let arr = parsed.as_array().expect("find --json returns a JSON array");
    assert!(!arr.is_empty(), "expected at least one match");

    let paths: Vec<&str> = arr
        .iter()
        .filter_map(|entry| entry["source"]["path"].as_str())
        .collect();

    assert!(
        paths.iter().any(|p| p.ends_with("Kalnia[wdth,wght].ttf")),
        "variable search should include Kalnia"
    );
}

/// Verify that `find --paths` output contains no ANSI escape codes even when `--color always` is set.
#[test]
fn find_paths_output_is_ansi_free_even_with_color_always() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "latn", "--paths", "--color", "always"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(
        output.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.lines().count() > 0, "expected some paths in output");
    assert!(
        !stdout.contains("\u{1b}["),
        "paths output should not include ANSI codes even when color is forced"
    );
}

/// Verify that `find --name "Noto Sans" --json` matches the font's internal name table.
#[test]
fn find_name_regex_matches_family_name() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--name", "Noto Sans", "--json"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(
        output.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let stdout = String::from_utf8(output.stdout).expect("utf8 stdout");
    let parsed: Value = serde_json::from_str(&stdout).expect("parse json output");
    let arr = parsed.as_array().expect("find --json returns array");
    assert!(
        arr.iter().any(|entry| entry["source"]["path"]
            .as_str()
            .map(|p| p.ends_with("NotoSans-Regular.ttf"))
            .unwrap_or(false)),
        "name regex should match family name from the name table"
    );
}

/// Exercise the full cache lifecycle: add fonts, list, find by script, remove one file, then clean.
#[test]
fn cache_add_find_and_clean_cycle() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let cache_path = tmp.path().join("cache.json");
    let mirror = tmp.path().join("fonts");
    fs::create_dir_all(&mirror).expect("mirror dir");

    for entry in fs::read_dir(&fonts).expect("read fixtures") {
        let entry = entry.expect("dir entry");
        let path = entry.path();
        if path.is_file() {
            let dest = mirror.join(path.file_name().expect("filename"));
            fs::copy(&path, &dest).expect("copy font fixture");
        }
    }

    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--cache-path"])
        .arg(&cache_path)
        .arg(&mirror)
        .output()
        .expect("run cache add");
    assert!(
        add.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&add.stderr)
    );
    assert!(cache_path.exists(), "cache file should be created");

    let list = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "list", "--cache-path"])
        .arg(&cache_path)
        .arg("--json")
        .output()
        .expect("run cache list");
    assert!(
        list.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&list.stderr)
    );
    let listed: Value = serde_json::from_slice(&list.stdout).expect("parse list json");
    let initial_len = listed.as_array().map(|a| a.len()).unwrap_or(0);
    assert!(initial_len > 0, "cache should contain entries");

    let find = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "find", "--cache-path"])
        .arg(&cache_path)
        .args(["--scripts", "latn", "--json"])
        .output()
        .expect("run cache find");
    assert!(
        find.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&find.stderr)
    );
    let found: Value = serde_json::from_slice(&find.stdout).expect("parse find json");
    let arr = found.as_array().expect("find returns array");
    assert!(
        arr.iter().any(|entry| entry["source"]["path"]
            .as_str()
            .map(|p| p.ends_with("NotoSans-Regular.ttf"))
            .unwrap_or(false)),
        "cached find should include NotoSans-Regular.ttf"
    );

    // Remove one font and ensure clean drops it.
    let removed = mirror.join("NotoSans-Regular.ttf");
    fs::remove_file(&removed).expect("remove a cached font");

    let clean = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "clean", "--cache-path"])
        .arg(&cache_path)
        .output()
        .expect("run cache clean");
    assert!(
        clean.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&clean.stderr)
    );

    let list_after = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "list", "--cache-path"])
        .arg(&cache_path)
        .arg("--json")
        .output()
        .expect("run cache list after clean");
    let listed_after: Value =
        serde_json::from_slice(&list_after.stdout).expect("parse list json after clean");
    let after_len = listed_after.as_array().map(|a| a.len()).unwrap_or(0);
    assert!(
        after_len < initial_len,
        "clean should prune missing entries ({} -> {})",
        initial_len,
        after_len
    );
}

/// Verify that `cache find --scripts latn --count` outputs a single integer.
#[test]
fn cache_find_count_outputs_number() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let cache_path = tmp.path().join("cache.json");

    // First add some fonts.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--cache-path"])
        .arg(&cache_path)
        .arg(&fonts)
        .output()
        .expect("run cache add");
    assert!(add.status.success());

    // Find with --count flag.
    let find = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "find", "--cache-path"])
        .arg(&cache_path)
        .args(["--scripts", "latn", "--count"])
        .output()
        .expect("run cache find --count");

    assert!(
        find.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&find.stderr)
    );

    let stdout = String::from_utf8_lossy(&find.stdout);
    let count: usize = stdout.trim().parse().expect("count should be a number");
    assert!(count > 0, "should find at least one Latin font");
}

/// Verify `cache info` outputs correct statistics including entry count and storage type.
#[test]
fn cache_info_shows_stats() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let cache_path = tmp.path().join("cache.json");

    // First add some fonts.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--cache-path"])
        .arg(&cache_path)
        .arg(&fonts)
        .output()
        .expect("run cache add");
    assert!(add.status.success());

    // Then check info.
    let info = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "info", "--cache-path"])
        .arg(&cache_path)
        .arg("--json")
        .output()
        .expect("run cache info");

    assert!(
        info.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&info.stderr)
    );

    let parsed: Value = serde_json::from_slice(&info.stdout).expect("parse info json");
    assert!(parsed["exists"].as_bool().unwrap_or(false));
    assert!(parsed["entries"].as_u64().unwrap_or(0) > 0);
    assert_eq!(parsed["type"].as_str(), Some("json"));
}

/// Verify that `--quiet cache add` suppresses the progress message on stderr while still creating the cache.
#[test]
fn cache_add_quiet_suppresses_stderr() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let cache_path = tmp.path().join("cache.json");

    // Add with --quiet flag - should suppress stderr.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["--quiet", "cache", "add", "--cache-path"])
        .arg(&cache_path)
        .arg(&fonts)
        .output()
        .expect("run cache add --quiet");

    assert!(
        add.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&add.stderr)
    );

    let stderr = String::from_utf8_lossy(&add.stderr);
    assert!(
        stderr.is_empty() || !stderr.contains("cached"),
        "quiet mode should suppress 'cached X font faces' message"
    );
    assert!(cache_path.exists(), "cache file should still be created");
}

/// Verify that `cache info --index` reports LMDB stats correctly (requires hpindex feature).
#[test]
#[cfg(feature = "hpindex")]
fn cache_info_index_shows_lmdb_stats() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let index_path = tmp.path().join("index");

    // First add some fonts to index.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--index", "--index-path"])
        .arg(&index_path)
        .arg(&fonts)
        .output()
        .expect("run cache add --index");
    assert!(add.status.success());

    // Check info with --index flag.
    let info = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "info", "--index", "--index-path"])
        .arg(&index_path)
        .arg("--json")
        .output()
        .expect("run cache info --index");

    assert!(
        info.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&info.stderr)
    );

    let parsed: Value = serde_json::from_slice(&info.stdout).expect("parse info json");
    assert!(parsed["exists"].as_bool().unwrap_or(false));
    assert!(parsed["entries"].as_u64().unwrap_or(0) > 0);
    assert_eq!(parsed["type"].as_str(), Some("lmdb"));
}

/// Exercise the full LMDB index lifecycle: add, list, find by script, and filter for variable fonts (requires hpindex feature).
#[test]
#[cfg(feature = "hpindex")]
fn index_add_find_and_list_cycle() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let index_path = tmp.path().join("index");

    // Add fonts to the index.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--index", "--index-path"])
        .arg(&index_path)
        .arg(&fonts)
        .output()
        .expect("run cache add --index");
    assert!(
        add.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&add.stderr)
    );
    assert!(index_path.exists(), "index directory should be created");

    // List fonts from the index.
    let list = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "list", "--index", "--index-path"])
        .arg(&index_path)
        .arg("--json")
        .output()
        .expect("run cache list --index");
    assert!(
        list.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&list.stderr)
    );
    let listed: Value = serde_json::from_slice(&list.stdout).expect("parse list json");
    let arr = listed.as_array().expect("list returns array");
    assert!(!arr.is_empty(), "index should contain entries");

    // Find fonts with feature filter.
    let find = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "find", "--index", "--index-path"])
        .arg(&index_path)
        .args(["--scripts", "latn", "--json"])
        .output()
        .expect("run cache find --index");
    assert!(
        find.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&find.stderr)
    );
    let found: Value = serde_json::from_slice(&find.stdout).expect("parse find json");
    let arr = found.as_array().expect("find returns array");
    assert!(
        arr.iter().any(|entry| entry["source"]["path"]
            .as_str()
            .map(|p| p.ends_with("NotoSans-Regular.ttf"))
            .unwrap_or(false)),
        "indexed find should include NotoSans-Regular.ttf"
    );

    // Find variable fonts only.
    let find_var = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "find", "--index", "--index-path"])
        .arg(&index_path)
        .args(["--variable", "--json"])
        .output()
        .expect("run cache find --index --variable");
    assert!(
        find_var.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&find_var.stderr)
    );
    let found_var: Value = serde_json::from_slice(&find_var.stdout).expect("parse find json");
    let arr = found_var.as_array().expect("find returns array");
    assert!(
        arr.iter().any(|entry| entry["source"]["path"]
            .as_str()
            .map(|p| p.ends_with("Kalnia[wdth,wght].ttf"))
            .unwrap_or(false)),
        "indexed find --variable should include Kalnia"
    );
}

/// Verify that `find --details 0` returns only paths as a json array or plain text.
#[test]
fn find_details_preset_0() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    // JSON format with -d 0: should return a JSON array of strings
    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "arab", "-d", "0", "--json"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(output.status.success());
    let stdout = String::from_utf8(output.stdout).expect("utf8 stdout");
    let parsed: Value = serde_json::from_str(&stdout).expect("parse json");
    let arr = parsed
        .as_array()
        .expect("preset 0 json should be array of paths");
    assert_eq!(arr.len(), 1);
    assert!(arr[0]
        .as_str()
        .unwrap()
        .ends_with("NotoNaskhArabic-Regular.ttf"));

    // Plain format with -d 0: should return just the path
    let output_plain = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "arab", "-d", "0"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(output_plain.status.success());
    let stdout_plain = String::from_utf8_lossy(&output_plain.stdout);
    assert!(stdout_plain.trim().ends_with("NotoNaskhArabic-Regular.ttf"));
    // Since -d 0 was requested, plain output should just contain the path (no family/style suffix).
    assert!(!stdout_plain.contains(" - "));
}

/// Verify custom property lists.
#[test]
fn find_custom_details_json() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args([
            "find",
            "--scripts",
            "arab",
            "-d",
            "fname,fmt,psname",
            "--json",
        ])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(output.status.success());
    let stdout = String::from_utf8(output.stdout).expect("utf8 stdout");
    let parsed: Value = serde_json::from_str(&stdout).expect("parse json");
    let arr = parsed.as_array().expect("json should be array of objects");
    assert_eq!(arr.len(), 1);
    let obj = arr[0].as_object().expect("each item is an object");
    assert_eq!(obj.len(), 3);
    assert!(obj.contains_key("fname"));
    assert!(obj.contains_key("fmt"));
    assert!(obj.contains_key("psname"));
    assert_eq!(obj["fmt"].as_str(), Some("ttf"));
}

/// Verify CSV output format.
#[test]
fn find_csv_output() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let output = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["find", "--scripts", "arab", "--csv"])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    let lines: Vec<&str> = stdout.lines().collect();
    assert!(lines.len() >= 2);
    // Header should be: path,fname,sname,fmt,var,wt,wd
    assert!(lines[0].starts_with("path,fname,sname,fmt,var,wt,wd"));
    assert!(lines[1].contains("NotoNaskhArabic-Regular.ttf"));

    // Test with custom details in CSV
    let output_custom = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args([
            "find",
            "--scripts",
            "arab",
            "-d",
            "fname,psname,fmt",
            "--csv",
        ])
        .arg(&fonts)
        .output()
        .expect("run typg");

    assert!(output_custom.status.success());
    let stdout_custom = String::from_utf8_lossy(&output_custom.stdout);
    let lines_custom: Vec<&str> = stdout_custom.lines().collect();
    assert_eq!(lines_custom[0], "fname,psname,fmt");
    assert!(lines_custom[1].contains("ttf"));
}

/// Verify that cache search commands also support --details and --csv.
#[test]
fn cache_find_details_and_csv() {
    let fonts = match fonts_dir() {
        Some(dir) => dir,
        None => return, // skip when fixtures are unavailable
    };

    let tmp = tempdir().expect("tempdir");
    let cache_path = tmp.path().join("cache.json");

    // Add fonts.
    let add = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "add", "--cache-path"])
        .arg(&cache_path)
        .arg(&fonts)
        .output()
        .expect("run cache add");
    assert!(add.status.success());

    // Cache find with CSV and details.
    let find = Command::new(env!("CARGO_BIN_EXE_typg"))
        .args(["cache", "find", "--cache-path"])
        .arg(&cache_path)
        .args(["--scripts", "arab", "-d", "fname,fmt", "--csv"])
        .output()
        .expect("run cache find");

    assert!(find.status.success());
    let stdout = String::from_utf8_lossy(&find.stdout);
    let lines: Vec<&str> = stdout.lines().collect();
    assert_eq!(lines[0], "fname,fmt");
    assert!(lines[1].contains("Noto Naskh Arabic"));
    assert!(lines[1].contains("ttf"));
}