2020-10-13 12:34:11 +02:00
# Tests
2021-02-20 17:53:40 +01:00
## Directory structure
Top level directory structure:
2022-11-03 16:13:35 +01:00
- `src` : Testing code.
2022-11-29 13:37:25 +01:00
- `typ` : Input files. The tests in `compiler` specifically test the compiler
while the others test the standard library (but also the compiler
indirectly).
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
2022-11-03 16:13:35 +01:00
Running all tests (including unit tests):
2021-02-07 13:27:03 +01:00
```bash
2023-05-20 10:48:25 +02:00
cargo test --workspace
2022-11-03 16:13:35 +01:00
```
Running just the integration tests (the tests in this directory):
```bash
2023-05-20 10:48:25 +02:00
cargo test --workspace --test tests
2022-11-03 16:13:35 +01:00
```
You may want to [make yourself an alias ](#making-an-alias ) like:
```bash
testit
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
2022-11-03 16:13:35 +01:00
testit page stack
2021-12-15 11:12:38 +01:00
```
Running a test with the exact filename `page.typ` .
```bash
2022-11-03 16:13:35 +01:00
testit --exact page.typ
2021-12-15 11:12:38 +01:00
```
Debug-printing the layout trees for all executed tests.
```bash
2022-11-03 16:13:35 +01:00
testit --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
2022-11-03 16:13:35 +01:00
testit --pdf
2021-03-19 17:57:31 +01:00
```
2023-04-20 01:47:31 -07:00
## Update expected images
If you created a new test or fixed a bug in an existing test, you need to update
the reference image used for comparison. For this, you can use the
2023-05-02 20:45:18 +02:00
`UPDATE_EXPECT` environment variable or the `--update` flag:
2021-01-14 17:28:03 +01:00
```bash
2023-04-20 01:47:31 -07:00
testit mytest --update
2021-01-14 17:28:03 +01:00
```
2021-12-15 11:12:38 +01:00
2023-04-20 01:47:31 -07:00
If you use the VS Code test helper extension (see the `tools` folder), you can
alternatively use the checkmark button to update the reference image. In that
case you should also install `oxipng` on your system so that the test helper
can optimize the reference images.
2022-11-03 16:13:35 +01:00
## Making an alias
2021-12-15 11:12:38 +01:00
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
2022-11-03 16:13:35 +01:00
testit empty.typ
```
### Bash
Open your Bash configuration by executing `nano ~/.bashrc` .
```bash
2023-05-20 10:48:25 +02:00
alias testit="cargo test --workspace --test tests --"
2021-12-15 11:12:38 +01:00
```
### PowerShell
Open your PowerShell profile by executing `notepad $profile` .
```ps
2022-11-03 16:13:35 +01:00
function testit {
2023-05-20 10:48:25 +02:00
cargo test --workspace --test tests -- $args
2021-12-15 11:12:38 +01:00
}
```