Giter Club home page Giter Club logo

typst-test's Introduction

rust & typst enthusiast

typst-test's People

Contributors

pgbiel avatar tingerrr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

pgbiel

typst-test's Issues

Change folder structure to one subdirectory per test

I propose changing the folder structure, such that each test file lives in its own folder. A test folder contains a Typst file (e.g. "test.typ") plus the reference image.

CeTZ currently uses its own test script, which structures the tests as given above, but we would like to use typst-test.

CeTZ's tests are recognized by recursively scanning the tests/ directory for test.typ files and, if found, use the folder of those files as test-cases. This allows nesting/grouping tests by topic by just putting them in common parent directories.

Compile tests in memory

By adding typst as a dependency, test output generation and comparison could be done entirely in memory. This seems like a sensible thing to do, here are some of the pros and cons:

Pros

  • less I/O by doing in-memory reference to image comparison
    • increased performance
  • typst-test can be run without an external binary for typst, reducing error paths and improving usability
  • multiple tests can be parsed from a single test file with most of the config living in this file
    • avoids config files for configuring per test behavior
  • allows for separation of typst-test into a library crate and binary crate
    • opens the door for others to use the same underlying implementation for test running

Cons

  • fixes typst-test to a typst version for its default invocation
  • the default behavior of typst-test may diverge from the user's installed typst compiler on a version mismatch
  • massively increased dependency tree and binary size
  • increased complexity of the implementation
    • many implementations will have to be copied verbatim from typst-cli to ensure the same world behavior

Generate better diff images

When generating a diff image, the following things could be improved:

  • generate diff images on a page size mismatch (#8)
  • highlight changes, bounding boxes of small change sets can be created very easily using a border finding algorithm (see for example Suzuki and Abe 1)
  • highlight which kind of change it is
    • red: deletion from reference to output
    • green: addition from reference to output
  • overlay these boxes on the output or reference image to make it easier to visually compare

Footnotes

  1. https://www.nevis.columbia.edu/~vgenty/public/suzuki_et_al.pdf โ†ฉ

Allow custom default tests

Currently whenever a new test is created it is populated with "Hello World!". I then have to copy and paste in the package's import statement and other setup which is common to all tests I want to run.

I would like a way to change the default test on a per project basis.

Rework and cleanup core implementation

The current implementation is a little brittle, this has a lot of downsides:

  • error reporting is sometimes done using ?, other times it's swallowed and simply printed to stdout
  • some actually likely error cases are not properly handled and result in a simple error message with no hint
  • as it currently is, reporting a nonzero exit code on test failure would need an ugly hack
    • this is currently the primary blocker for adoption of typst-test in cetz and in code bases which test using CI in general

The core should be reworked into a solid foundation on which new features can be built. At this stage, the project is still fairly small, and a rewrite is feasible.

I want to achieve the following goals with the rewrite:

  • Abstract user facing reporting sufficiently to allow in place progress per test for multiple tests
  • Properly handle common error cases better
  • Make code easier to follow and reason about
  • Make code, which depends on FS operations, easier to test automatically
  • Abstract the testing in a way that makes separation into a core library and cli frontend easier down the line

Extract core behavior into a library crate

By extracting the core implementation of test scaffolding and test running, other projects such as typst-lsp and typst-preview could benefit from it without needing to interface with the bare bones binary interface.

Typst-preview already supports a special presentation mode for polylux, it's not too far-fetched to assume they could be interested in a special test-watching mode. Likewise, typst-lsp could allow discovering and running tests easily.

This is blocked by #12.

Custom user actions

Allow users to run custom actions between test stages.

On compelling use case for this is being able to test typstfmt (see #3). This avoids pulling it in as a dependency or even tying it to a command line option of typst-test at all.

With sufficiently flexible custom actions, typstfmt could generate the references from the unaltered test script and the output from the altered version, failing if the formatting introduce a visual regression.

Testing formatters

Looks really nice!

Maybe it could be use to test formatters as well!

Given a formatter and a test file

  • Tests that the compilation gives the same result before and after formatting
  • Else pinpoints where it broke the code file
    Apply diffs with dichotomy and test the output, it's a bit of a headache to implement because the diff types I used were hard to understand I think

It could happily live next to typstfmt when I get up to it but I think it might be better suited in typst-test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.