From cc5f14193c25200e254e64cc594b15e84da280f9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 16 Jan 2021 15:28:03 +0100 Subject: [PATCH] =?UTF-8?q?Flip=20test=20directory=20structure=20?= =?UTF-8?q?=F0=9F=94=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move full/lang/library to the top-level as that's more ergonomic to use. --- .gitignore | 8 +++---- bench/src/bench.rs | 2 +- tests/README.md | 22 +++++++++--------- tests/{ref/full => full/ref}/coma.png | Bin tests/{typ/full => full/typ}/coma.typ | 0 tests/{ref/lang => lang/ref}/arrays.png | Bin tests/{ref/lang => lang/ref}/basics.png | Bin tests/{ref/lang => lang/ref}/blocks.png | Bin tests/{ref/lang => lang/ref}/bracket-call.png | Bin tests/{ref/lang => lang/ref}/comments.png | Bin tests/{ref/lang => lang/ref}/dictionaries.png | Bin tests/{ref/lang => lang/ref}/empty.png | Bin tests/{ref/lang => lang/ref}/escaping.png | Bin tests/{ref/lang => lang/ref}/expressions.png | Bin tests/{ref/lang => lang/ref}/headings.png | Bin tests/{ref/lang => lang/ref}/let.png | Bin tests/{ref/lang => lang/ref}/raw.png | Bin tests/{ref/lang => lang/ref}/values.png | Bin tests/{typ/lang => lang/typ}/arrays.typ | 0 tests/{typ/lang => lang/typ}/basics.typ | 0 tests/{typ/lang => lang/typ}/blocks.typ | 0 tests/{typ/lang => lang/typ}/bracket-call.typ | 0 tests/{typ/lang => lang/typ}/comments.typ | 0 tests/{typ/lang => lang/typ}/dictionaries.typ | 0 tests/{typ/lang => lang/typ}/empty.typ | 0 tests/{typ/lang => lang/typ}/escaping.typ | 0 tests/{typ/lang => lang/typ}/expressions.typ | 0 tests/{typ/lang => lang/typ}/headings.typ | 0 tests/{typ/lang => lang/typ}/let.typ | 0 tests/{typ/lang => lang/typ}/raw.typ | 0 tests/{typ/lang => lang/typ}/values.typ | 0 tests/{ref/library => library/ref}/font.png | Bin tests/{ref/library => library/ref}/hv.png | Bin tests/{ref/library => library/ref}/image.png | Bin tests/{ref/library => library/ref}/page.png | Bin .../library => library/ref}/pagebreak.png | Bin tests/{ref/library => library/ref}/rgb.png | Bin tests/{typ/library => library/typ}/font.typ | 0 tests/{typ/library => library/typ}/hv.typ | 0 tests/{typ/library => library/typ}/image.typ | 0 tests/{typ/library => library/typ}/page.typ | 0 .../library => library/typ}/pagebreak.typ | 0 tests/{typ/library => library/typ}/rgb.typ | 0 tests/typeset.rs | 17 +++++++++----- 44 files changed, 26 insertions(+), 23 deletions(-) rename tests/{ref/full => full/ref}/coma.png (100%) rename tests/{typ/full => full/typ}/coma.typ (100%) rename tests/{ref/lang => lang/ref}/arrays.png (100%) rename tests/{ref/lang => lang/ref}/basics.png (100%) rename tests/{ref/lang => lang/ref}/blocks.png (100%) rename tests/{ref/lang => lang/ref}/bracket-call.png (100%) rename tests/{ref/lang => lang/ref}/comments.png (100%) rename tests/{ref/lang => lang/ref}/dictionaries.png (100%) rename tests/{ref/lang => lang/ref}/empty.png (100%) rename tests/{ref/lang => lang/ref}/escaping.png (100%) rename tests/{ref/lang => lang/ref}/expressions.png (100%) rename tests/{ref/lang => lang/ref}/headings.png (100%) rename tests/{ref/lang => lang/ref}/let.png (100%) rename tests/{ref/lang => lang/ref}/raw.png (100%) rename tests/{ref/lang => lang/ref}/values.png (100%) rename tests/{typ/lang => lang/typ}/arrays.typ (100%) rename tests/{typ/lang => lang/typ}/basics.typ (100%) rename tests/{typ/lang => lang/typ}/blocks.typ (100%) rename tests/{typ/lang => lang/typ}/bracket-call.typ (100%) rename tests/{typ/lang => lang/typ}/comments.typ (100%) rename tests/{typ/lang => lang/typ}/dictionaries.typ (100%) rename tests/{typ/lang => lang/typ}/empty.typ (100%) rename tests/{typ/lang => lang/typ}/escaping.typ (100%) rename tests/{typ/lang => lang/typ}/expressions.typ (100%) rename tests/{typ/lang => lang/typ}/headings.typ (100%) rename tests/{typ/lang => lang/typ}/let.typ (100%) rename tests/{typ/lang => lang/typ}/raw.typ (100%) rename tests/{typ/lang => lang/typ}/values.typ (100%) rename tests/{ref/library => library/ref}/font.png (100%) rename tests/{ref/library => library/ref}/hv.png (100%) rename tests/{ref/library => library/ref}/image.png (100%) rename tests/{ref/library => library/ref}/page.png (100%) rename tests/{ref/library => library/ref}/pagebreak.png (100%) rename tests/{ref/library => library/ref}/rgb.png (100%) rename tests/{typ/library => library/typ}/font.typ (100%) rename tests/{typ/library => library/typ}/hv.typ (100%) rename tests/{typ/library => library/typ}/image.typ (100%) rename tests/{typ/library => library/typ}/page.typ (100%) rename tests/{typ/library => library/typ}/pagebreak.typ (100%) rename tests/{typ/library => library/typ}/rgb.typ (100%) 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); }