diff --git a/.gitignore b/.gitignore index f60c09f7d..8e251b30a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,8 @@ bench/target **/*.rs.bk Cargo.lock -tests/png -tests/pdf -tests/playground.typ -tests/playground.png -tests/playground.pdf +tests/*/png +tests/*/pdf +tests/playground.* tarpaulin-report.html diff --git a/bench/src/bench.rs b/bench/src/bench.rs index e1ae838ad..2d3230db8 100644 --- a/bench/src/bench.rs +++ b/bench/src/bench.rs @@ -11,7 +11,7 @@ use typst::parse::parse; use typst::typeset; const FONT_DIR: &str = "../fonts"; -const COMA: &str = include_str!("../../tests/typ/full/coma.typ"); +const COMA: &str = include_str!("../../tests/full/typ/coma.typ"); fn benchmarks(c: &mut Criterion) { macro_rules! bench { diff --git a/tests/README.md b/tests/README.md index 91bf8f49e..efca6dd6c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,23 +1,23 @@ # Tests -Directory structure: -- `typ`: Input files. -- `ref`: Reference images which the output is compared with to determine whether - a test passed or failed. -- `res`: Resource files used by tests. -- `png`: PNG files produced by tests. -- `pdf`: PDF files produced by tests. - -The test files are split into three categories: +Top level directory structure: - `full`: Tests of full documents. - `lang`: Tests for specific language features. - `library`: Tests for specific library functions. +- `res`: Resource files used by tests. + +Directory structure for each category: +- `typ`: Input files. +- `ref`: Reference images which the output is compared with to determine whether + a test passed or failed. +- `png`: PNG files produced by tests. +- `pdf`: PDF files produced by tests. To keep things small, please optimize the reference images: ```bash # One image -oxipng -o max tests/ref/image.png +oxipng -o max path/to/image.png # All images -oxipng -r -o max tests/ref/* +oxipng -r -o max tests/*/ref ``` diff --git a/tests/ref/full/coma.png b/tests/full/ref/coma.png similarity index 100% rename from tests/ref/full/coma.png rename to tests/full/ref/coma.png diff --git a/tests/typ/full/coma.typ b/tests/full/typ/coma.typ similarity index 100% rename from tests/typ/full/coma.typ rename to tests/full/typ/coma.typ diff --git a/tests/ref/lang/arrays.png b/tests/lang/ref/arrays.png similarity index 100% rename from tests/ref/lang/arrays.png rename to tests/lang/ref/arrays.png diff --git a/tests/ref/lang/basics.png b/tests/lang/ref/basics.png similarity index 100% rename from tests/ref/lang/basics.png rename to tests/lang/ref/basics.png diff --git a/tests/ref/lang/blocks.png b/tests/lang/ref/blocks.png similarity index 100% rename from tests/ref/lang/blocks.png rename to tests/lang/ref/blocks.png diff --git a/tests/ref/lang/bracket-call.png b/tests/lang/ref/bracket-call.png similarity index 100% rename from tests/ref/lang/bracket-call.png rename to tests/lang/ref/bracket-call.png diff --git a/tests/ref/lang/comments.png b/tests/lang/ref/comments.png similarity index 100% rename from tests/ref/lang/comments.png rename to tests/lang/ref/comments.png diff --git a/tests/ref/lang/dictionaries.png b/tests/lang/ref/dictionaries.png similarity index 100% rename from tests/ref/lang/dictionaries.png rename to tests/lang/ref/dictionaries.png diff --git a/tests/ref/lang/empty.png b/tests/lang/ref/empty.png similarity index 100% rename from tests/ref/lang/empty.png rename to tests/lang/ref/empty.png diff --git a/tests/ref/lang/escaping.png b/tests/lang/ref/escaping.png similarity index 100% rename from tests/ref/lang/escaping.png rename to tests/lang/ref/escaping.png diff --git a/tests/ref/lang/expressions.png b/tests/lang/ref/expressions.png similarity index 100% rename from tests/ref/lang/expressions.png rename to tests/lang/ref/expressions.png diff --git a/tests/ref/lang/headings.png b/tests/lang/ref/headings.png similarity index 100% rename from tests/ref/lang/headings.png rename to tests/lang/ref/headings.png diff --git a/tests/ref/lang/let.png b/tests/lang/ref/let.png similarity index 100% rename from tests/ref/lang/let.png rename to tests/lang/ref/let.png diff --git a/tests/ref/lang/raw.png b/tests/lang/ref/raw.png similarity index 100% rename from tests/ref/lang/raw.png rename to tests/lang/ref/raw.png diff --git a/tests/ref/lang/values.png b/tests/lang/ref/values.png similarity index 100% rename from tests/ref/lang/values.png rename to tests/lang/ref/values.png diff --git a/tests/typ/lang/arrays.typ b/tests/lang/typ/arrays.typ similarity index 100% rename from tests/typ/lang/arrays.typ rename to tests/lang/typ/arrays.typ diff --git a/tests/typ/lang/basics.typ b/tests/lang/typ/basics.typ similarity index 100% rename from tests/typ/lang/basics.typ rename to tests/lang/typ/basics.typ diff --git a/tests/typ/lang/blocks.typ b/tests/lang/typ/blocks.typ similarity index 100% rename from tests/typ/lang/blocks.typ rename to tests/lang/typ/blocks.typ diff --git a/tests/typ/lang/bracket-call.typ b/tests/lang/typ/bracket-call.typ similarity index 100% rename from tests/typ/lang/bracket-call.typ rename to tests/lang/typ/bracket-call.typ diff --git a/tests/typ/lang/comments.typ b/tests/lang/typ/comments.typ similarity index 100% rename from tests/typ/lang/comments.typ rename to tests/lang/typ/comments.typ diff --git a/tests/typ/lang/dictionaries.typ b/tests/lang/typ/dictionaries.typ similarity index 100% rename from tests/typ/lang/dictionaries.typ rename to tests/lang/typ/dictionaries.typ diff --git a/tests/typ/lang/empty.typ b/tests/lang/typ/empty.typ similarity index 100% rename from tests/typ/lang/empty.typ rename to tests/lang/typ/empty.typ diff --git a/tests/typ/lang/escaping.typ b/tests/lang/typ/escaping.typ similarity index 100% rename from tests/typ/lang/escaping.typ rename to tests/lang/typ/escaping.typ diff --git a/tests/typ/lang/expressions.typ b/tests/lang/typ/expressions.typ similarity index 100% rename from tests/typ/lang/expressions.typ rename to tests/lang/typ/expressions.typ diff --git a/tests/typ/lang/headings.typ b/tests/lang/typ/headings.typ similarity index 100% rename from tests/typ/lang/headings.typ rename to tests/lang/typ/headings.typ diff --git a/tests/typ/lang/let.typ b/tests/lang/typ/let.typ similarity index 100% rename from tests/typ/lang/let.typ rename to tests/lang/typ/let.typ diff --git a/tests/typ/lang/raw.typ b/tests/lang/typ/raw.typ similarity index 100% rename from tests/typ/lang/raw.typ rename to tests/lang/typ/raw.typ diff --git a/tests/typ/lang/values.typ b/tests/lang/typ/values.typ similarity index 100% rename from tests/typ/lang/values.typ rename to tests/lang/typ/values.typ diff --git a/tests/ref/library/font.png b/tests/library/ref/font.png similarity index 100% rename from tests/ref/library/font.png rename to tests/library/ref/font.png diff --git a/tests/ref/library/hv.png b/tests/library/ref/hv.png similarity index 100% rename from tests/ref/library/hv.png rename to tests/library/ref/hv.png diff --git a/tests/ref/library/image.png b/tests/library/ref/image.png similarity index 100% rename from tests/ref/library/image.png rename to tests/library/ref/image.png diff --git a/tests/ref/library/page.png b/tests/library/ref/page.png similarity index 100% rename from tests/ref/library/page.png rename to tests/library/ref/page.png diff --git a/tests/ref/library/pagebreak.png b/tests/library/ref/pagebreak.png similarity index 100% rename from tests/ref/library/pagebreak.png rename to tests/library/ref/pagebreak.png diff --git a/tests/ref/library/rgb.png b/tests/library/ref/rgb.png similarity index 100% rename from tests/ref/library/rgb.png rename to tests/library/ref/rgb.png diff --git a/tests/typ/library/font.typ b/tests/library/typ/font.typ similarity index 100% rename from tests/typ/library/font.typ rename to tests/library/typ/font.typ diff --git a/tests/typ/library/hv.typ b/tests/library/typ/hv.typ similarity index 100% rename from tests/typ/library/hv.typ rename to tests/library/typ/hv.typ diff --git a/tests/typ/library/image.typ b/tests/library/typ/image.typ similarity index 100% rename from tests/typ/library/image.typ rename to tests/library/typ/image.typ diff --git a/tests/typ/library/page.typ b/tests/library/typ/page.typ similarity index 100% rename from tests/typ/library/page.typ rename to tests/library/typ/page.typ diff --git a/tests/typ/library/pagebreak.typ b/tests/library/typ/pagebreak.typ similarity index 100% rename from tests/typ/library/pagebreak.typ rename to tests/library/typ/pagebreak.typ diff --git a/tests/typ/library/rgb.typ b/tests/library/typ/rgb.typ similarity index 100% rename from tests/typ/library/rgb.typ rename to tests/library/typ/rgb.typ diff --git a/tests/typeset.rs b/tests/typeset.rs index 5777950f8..10e6231e1 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -38,14 +38,18 @@ fn main() { let filter = TestFilter::new(env::args().skip(1)); let mut filtered = Vec::new(); - for entry in WalkDir::new(TYP_DIR).into_iter() { + for entry in WalkDir::new(".").into_iter() { let entry = entry.unwrap(); + if entry.depth() <= 1 { + continue; + } + let src_path = entry.into_path(); if src_path.extension() != Some(OsStr::new("typ")) { continue; } - if filter.matches(&src_path.to_string_lossy().to_string()) { + if filter.matches(&src_path.to_string_lossy()) { filtered.push(src_path); } } @@ -78,10 +82,11 @@ fn main() { let mut ok = true; for src_path in filtered { - let relative = src_path.strip_prefix(TYP_DIR).unwrap(); - let png_path = Path::new(PNG_DIR).join(&relative).with_extension("png"); - let pdf_path = Path::new(PDF_DIR).join(&relative).with_extension("pdf"); - let ref_path = Path::new(REF_DIR).join(&relative).with_extension("png"); + let category = src_path.parent().unwrap().parent().unwrap(); + let name = src_path.file_stem().unwrap(); + let png_path = category.join(PNG_DIR).join(name).with_extension("png"); + let pdf_path = category.join(PDF_DIR).join(name).with_extension("pdf"); + let ref_path = category.join(REF_DIR).join(name).with_extension("png"); ok &= test(&src_path, &png_path, &pdf_path, Some(&ref_path), &mut env); }