Skip to content

Commit

Permalink
Merge pull request #681 from googlefonts/ttx-test-fixups
Browse files Browse the repository at this point in the history
[fea-rs] Fixups for ttx_test util
  • Loading branch information
rsheeter authored Jan 23, 2024
2 parents a426fe0 + 0343d56 commit 618ce67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
3 changes: 1 addition & 2 deletions fea-rs/src/bin/ttx_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions fea-rs/src/tests/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 22 additions & 8 deletions fea-rs/src/util/ttx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>, 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();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 618ce67

Please sign in to comment.