Move test files into category subfolders 🚚

This commit is contained in:
Laurenz 2021-01-14 16:47:29 +01:00
parent 272a4c2289
commit cfcb36b159
35 changed files with 60 additions and 96 deletions

View File

@ -25,6 +25,7 @@ serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies] [dev-dependencies]
tiny-skia = "0.2" tiny-skia = "0.2"
walkdir = "2"
[profile.dev] [profile.dev]
opt-level = 2 opt-level = 2

View File

@ -13,7 +13,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/typ/example-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 {

View File

@ -3,7 +3,7 @@ use std::fmt::{self, Debug, Formatter};
use super::*; use super::*;
use crate::eval::Softness; use crate::eval::Softness;
/// A spacing node. /// A spacing node.
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub struct NodeSpacing { pub struct NodeSpacing {
/// The amount of spacing to insert. /// The amount of spacing to insert.

View File

@ -8,3 +8,8 @@
- `res`: Resource files used by tests. - `res`: Resource files used by tests.
- `png`: PNG files produced by tests. - `png`: PNG files produced by tests.
- `pdf`: PDF 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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
tests/ref/lang/basics.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 94 B

After

Width:  |  Height:  |  Size: 94 B

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 215 KiB

After

Width:  |  Height:  |  Size: 215 KiB

BIN
tests/ref/library/page.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

Before

Width:  |  Height:  |  Size: 821 B

After

Width:  |  Height:  |  Size: 821 B

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1,5 +1,3 @@
// Test integration of syntax, library and layouting.
[page width: 450pt, height: 300pt, margins: 1cm] [page width: 450pt, height: 300pt, margins: 1cm]
[box][ [box][

View File

@ -1,17 +1,9 @@
// Test text, emph and strong.
Hello 🌏! Hello 🌏!
_Emph_ and *strong*! _Emph_ and *strong*!
---
// Test non-breaking space.
The non-breaking~space does not work. The non-breaking~space does not work.
---
// Test backslash.
// Directly after word. // Directly after word.
Line\ Break Line\ Break

View File

@ -1,4 +1,4 @@
// Number of hashtags. // Test different numbers of hashtags.
# One # One
### Three ### Three
@ -8,7 +8,7 @@
####### Seven ####### Seven
--- ---
// Heading vs. no heading. // Test heading vs. no heading.
/**/ # Heading /**/ # Heading
{[## Heading]} {[## Heading]}
@ -24,7 +24,7 @@ Nr#1
#nope #nope
--- ---
// Heading continues over linebreak. // Heading continuation over linebreak.
# This { # This {
"works" "works"

View File

@ -19,8 +19,22 @@
// Set stretch (not available, matching closest). // Set stretch (not available, matching closest).
[font stretch: ultra-condensed][Condensed] [font stretch: ultra-condensed][Condensed]
// Error: 1:7-1:12 unexpected argument
[font false]
// Error: 3:14-3:18 expected font style, found font weight
// Error: 2:28-2:34 expected font weight, found string
// Error: 1:43-1:44 expected font family or array of font families, found integer
[font style: bold, weight: "thin", serif: 0]
// Warning: 1:15-1:19 must be between 100 and 900
[font weight: 2700]
// Error: 1:7-1:27 unexpected argument
[font something: "invalid"]
--- ---
// Test font fallback. // Test font fallback and class definitions.
// Source Sans Pro + Segoe UI Emoji. // Source Sans Pro + Segoe UI Emoji.
Emoji: 🏀 Emoji: 🏀
@ -40,21 +54,3 @@ Emoji: 🏀
[font sans-serif: "Noto Emoji"] [font sans-serif: "Noto Emoji"]
[font sans-serif: ("Archivo", sans-serif)] [font sans-serif: ("Archivo", sans-serif)]
New sans-serif. 🚀 New sans-serif. 🚀
---
// Test error cases.
// Ref: false
// Error: 1:7-1:12 unexpected argument
[font false]
// Error: 3:14-3:18 expected font style, found font weight
// Error: 2:28-2:34 expected font weight, found string
// Error: 1:43-1:44 expected font family or array of font families, found integer
[font style: bold, weight: "thin", serif: 0]
// Warning: 1:15-1:19 must be between 100 and 900
[font weight: 2700]
// Error: 1:7-1:27 unexpected argument
[font something: "invalid"]

View File

@ -1,5 +1,3 @@
// Test the `h` and `v` functions.
// Ends paragraphs. // Ends paragraphs.
Tightly [v -5pt] packed Tightly [v -5pt] packed

View File

@ -7,6 +7,12 @@
// Load an RGB JPEG image. // Load an RGB JPEG image.
[image "res/tiger.jpg"] [image "res/tiger.jpg"]
// Error: 1:8-1:29 failed to load image
[image "path/does/not/exist"]
// Error: 1:8-1:29 failed to load image
[image "typ/image-error.typ"]
--- ---
// Test configuring the size and fitting behaviour of images. // Test configuring the size and fitting behaviour of images.
@ -31,14 +37,3 @@
[align bottom, right][ [align bottom, right][
[image "res/tiger.jpg", width: 60pt] [image "res/tiger.jpg", width: 60pt]
] ]
---
// Test error cases.
//
// Ref: false
// Error: 1:8-1:29 failed to load image
[image "path/does/not/exist"]
// Error: 1:8-1:29 failed to load image
[image "typ/image-error.typ"]

View File

@ -21,8 +21,11 @@
// Ensure that specific margins override general margins. // Ensure that specific margins override general margins.
[page margins: 0pt, left: 20pt][Overriden] [page margins: 0pt, left: 20pt][Overriden]
--- // Error: 1:7-1:18 unknown variable
// Test flipping. [page nonexistant]
// Error: 1:17-1:20 aligned axis
[page main-dir: ltr]
// Flipped predefined paper. // Flipped predefined paper.
[page "a11", flip: true][Flipped A11] [page "a11", flip: true][Flipped A11]
@ -32,6 +35,11 @@
[page flip: true] [page flip: true]
Wide Wide
// Test changing the layouting directions of pages.
[page height: 50pt, main-dir: btt, cross-dir: rtl]
Right to left!
--- ---
// Test a combination of pages with bodies and normal content. // Test a combination of pages with bodies and normal content.
@ -44,21 +52,3 @@ Fourth
[page][] [page][]
Sixth Sixth
[page][Seventh and last] [page][Seventh and last]
---
// Test changing the layouting directions of pages.
[page height: 50pt, main-dir: btt, cross-dir: rtl]
Right to left!
---
// Test error cases.
//
// Ref: false
// Error: 1:7-1:18 unknown variable
[page nonexistant]
// Error: 1:17-1:20 aligned axis
[page main-dir: ltr]

View File

@ -1,5 +1,3 @@
// Test trailing pagebreak.
First of two First of two
[pagebreak] [pagebreak]
[page height: 40pt] [page height: 40pt]

View File

@ -1,5 +1,3 @@
// Test the `rgb` function.
// Check the output. // Check the output.
[rgb 0.0, 0.3, 0.7] [rgb 0.0, 0.3, 0.7]

View File

@ -12,6 +12,7 @@ use tiny_skia::{
Rect, SpreadMode, Transform, Rect, SpreadMode, Transform,
}; };
use ttf_parser::OutlineBuilder; use ttf_parser::OutlineBuilder;
use walkdir::WalkDir;
use typst::diag::{Diag, Feedback, Level, Pass}; use typst::diag::{Diag, Feedback, Level, Pass};
use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv}; use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv};
@ -37,15 +38,15 @@ fn main() {
let filter = TestFilter::new(env::args().skip(1)); let filter = TestFilter::new(env::args().skip(1));
let mut filtered = Vec::new(); let mut filtered = Vec::new();
for entry in fs::read_dir(TYP_DIR).unwrap() { for entry in WalkDir::new(TYP_DIR).into_iter() {
let src_path = entry.unwrap().path(); let entry = entry.unwrap();
let src_path = entry.into_path();
if src_path.extension() != Some(OsStr::new("typ")) { if src_path.extension() != Some(OsStr::new("typ")) {
continue; continue;
} }
let name = src_path.file_stem().unwrap().to_string_lossy().to_string(); if filter.matches(&src_path.to_string_lossy().to_string()) {
if filter.matches(&name) { filtered.push(src_path);
filtered.push((name, src_path));
} }
} }
@ -56,9 +57,6 @@ fn main() {
println!("Running {} tests", len); println!("Running {} tests", len);
} }
fs::create_dir_all(PNG_DIR).unwrap();
fs::create_dir_all(PDF_DIR).unwrap();
let mut index = FsIndex::new(); let mut index = FsIndex::new();
index.search_dir(FONT_DIR); index.search_dir(FONT_DIR);
@ -69,9 +67,8 @@ fn main() {
})); }));
let playground = Path::new("playground.typ"); let playground = Path::new("playground.typ");
if playground.exists() { if playground.exists() && filtered.is_empty() {
test( test(
"playground",
playground, playground,
Path::new("playground.png"), Path::new("playground.png"),
Path::new("playground.pdf"), Path::new("playground.pdf"),
@ -81,18 +78,12 @@ fn main() {
} }
let mut ok = true; let mut ok = true;
for (name, src_path) in filtered { for src_path in filtered {
let png_path = Path::new(PNG_DIR).join(&name).with_extension("png"); let relative = src_path.strip_prefix(TYP_DIR).unwrap();
let pdf_path = Path::new(PDF_DIR).join(&name).with_extension("pdf"); let png_path = Path::new(PNG_DIR).join(&relative).with_extension("png");
let ref_path = Path::new(REF_DIR).join(&name).with_extension("png"); let pdf_path = Path::new(PDF_DIR).join(&relative).with_extension("pdf");
ok &= test( let ref_path = Path::new(REF_DIR).join(&relative).with_extension("png");
&name, ok &= test(&src_path, &png_path, &pdf_path, Some(&ref_path), &env);
&src_path,
&png_path,
&pdf_path,
Some(&ref_path),
&env,
);
} }
if !ok { if !ok {
@ -131,14 +122,14 @@ impl TestFilter {
} }
fn test( fn test(
name: &str,
src_path: &Path, src_path: &Path,
png_path: &Path, png_path: &Path,
pdf_path: &Path, pdf_path: &Path,
ref_path: Option<&Path>, ref_path: Option<&Path>,
env: &SharedEnv, env: &SharedEnv,
) -> bool { ) -> bool {
println!("Testing {}.", name); let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
println!("Testing {}", name.display());
let src = fs::read_to_string(src_path).unwrap(); let src = fs::read_to_string(src_path).unwrap();
@ -154,9 +145,11 @@ fn test(
let env = env.borrow(); let env = env.borrow();
if !frames.is_empty() { if !frames.is_empty() {
let pdf_data = pdf::export(&frames, &env); let pdf_data = pdf::export(&frames, &env);
fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
fs::write(pdf_path, pdf_data).unwrap(); fs::write(pdf_path, pdf_data).unwrap();
let canvas = draw(&frames, &env, 2.0); let canvas = draw(&frames, &env, 2.0);
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 Some(ref_path) = ref_path {
@ -173,7 +166,7 @@ fn test(
} }
if ok { if ok {
println!("\x1b[1ATesting {}.", name); println!("\x1b[1ATesting {}", name.display());
} }
ok ok