tinymist icon indicating copy to clipboard operation
tinymist copied to clipboard

Failures inside `context` do not fail tests.

Open patrick-kidger opened this issue 3 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Platform

Apple Silicon macOS (darwin-arm64, Most Common)

Editor

Helix

Editor Version

helix 24.3 (2cadec0b)

Describe the bug

MWE code:

// foo.typ
#let test-foo() = {
  context assert(false)
}

And then running like so:

❯ tinymist test foo.typ
   Info Found 1 tests and 0 examples
Running test(test-foo)
 Passed test(test-foo)
   Info All test cases passed...

What else has been tried

Adding an extra line #test-foo() to foo.typ, and then running, simply causes no output:

❯ tinymist test foo.typ  // nothing else here!

though it does quit with error code 1, which is something.

Adding an extra line #test-foo() to foo.typ, and then running typst compile foo.typ, will cause a failure:

❯ typst compile foo.typ
error: assertion failed
  ┌─ foo.typ:3:10
  │
3 │   context assert(false)
  │           ^^^^^^^^^^^^^

Server Logs

I think logs here are not applicable, as the failure is through the CLI and not the LSP.

Browser Logs

N/A, I don't know what this might correspond to in Helix.

Additional context

No response

patrick-kidger avatar Sep 22 '25 22:09 patrick-kidger

The test- functions only evaluate the code, i.e. doesn't run an engine to typeset content. If we know typst engine, we get that the body of contextual blocks are not executed intermediately and will be executed when they are instantiated during typesetting.

Myriad-Dreamin avatar Sep 23 '25 16:09 Myriad-Dreamin

Yup, I understand the underlying reason.

Perhaps tinymist test could both (a) run the function and then (b) #place-it-in-a-document so that contextual errors are properly caught as well?

patrick-kidger avatar Sep 23 '25 22:09 patrick-kidger

We can geneate main files that "place-it-in-a-document" and compile them to capture errors in typst contents. The change may slow down tests for some reason, but it is acceptable for it is more important to get all errors. This is an enhancement not a bug.

Myriad-Dreamin avatar Oct 02 '25 23:10 Myriad-Dreamin