Reorganize tests 🔀
4
.gitignore
vendored
@ -6,8 +6,8 @@ bench/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
|
||||
tests/*/png
|
||||
tests/*/pdf
|
||||
tests/png
|
||||
tests/pdf
|
||||
tests/playground.*
|
||||
|
||||
tarpaulin-report.html
|
||||
|
@ -12,7 +12,7 @@ use typst::parse::parse;
|
||||
use typst::typeset;
|
||||
|
||||
const FONT_DIR: &str = "../fonts";
|
||||
const COMA: &str = include_str!("../../tests/full/typ/coma.typ");
|
||||
const COMA: &str = include_str!("../../tests/typ/full/coma.typ");
|
||||
|
||||
fn benchmarks(c: &mut Criterion) {
|
||||
macro_rules! bench {
|
||||
|
@ -1,5 +1,14 @@
|
||||
# Tests
|
||||
|
||||
## Directory structure
|
||||
Top level directory structure:
|
||||
- `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.
|
||||
- `res`: Resource files used by tests.
|
||||
|
||||
## Running the tests
|
||||
```bash
|
||||
# Run all tests
|
||||
@ -11,34 +20,16 @@ cargo test --lib
|
||||
# Run integration tests (the tests in this directory)
|
||||
cargo test --test typeset
|
||||
|
||||
# Run all tests whose names contain a filter word
|
||||
cargo test --test typeset call
|
||||
# Run all tests whose names contain the word `filter`
|
||||
cargo test --test typeset filter
|
||||
```
|
||||
|
||||
For experimenting it's often useful to have a test file you can quickly run. For that purpose you can have a file named `playground.typ` right in this directory (the file is ignored by git). The playground test will be executed whenever no other test matches the filter, so you can run it with (since no real test's name contains an underscore):
|
||||
```bash
|
||||
cargo test --test typeset _
|
||||
```
|
||||
|
||||
## 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.
|
||||
- `png`: PNG files produced by tests.
|
||||
- `pdf`: PDF files produced by tests.
|
||||
|
||||
## Creating new tests
|
||||
To keep things small, please optimize reference images before committing them:
|
||||
```bash
|
||||
# One image
|
||||
oxipng -o max path/to/image.png
|
||||
|
||||
# All images
|
||||
oxipng -r -o max tests/*/ref
|
||||
oxipng -r -o max tests/ref
|
||||
```
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Test unary expressions.
|
||||
// Ref: false
|
||||
|
||||
---
|
||||
// Test plus and minus.
|
||||
#for v in (1, 3.14, 12pt, 45deg, 90%, 13% + 10pt) {
|
||||
// Test plus.
|
||||
test(+v, v)
|
||||
|
||||
// Test minus.
|
||||
test(-v, -1 * v)
|
||||
test(--v, v)
|
||||
|
||||
// Test combination.
|
||||
test(-++ --v, -v)
|
||||
}
|
||||
|
||||
#test(-(4 + 2), 6-12)
|
||||
|
||||
---
|
||||
// Test not.
|
||||
#test(not true, false)
|
||||
#test(not false, true)
|
Before Width: | Height: | Size: 682 B After Width: | Height: | Size: 682 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 364 B After Width: | Height: | Size: 364 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 507 B After Width: | Height: | Size: 507 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 756 B After Width: | Height: | Size: 756 B |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 215 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 821 B After Width: | Height: | Size: 821 B |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -9,6 +9,21 @@
|
||||
---
|
||||
// Test math operators.
|
||||
|
||||
// Test plus and minus.
|
||||
#for v in (1, 3.14, 12pt, 45deg, 90%, 13% + 10pt) {
|
||||
// Test plus.
|
||||
test(+v, v)
|
||||
|
||||
// Test minus.
|
||||
test(-v, -1 * v)
|
||||
test(--v, v)
|
||||
|
||||
// Test combination.
|
||||
test(-++ --v, -v)
|
||||
}
|
||||
|
||||
#test(-(4 + 2), 6-12)
|
||||
|
||||
// Addition.
|
||||
#test(2 + 4, 6)
|
||||
#test("a" + "b", "ab")
|
||||
@ -74,6 +89,10 @@
|
||||
---
|
||||
// Test boolean operators.
|
||||
|
||||
// Test not.
|
||||
#test(not true, false)
|
||||
#test(not false, true)
|
||||
|
||||
// And.
|
||||
#test(false and false, false)
|
||||
#test(false and true, false)
|
@ -28,10 +28,10 @@ use typst::shaping::Shaped;
|
||||
use typst::syntax::{Location, Pos};
|
||||
use typst::typeset;
|
||||
|
||||
const TYP_DIR: &str = "typ";
|
||||
const REF_DIR: &str = "ref";
|
||||
const PNG_DIR: &str = "png";
|
||||
const PDF_DIR: &str = "pdf";
|
||||
const TYP_DIR: &str = "./typ";
|
||||
const REF_DIR: &str = "./ref";
|
||||
const PNG_DIR: &str = "./png";
|
||||
const PDF_DIR: &str = "./pdf";
|
||||
const FONT_DIR: &str = "../fonts";
|
||||
|
||||
fn main() {
|
||||
@ -71,25 +71,13 @@ fn main() {
|
||||
resources: ResourceLoader::new(),
|
||||
};
|
||||
|
||||
let playground = Path::new("playground.typ");
|
||||
if playground.exists() && filtered.is_empty() {
|
||||
test(
|
||||
playground,
|
||||
Path::new("playground.png"),
|
||||
Path::new("playground.pdf"),
|
||||
None,
|
||||
&mut env,
|
||||
);
|
||||
}
|
||||
|
||||
let mut ok = true;
|
||||
for src_path in filtered {
|
||||
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);
|
||||
let trailer = src_path.strip_prefix(TYP_DIR).unwrap();
|
||||
let png_path = Path::new(PNG_DIR).join(trailer).with_extension("png");
|
||||
let pdf_path = Path::new(PDF_DIR).join(trailer).with_extension("pdf");
|
||||
let ref_path = Path::new(REF_DIR).join(trailer).with_extension("png");
|
||||
ok &= test(&src_path, &png_path, &pdf_path, &ref_path, &mut env);
|
||||
}
|
||||
|
||||
if !ok {
|
||||
@ -131,7 +119,7 @@ fn test(
|
||||
src_path: &Path,
|
||||
png_path: &Path,
|
||||
pdf_path: &Path,
|
||||
ref_path: Option<&Path>,
|
||||
ref_path: &Path,
|
||||
env: &mut Env,
|
||||
) -> bool {
|
||||
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
||||
@ -176,16 +164,14 @@ fn test(
|
||||
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
||||
canvas.pixmap.save_png(png_path).unwrap();
|
||||
|
||||
if let Some(ref_path) = ref_path {
|
||||
if let Ok(ref_pixmap) = Pixmap::load_png(ref_path) {
|
||||
if canvas.pixmap != ref_pixmap {
|
||||
println!(" Does not match reference image. ❌");
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
println!(" Failed to open reference image. ❌");
|
||||
if let Ok(ref_pixmap) = Pixmap::load_png(ref_path) {
|
||||
if canvas.pixmap != ref_pixmap {
|
||||
println!(" Does not match reference image. ❌");
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
println!(" Failed to open reference image. ❌");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
|