Skip to content

Better test runner - #3922

Merged
laurmaedje merged 3 commits into
mainfrom
better-test-runner
Apr 13, 2024
Merged

laurmaedje merged 3 commits into
mainfrom
better-test-runner

Conversation

@laurmaedje

Copy link
Copy Markdown
Member

This PR rewrites the test runner from scratch and refactors the test suite. Here are the main changes:

  • All 1967 tests now have unique names. The names reflect the intent of the tests to make them easier to understand. They are also used for the reference images. The format is --- {name} --- followed by the test, e.g.:

    --- math-accent-bounds ---
    // Test accent bounds.
    $sqrt(tilde(T)) + hat(f)/hat(g)$
  • There is now one reference image per individual test rather than one per test file. This means that tests don't need to be split up awkwardly anymore just to prevent an overlarge reference image.

  • The test-helper VS Code extension was updated to provide a per-test code lens that can be used to View, Run, and Save the test or to run it in the terminal.

    math-accent

  • The test runner now automatically detects whether a test has visual output and requires a reference image if and only if it does. There is no // Ref: false anymore.

  • The runner's output is much more helpful. It points to concrete source locations in the test when there are failures and detects when just the range or message of an error is mismatched, but not both. For example

    --- playground ---
    // Error: 10-13 expected content, found auto
    #heading(auto)

    now yields

    ❌ playground (tests/suite/playground.typ:2)
    mismatched range (tests/suite/playground.typ:2):
      message   | expected content, found auto
      annotated | 3:10-3:13 | `aut`
      emitted   | 3:10-3:14 | `auto`
    
  • The resolution of the reference images was reduced from 2 pixels per point to 1 pixel per point. For the comparison itself that's enough and it's also still enough resolution to see what's going on. If a higher resolution is useful during development, the test runner's new --scale flag can be used. The reason for the lower resolution is to prevent repository bloat. With the smaller size and some changes to exceptionally large tests, the full reference image suite is brought down to 2.5 MiB at the time of writing. Through the change to images per test rather than per test file, the amount of data added to the git history in the future should be additionally lowered.

  • To ensure that no overlarge reference images slip in, the test runner enforces a maximum reference image size of 20 KiB. If this limit is exceeded, it's typically possible to adjust the test to make it smaller without too much problems. If truly necessary, the limit can however be lifted by adding // LARGE as the first line of a test.

  • The test suite was reorganized, merging previously separate files, bringing the tests more in line with changes to the code base, and cleaning things up in general. The test harness was moved from typ to suite. The output directories were moved into a shared store directory.

  • The runner now has more robust handling for when a test is stuck in an endless loop or panicked and points to the concrete problematic test.

  • The test runner only accepts --update, not UPDATE_EXPECT anymore. When used just once, the variable doesn't really make much sense over a flag, and permanently being in the updating state does not make sense at all.

  • Autocompletion tests were migrated to normal Rust unit tests in the typst-ide crate. It turns out that this approach is actually much simpler and more flexible than maintaining separate test syntax just for that. The small bit of new infrastructure in typst-ide also makes it easy to test other functionality like tooltips, etc. in the future.

@LuxxxLucy

LuxxxLucy commented Apr 16, 2024 •

Copy link
Copy Markdown
Contributor

For anyone seeing this, you will need to manually clean/remove the old png folder to get new test runner working. And also that previously you run specific test by specifying the typ file name, now you should run by specifying the test_case_name which is the test case

--- <test-case-name> ---

as in the typ file. And so you should do cargo test --workspace --test tests -- <test-case-name>

This should apply to anyone that has a working copy of the repo before this PR is merged. New afresh repo should be fine,

laurmaedje added a commit that referenced this pull request May 16, 2024
laurmaedje added a commit that referenced this pull request May 17, 2024
@isuffix isuffix mentioned this pull request Nov 19, 2025
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants