2020-10-13 12:34:11 +02:00
# Tests
2021-02-20 17:53:40 +01:00
## Directory structure
Top level directory structure:
- `typ` : Input files.
2021-03-19 17:57:31 +01:00
- `res` : Resource files used by tests.
2021-02-20 17:53:40 +01:00
- `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.
2021-02-07 13:27:03 +01:00
## Running the tests
2021-03-19 17:57:31 +01:00
Running the integration tests (the tests in this directory).
2021-02-07 13:27:03 +01:00
```bash
cargo test --test typeset
2021-03-19 17:57:31 +01:00
```
2021-02-07 13:27:03 +01:00
2021-12-15 11:12:38 +01:00
Running all tests whose paths contain the string `page` or `stack` .
2021-03-19 17:57:31 +01:00
```bash
2021-12-15 11:12:38 +01:00
cargo test --test typeset page stack
```
Running a test with the exact filename `page.typ` .
```bash
cargo test --test typeset -- --exact page.typ
```
Debug-printing the layout trees for all executed tests.
```bash
cargo test --test typeset -- --debug empty.typ
2021-02-07 13:27:03 +01:00
```
2021-03-19 17:57:31 +01:00
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
```
2021-02-20 17:53:40 +01:00
## Creating new tests
2021-03-19 17:57:31 +01:00
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.
2021-01-14 17:28:03 +01:00
```bash
# One image
2021-01-16 15:28:03 +01:00
oxipng -o max path/to/image.png
2021-01-14 17:28:03 +01:00
# All images
2021-02-20 17:53:40 +01:00
oxipng -r -o max tests/ref
2021-01-14 17:28:03 +01:00
```
2021-12-15 11:12:38 +01:00
## Shorthand for running tests
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:
```bash
tests --debug empty.typ
```
### PowerShell
Open your PowerShell profile by executing `notepad $profile` .
```ps
function tests {
cargo test --test typeset -- $args
}
```
### Bash
Open your Bash configuration by executing `nano ~/.bashrc` .
```bash
alias tests="cargo test --test typeset --"
```