Skip to content

Commit

Permalink
Flip test directory structure 🔃
Browse files Browse the repository at this point in the history
Move full/lang/library to the top-level as that's more ergonomic to use.
  • Loading branch information
laurmaedje committed Jan 16, 2021
1 parent 51efb0f commit cc5f141
Show file tree
Hide file tree
Showing 44 changed files with 24 additions and 21 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bench/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Tests

Directory structure:
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.
- `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:
- `full`: Tests of full documents.
- `lang`: Tests for specific language features.
- `library`: Tests for specific library functions.

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
```
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 11 additions & 6 deletions tests/typeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit cc5f141

Please sign in to comment.