typst/tests
2022-11-24 17:51:07 +01:00
..
fonts Move font folder 2022-11-20 18:14:13 +01:00
ref Don't display functions 2022-11-21 17:11:40 +01:00
res XML reading 2022-09-25 18:20:39 +02:00
src Separate typesetting and compilation 2022-11-24 17:51:07 +01:00
typ Show with set 2022-11-21 17:12:16 +01:00
Cargo.toml Separate test crate 2022-11-03 16:13:35 +01:00
README.md Move font folder 2022-11-20 18:14:13 +01:00

Tests

Directory structure

Top level directory structure:

  • src: Testing code.
  • 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.
  • fonts: Font files used for tests.

Running the tests

Running all tests (including unit tests):

cargo test --all

Running just the integration tests (the tests in this directory):

cargo test --all --test tests

You may want to make yourself an alias like:

testit

Running all tests whose paths contain the string page or stack.

testit page stack

Running a test with the exact filename page.typ.

testit --exact page.typ

Debug-printing the layout trees for all executed tests.

testit --debug empty.typ

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.

testit --pdf

Creating new tests

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.

# One image
oxipng -o max path/to/image.png

# All images
oxipng -r -o max tests/ref

Making an alias

If you want to have a quicker way to run the tests, consider adding a shortcut to your shell profile so that you can simply write something like:

testit empty.typ

Bash

Open your Bash configuration by executing nano ~/.bashrc.

alias testit="cargo test --all --test tests --"

PowerShell

Open your PowerShell profile by executing notepad $profile.

function testit {
    cargo test --all --test tests -- $args
}