mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-07 12:13:20 +00:00
craft-font-catalog: run the Unix font-folder tests only on Unix (#621)
* craft-font-catalog: run the Unix font-folder tests only on Unix Five tests build an Os::Unix FontEnv from Unix paths (/home/me, <dir>/sys/fonts</dir>). Windows doesn't treat those paths as absolute, so the tests failed there. Production code is unaffected: on Windows FontEnv::from_process picks Os::Windows, whose folders never go through the Unix path logic. FontEnv's docs now say its paths follow the host's path rules. The font-store workflow, which already triggers on crates/font-catalog, now also runs craft-font-catalog's clippy and tests on Linux and Windows. Refs #619 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * craft-font-catalog: keep the store override and no-store tests on Windows These assertions don't depend on Unix path rules, so they now sit in their own ungated test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * craft-font-catalog: verify store override precedence Exercise the override with platform defaults present on every OS variant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,8 @@ jobs:
|
||||
- run: cargo fmt --check
|
||||
- run: cargo clippy -p craft-font-store --all-targets --locked -- -D warnings
|
||||
- run: cargo test -p craft-font-store --locked
|
||||
- run: cargo clippy -p craft-font-catalog --all-targets --locked -- -D warnings
|
||||
- run: cargo test -p craft-font-catalog --locked
|
||||
- name: Check the web build
|
||||
if: runner.os == 'Linux'
|
||||
run: cargo check -p craft-font-store --target wasm32-unknown-unknown --locked
|
||||
|
||||
@@ -38,6 +38,9 @@ impl Os {
|
||||
}
|
||||
|
||||
/// The environment the font folders depend on.
|
||||
///
|
||||
/// Its paths are read with the host's path rules, so it describes a system of the host's family:
|
||||
/// on Windows, `/usr/share` isn't absolute and an [`Os::Unix`] environment's folders come out wrong.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct FontEnv {
|
||||
/// Which platform's folders to list.
|
||||
|
||||
@@ -211,7 +211,8 @@ fn decode_entities(s: &str) -> String {
|
||||
s.replace("<", "<").replace(">", ">").replace(""", "\"").replace("'", "'").replace("&", "&")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
// Uses Unix paths, which Windows doesn't treat as absolute (#619).
|
||||
#[cfg(all(test, unix))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -145,6 +145,8 @@ fn linux_env(root: &Path) -> FontEnv {
|
||||
}
|
||||
}
|
||||
|
||||
// Uses Unix paths, which Windows doesn't treat as absolute (#619).
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn linux_font_dirs_cover_xdg_flatpak_and_fontconfig() {
|
||||
let root = temp("dirs");
|
||||
@@ -167,6 +169,8 @@ fn linux_font_dirs_cover_xdg_flatpak_and_fontconfig() {
|
||||
assert_eq!(dirs, want);
|
||||
}
|
||||
|
||||
// Uses Unix paths, which Windows doesn't treat as absolute (#619).
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn fontconfig_dirs_follow_includes_prefixes_and_skip_the_rest() {
|
||||
let root = temp("conf");
|
||||
@@ -210,6 +214,8 @@ fn fontconfig_dirs_follow_includes_prefixes_and_skip_the_rest() {
|
||||
);
|
||||
}
|
||||
|
||||
// Uses Unix paths, which Windows doesn't treat as absolute (#619).
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn flatpak_adds_the_hosts_font_folders() {
|
||||
let root = temp("flatpak");
|
||||
@@ -249,15 +255,26 @@ fn macos_and_windows_folders() {
|
||||
assert_eq!(office_font_dirs(&env).len(), 1);
|
||||
}
|
||||
|
||||
// Uses Unix paths, which Windows doesn't treat as absolute (#619).
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn font_store_folder() {
|
||||
let env = FontEnv { os: Os::Unix, home: Some("/home/me".into()), ..Default::default() };
|
||||
assert_eq!(font_store_dir(&env), Some(PathBuf::from("/home/me/.local/share/craft-fonts")));
|
||||
let env = FontEnv { xdg_data_home: Some("/data".into()), ..env };
|
||||
assert_eq!(font_store_dir(&env), Some(PathBuf::from("/data/craft-fonts")));
|
||||
let env = FontEnv { font_store: Some("/portable/fonts".into()), ..env };
|
||||
assert_eq!(font_store_dir(&env), Some(PathBuf::from("/portable/fonts")));
|
||||
assert_eq!(font_store_dir(&FontEnv { os: Os::None, home: Some("/h".into()), ..Default::default() }), None);
|
||||
}
|
||||
|
||||
/// The store override wins with or without platform defaults; unsupported platforms have no default store.
|
||||
#[test]
|
||||
fn font_store_override_and_no_store() {
|
||||
for os in [Os::Unix, Os::MacOs, Os::Windows, Os::Haiku, Os::None] {
|
||||
let env = FontEnv { os, font_store: Some("portable/fonts".into()), ..Default::default() };
|
||||
assert_eq!(font_store_dir(&env), Some(PathBuf::from("portable/fonts")));
|
||||
let env = FontEnv { home: Some("home".into()), local_app_data: Some("local".into()), ..env };
|
||||
assert_eq!(font_store_dir(&env), Some(PathBuf::from("portable/fonts")));
|
||||
}
|
||||
assert_eq!(font_store_dir(&FontEnv { os: Os::None, home: Some("h".into()), ..Default::default() }), None);
|
||||
}
|
||||
|
||||
/// A Linux system with fonts in a system folder, the Flatpak host folder, the user's folder and
|
||||
|
||||
Reference in New Issue
Block a user