tingerrr / typst-test

A test runner for typst projects.
https://tingerrr.github.io/typst-test/
MIT License
27 stars 2 forks source link

Compile-only tests #14

Closed tingerrr closed 4 months ago

tingerrr commented 8 months ago

Add some kind of mechanism to mark tests which do not have references and are meant only to be compiled.

Just omitting the references could be enough, an option on new and edit could be added to select if a test should be compared or not.

freundTech commented 5 months ago

In addition to compile-only tests I would also like to see query test that use typst query to confirm that certain conditions are met.

I used python and pytest to implement a simple version of that in my typearea package.

In my case a test looks like this:

#import "../typearea.typ": *

#show: typearea.with(
  width: 100pt,
  height: 100pt,
  div: 10,
)

#context [
  #layout(size => [
    #metadata(here().position() + size)<result>
  ])
]

#metadata((
  page: 1,
  x: 10pt,
  y: 10pt,
  width: 70pt,
  height: 70pt,
))<expected>

and the test verifies that <result>.value and <expected>.value are the same.

tingerrr commented 5 months ago

Couldn't you just compare the values using assert.eq?

#import "../typearea.typ": *

#show: typearea.with(
  width: 100pt,
  height: 100pt,
  div: 10,
)

#context [
  #layout(size => [
    #metadata(here().position() + size)<result>
  ])
]

#context {
  assert.eq(
    query(<result>).first(),
    (
      page: 1,
      x: 10pt,
      y: 10pt,
      width: 70pt,
      height: 70pt,
    ),
  )
}

I don't see a specific reason for query, at least for this example, but I'll make an issue for it.

EDIT: See #23.