summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-19 17:57:31 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-19 17:57:31 +0100
commit264a7dedd42e27cd9e604037640cf0594b2ec46b (patch)
treed26feea399d54bb86bd44878f40293983bf5251d /tests
parentca3df70e2a5069832d7d2135967674c34a155442 (diff)
Scheduled maintenance 🔨
- New naming scheme - TextNode instead of NodeText - CallExpr instead of ExprCall - ... - Less glob imports - Removes Value::Args variant - Removes prelude - Renames Layouted to Fragment - Moves font into env - Moves shaping into layout - Moves frame into separate module
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md26
-rw-r--r--tests/typeset.rs26
2 files changed, 31 insertions, 21 deletions
diff --git a/tests/README.md b/tests/README.md
index fb755f1b..57d47fe2 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -3,29 +3,35 @@
## Directory structure
Top level directory structure:
- `typ`: Input files.
+- `res`: Resource files used by tests.
- `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 integration tests (the tests in this directory).
```bash
-# Run all tests
-cargo test
-
-# Run unit tests
-cargo test --lib
-
-# Run integration tests (the tests in this directory)
cargo test --test typeset
+```
-# Run all tests whose names contain the word `filter`
+Running all tests whose names contain the word `filter`.
+```bash
cargo test --test typeset filter
```
+To make the integration tests go faster they don't generate PDFs by default.
+Pass the `--pdf` flag to generate those. Mind that PDFs are not tested
+automatically at the moment, so you should always check the output manually when
+making changes.
+```bash
+cargo test --test typeset -- --pdf
+```
+
## Creating new tests
-To keep things small, please optimize reference images before committing them:
+To keep things small, please optimize reference images before committing them.
+When you use the approve buttom from the Test Helper (see the `tools` folder)
+this happens automatically if you have `oxipng` installed.
```bash
# One image
oxipng -o max path/to/image.png
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 0cd146f4..7e7efc67 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -15,16 +15,15 @@ use ttf_parser::OutlineBuilder;
use walkdir::WalkDir;
use typst::diag::{Diag, DiagSet, Level, Pass};
-use typst::env::{Env, ImageResource, ResourceLoader};
-use typst::eval::{EvalContext, Scope, Value, ValueArgs, ValueFunc};
+use typst::env::{Env, FsIndexExt, ImageResource, ResourceLoader};
+use typst::eval::{EvalContext, FuncArgs, FuncValue, Scope, Value};
use typst::exec::State;
use typst::export::pdf;
-use typst::font::FsIndexExt;
use typst::geom::{Length, Point, Sides, Size};
-use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape};
+use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape, Shaped};
use typst::library;
use typst::parse::{LineMap, Scanner};
-use typst::shaping::Shaped;
+use typst::pretty::pretty;
use typst::syntax::{Location, Pos};
use typst::typeset;
@@ -313,13 +312,18 @@ struct Panic {
}
fn register_helpers(scope: &mut Scope, panics: Rc<RefCell<Vec<Panic>>>) {
- pub fn args(_: &mut EvalContext, args: &mut ValueArgs) -> Value {
- let value = args.clone().into();
+ pub fn args(_: &mut EvalContext, args: &mut FuncArgs) -> Value {
+ let repr = pretty(args);
args.items.clear();
- value
+ Value::template("args", move |ctx| {
+ let snapshot = ctx.state.clone();
+ ctx.set_monospace();
+ ctx.push_text(&repr);
+ ctx.state = snapshot;
+ })
}
- let test = move |ctx: &mut EvalContext, args: &mut ValueArgs| -> Value {
+ let test = move |ctx: &mut EvalContext, args: &mut FuncArgs| -> Value {
let lhs = args.require::<Value>(ctx, "left-hand side");
let rhs = args.require::<Value>(ctx, "right-hand side");
if lhs != rhs {
@@ -331,8 +335,8 @@ fn register_helpers(scope: &mut Scope, panics: Rc<RefCell<Vec<Panic>>>) {
};
scope.def_const("error", Value::Error);
- scope.def_const("args", ValueFunc::new(Some("args".into()), args));
- scope.def_const("test", ValueFunc::new(Some("test".into()), test));
+ scope.def_const("args", FuncValue::new(Some("args".into()), args));
+ scope.def_const("test", FuncValue::new(Some("test".into()), test));
}
fn print_diag(diag: &Diag, map: &LineMap, lines: u32) {