diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-27 19:02:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-27 19:02:23 +0200 |
| commit | d8d60207ef1833001196feccb84cc0c78bdd84df (patch) | |
| tree | cdc2130d8b4265c52863f10418842d188afb63e8 /tests | |
| parent | f64c772b6d969fa3aa1a7391a3d8118b21430434 (diff) | |
| parent | e9960b89424ab67e633076ccc9f8c420316b076a (diff) | |
Merge pull request #33 from typst/cache-patterns
A test framework for incremental compilation
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/layout/stack.png | bin | 264 -> 325 bytes | |||
| -rw-r--r-- | tests/typ/layout/stack.typ | 9 | ||||
| -rw-r--r-- | tests/typeset.rs | 80 |
3 files changed, 74 insertions, 15 deletions
diff --git a/tests/ref/layout/stack.png b/tests/ref/layout/stack.png Binary files differindex 684905f7..2f190c4d 100644 --- a/tests/ref/layout/stack.png +++ b/tests/ref/layout/stack.png diff --git a/tests/typ/layout/stack.typ b/tests/typ/layout/stack.typ index 006a1412..89e587c7 100644 --- a/tests/typ/layout/stack.typ +++ b/tests/typ/layout/stack.typ @@ -7,3 +7,12 @@ rect(3cm, forest), rect(1cm, conifer), ) + +--- +// Test overflowing stack. + +#let rect(width, color) = rect(width: 1cm, height: 0.4cm, fill: color) +#box(height: 0.5cm, stack( + rect(3cm, forest), + rect(1cm, conifer), +)) diff --git a/tests/typeset.rs b/tests/typeset.rs index c5f31e61..31da3ce0 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -16,13 +16,13 @@ use walkdir::WalkDir; use typst::cache::Cache; use typst::color; use typst::diag::{Diag, DiagSet, Level}; -use typst::eval::{EvalContext, FuncArgs, FuncValue, Scope, Value}; -use typst::exec::State; +use typst::eval::{eval, EvalContext, FuncArgs, FuncValue, Scope, Value}; +use typst::exec::{exec, State}; use typst::geom::{self, Length, Point, Sides, Size}; use typst::image::ImageId; -use typst::layout::{Element, Fill, Frame, Shape, Text}; +use typst::layout::{layout, Element, Fill, Frame, Shape, Text}; use typst::loading::FsLoader; -use typst::parse::{LineMap, Scanner}; +use typst::parse::{parse, LineMap, Scanner}; use typst::syntax::{Location, Pos}; const TYP_DIR: &str = "./typ"; @@ -224,14 +224,20 @@ fn test_part( state.page.size = Size::new(Length::pt(120.0), Length::inf()); state.page.margins = Sides::splat(Some(Length::pt(10.0).into())); - // Clear cache between tests (for now). - cache.layout.clear(); - - let mut pass = typst::typeset(loader, cache, Some(src_path), &src, &scope, state); + let parsed = parse(src); + let evaluated = eval( + loader, + cache, + Some(src_path), + Rc::new(parsed.output), + &scope, + ); + let executed = exec(&evaluated.output.template, state.clone()); + let mut layouted = layout(loader, cache, &executed.output); - if !compare_ref { - pass.output.clear(); - } + let mut diags = parsed.diags; + diags.extend(evaluated.diags); + diags.extend(executed.diags); let mut ok = true; @@ -247,11 +253,11 @@ fn test_part( ok = false; } - if pass.diags != ref_diags { + if diags != ref_diags { println!(" Subtest {} does not match expected diagnostics. ❌", i); ok = false; - for diag in &pass.diags { + for diag in &diags { if !ref_diags.contains(diag) { print!(" Not annotated | "); print_diag(diag, &map, lines); @@ -259,14 +265,58 @@ fn test_part( } for diag in &ref_diags { - if !pass.diags.contains(diag) { + if !diags.contains(diag) { print!(" Not emitted | "); print_diag(diag, &map, lines); } } } - (ok, compare_ref, pass.output) + let reference_cache = cache.layout.clone(); + for level in 0 .. reference_cache.levels() { + cache.layout = reference_cache.clone(); + cache.layout.retain(|x| x == level); + if cache.layout.frames.is_empty() { + continue; + } + + cache.layout.turnaround(); + + let cached_result = layout(loader, cache, &executed.output); + + let misses = cache + .layout + .frames + .iter() + .flat_map(|(_, e)| e) + .filter(|e| e.level == level && !e.hit() && e.age() == 2) + .count(); + + if misses > 0 { + ok = false; + println!( + " Recompilation had {} cache misses on level {} (Subtest {}) ❌", + misses, level, i + ); + } + + if cached_result != layouted { + ok = false; + println!( + " Recompilation of subtest {} differs from clean pass ❌", + i + ); + } + } + + cache.layout = reference_cache; + cache.layout.turnaround(); + + if !compare_ref { + layouted.clear(); + } + + (ok, compare_ref, layouted) } fn parse_metadata(src: &str, map: &LineMap) -> (Option<bool>, DiagSet) { |
