From 0343d56f85517214e5fcf6f83b47c501d4a4fb23 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Tue, 23 Jan 2024 14:44:46 -0500 Subject: [PATCH] [fea-rs] Fixups for ttx_test util This utility had broken a bit during the move from the old fea-rs repo into this new repo; in particular it would fail if you ran it from the `fea-rs` directory, which is annoying. We will now attempt to figure out where we're running from when determining the path to the test data, instead of hardcoding paths. --- fea-rs/src/bin/ttx_test.rs | 3 +-- fea-rs/src/tests/compile.rs | 3 +-- fea-rs/src/util/ttx.rs | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/fea-rs/src/bin/ttx_test.rs b/fea-rs/src/bin/ttx_test.rs index 4ea6c49f2..0af22b37f 100644 --- a/fea-rs/src/bin/ttx_test.rs +++ b/fea-rs/src/bin/ttx_test.rs @@ -6,14 +6,13 @@ use std::path::{Path, PathBuf}; use clap::Parser; use fea_rs::util::ttx; -static TEST_DATA: &str = "./fea-rs/test-data/fonttools-tests"; static WIP_DIFF_DIR: &str = "./wip"; fn main() { env_logger::init(); let args = Args::parse(); - let results = ttx::run_all_tests(TEST_DATA, args.test_filter.as_ref()); + let results = ttx::run_fonttools_tests(args.test_filter.as_ref()); if let Some(to_compare) = args .compare diff --git a/fea-rs/src/tests/compile.rs b/fea-rs/src/tests/compile.rs index e1c44bf7c..b91ecef8d 100644 --- a/fea-rs/src/tests/compile.rs +++ b/fea-rs/src/tests/compile.rs @@ -13,14 +13,13 @@ static GOOD_DIR: &str = "good"; static BAD_DIR: &str = "bad"; static GLYPH_ORDER: &str = "glyph_order.txt"; static BAD_OUTPUT_EXTENSION: &str = "ERR"; -static FONTTOOLS_TESTS: &str = "./test-data/fonttools-tests"; static IMPORT_RESOLUTION_TEST: &str = "./test-data/include-resolution-tests/dir1/test1.fea"; // tests taken directly from fonttools; these require some special handling. #[test] fn fonttools_tests() -> Result<(), Report> { test_utils::assert_has_ttx_executable(); - test_utils::run_all_tests(FONTTOOLS_TESTS, None).into_error() + test_utils::run_fonttools_tests(None).into_error() } #[test] diff --git a/fea-rs/src/util/ttx.rs b/fea-rs/src/util/ttx.rs index 84bb792d7..718e59960 100644 --- a/fea-rs/src/util/ttx.rs +++ b/fea-rs/src/util/ttx.rs @@ -146,7 +146,8 @@ impl<'a> Filter<'a> { /// /// `filter` is an optional comma-separated list of strings. If present, only /// tests which contain one of the strings in the list will be run. -pub fn run_all_tests(fonttools_data_dir: impl AsRef, filter: Option<&String>) -> Report { +pub fn run_fonttools_tests(filter: Option<&String>) -> Report { + let fonttools_data_dir = test_data_dir().join("fonttools-tests"); let glyph_map = fonttools_test_glyph_order(); let filter = Filter::new(filter); let var_info = make_var_info(); @@ -504,25 +505,38 @@ pub fn plain_text_diff(left: &str, right: &str) -> String { result } -/// Generate the sample glyph map. +/// return the path to the test-data directory. /// -/// This is the glyph map used in the feaLib test suite. -pub(crate) fn fonttools_test_glyph_order() -> GlyphMap { +/// This figures out if we're running from the crate root or the project root. +fn test_data_dir() -> PathBuf { let cwd = std::env::current_dir().expect("could not retrieve current directory"); // hack: during testing cwd is the crate root, but when running a binary // it may be the project root let path = if cwd.ends_with("fea-rs") { assert!(!cwd.parent().expect("always presnt").ends_with("fea-rs")); - "./test-data/simple_glyph_order.txt" + "./test-data" } else { - "./fea-rs/test-data/simple_glyph_order.txt" + "./fea-rs/test-data" }; - if !Path::new(path).exists() { + let path = Path::new(path); + if !path.exists() { panic!( - "could not locate glyph order file (cwd '{}', path '{path}' )", + "could not locate fea-rs test-data. Please run from crate or project root. (cwd '{}')", cwd.display() ); } + path.to_owned() +} + +/// Generate the sample glyph map. +/// +/// This is the glyph map used in the feaLib test suite. +pub(crate) fn fonttools_test_glyph_order() -> GlyphMap { + let mut path = test_data_dir(); + path.push("simple_glyph_order.txt"); + if !path.exists() { + panic!("could not locate glyph map at {}", path.display()); + } let order_str = std::fs::read_to_string(path).unwrap(); crate::compile::parse_glyph_order(&order_str) .unwrap()