I'm using typst to generate a pdf , I want test if the pdf generated is generated as expected or not.
I'm thinking of having a pre generated correct sample pdf , which I can compare with the generated report and know if the pdf generated is correct or not...
I'm not yet sure how to achieve this , but if you have some good idea on how to test thhe pdf , please shahre.
#Testing generated pdf
8 messages · Page 1 of 1 (latest)
depends - what is "correct"?
If you want complete equality, then comparing the md5sum of two documents would work. I usually use this strategy in my libraries, but in a somewhat manual way:
- I have some examples in a
gallery/folder - after a change to the library, I regenerate the example pdfs
- if
git statusreports that any PDFs have changed, I know that the change I did was not a clean refactoring; if that was unexpected, I will investigate
generally, this works if your documents useset document(date: ...)(so that the timestamp is repeatable) and as long as the Typst version doesn't change. It may fail for more visual features, where what counts is not byte-for-byte equality.
If you want a visual comparison, you can have a look at typst-test. It doesn't wok on PDFs but on pngs and does a visual comparison, exactly like you described. In my experience, it also requires the Typst version not to change to work properly.
Thanks for the reply @grave garden ...
I cannot use typst-test as of now , since it's not stable as of now.
for the first approach I was trying something similar by generating hashes of both the files and comparing them , but that was failing due to meta data features like time etc
I assume this was you, given that it's very recent? https://github.com/typst/typst/issues/4561
so yeah, Typst PDFs are generally repeatable if the date is given
no that's not me
well, what a coincidence 😅 anyway, is there still a problem with the metadata or does it work now? if the document is not reproducible, I'd say that's considered a bug.
last time I checked it wasn't very reliable , so now trying to compare png or svg
that'll be much more reliable