Reorganize tests 🔀
4
.gitignore
vendored
@ -6,8 +6,8 @@ bench/target
|
|||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|
||||||
tests/*/png
|
tests/png
|
||||||
tests/*/pdf
|
tests/pdf
|
||||||
tests/playground.*
|
tests/playground.*
|
||||||
|
|
||||||
tarpaulin-report.html
|
tarpaulin-report.html
|
||||||
|
@ -12,7 +12,7 @@ use typst::parse::parse;
|
|||||||
use typst::typeset;
|
use typst::typeset;
|
||||||
|
|
||||||
const FONT_DIR: &str = "../fonts";
|
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) {
|
fn benchmarks(c: &mut Criterion) {
|
||||||
macro_rules! bench {
|
macro_rules! bench {
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
# Tests
|
# 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
|
## Running the tests
|
||||||
```bash
|
```bash
|
||||||
# Run all tests
|
# Run all tests
|
||||||
@ -11,34 +20,16 @@ cargo test --lib
|
|||||||
# Run integration tests (the tests in this directory)
|
# Run integration tests (the tests in this directory)
|
||||||
cargo test --test typeset
|
cargo test --test typeset
|
||||||
|
|
||||||
# Run all tests whose names contain a filter word
|
# Run all tests whose names contain the word `filter`
|
||||||
cargo test --test typeset call
|
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):
|
## Creating new tests
|
||||||
```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.
|
|
||||||
|
|
||||||
To keep things small, please optimize reference images before committing them:
|
To keep things small, please optimize reference images before committing them:
|
||||||
```bash
|
```bash
|
||||||
# One image
|
# One image
|
||||||
oxipng -o max path/to/image.png
|
oxipng -o max path/to/image.png
|
||||||
|
|
||||||
# All images
|
# 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 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.
|
// Addition.
|
||||||
#test(2 + 4, 6)
|
#test(2 + 4, 6)
|
||||||
#test("a" + "b", "ab")
|
#test("a" + "b", "ab")
|
||||||
@ -74,6 +89,10 @@
|
|||||||
---
|
---
|
||||||
// Test boolean operators.
|
// Test boolean operators.
|
||||||
|
|
||||||
|
// Test not.
|
||||||
|
#test(not true, false)
|
||||||
|
#test(not false, true)
|
||||||
|
|
||||||
// And.
|
// And.
|
||||||
#test(false and false, false)
|
#test(false and false, false)
|
||||||
#test(false and true, false)
|
#test(false and true, false)
|
@ -28,10 +28,10 @@ use typst::shaping::Shaped;
|
|||||||
use typst::syntax::{Location, Pos};
|
use typst::syntax::{Location, Pos};
|
||||||
use typst::typeset;
|
use typst::typeset;
|
||||||
|
|
||||||
const TYP_DIR: &str = "typ";
|
const TYP_DIR: &str = "./typ";
|
||||||
const REF_DIR: &str = "ref";
|
const REF_DIR: &str = "./ref";
|
||||||
const PNG_DIR: &str = "png";
|
const PNG_DIR: &str = "./png";
|
||||||
const PDF_DIR: &str = "pdf";
|
const PDF_DIR: &str = "./pdf";
|
||||||
const FONT_DIR: &str = "../fonts";
|
const FONT_DIR: &str = "../fonts";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -71,25 +71,13 @@ fn main() {
|
|||||||
resources: ResourceLoader::new(),
|
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;
|
let mut ok = true;
|
||||||
for src_path in filtered {
|
for src_path in filtered {
|
||||||
let category = src_path.parent().unwrap().parent().unwrap();
|
let trailer = src_path.strip_prefix(TYP_DIR).unwrap();
|
||||||
let name = src_path.file_stem().unwrap();
|
let png_path = Path::new(PNG_DIR).join(trailer).with_extension("png");
|
||||||
let png_path = category.join(PNG_DIR).join(name).with_extension("png");
|
let pdf_path = Path::new(PDF_DIR).join(trailer).with_extension("pdf");
|
||||||
let pdf_path = category.join(PDF_DIR).join(name).with_extension("pdf");
|
let ref_path = Path::new(REF_DIR).join(trailer).with_extension("png");
|
||||||
let ref_path = category.join(REF_DIR).join(name).with_extension("png");
|
ok &= test(&src_path, &png_path, &pdf_path, &ref_path, &mut env);
|
||||||
ok &= test(&src_path, &png_path, &pdf_path, Some(&ref_path), &mut env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -131,7 +119,7 @@ fn test(
|
|||||||
src_path: &Path,
|
src_path: &Path,
|
||||||
png_path: &Path,
|
png_path: &Path,
|
||||||
pdf_path: &Path,
|
pdf_path: &Path,
|
||||||
ref_path: Option<&Path>,
|
ref_path: &Path,
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
||||||
@ -176,7 +164,6 @@ fn test(
|
|||||||
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
||||||
canvas.pixmap.save_png(png_path).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 let Ok(ref_pixmap) = Pixmap::load_png(ref_path) {
|
||||||
if canvas.pixmap != ref_pixmap {
|
if canvas.pixmap != ref_pixmap {
|
||||||
println!(" Does not match reference image. ❌");
|
println!(" Does not match reference image. ❌");
|
||||||
@ -187,7 +174,6 @@ fn test(
|
|||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
println!("\x1b[1ATesting {} ✔", name.display());
|
println!("\x1b[1ATesting {} ✔", name.display());
|
||||||
|