slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.56k stars 604 forks source link

Tests for the renderers #1509

Closed ogoffart closed 1 year ago

ogoffart commented 2 years ago

Currently, we do not have any tests for the rendering. We should have tests that render images and compare theses images to make sure everything is pixel perfect.

The way I see it, we would have a folder with slint files such as

Test := Window {
    width: 80px; height: 80px;  // keep the test quite small so that rendered images don't take to much space
    GridLayout {
       // add various combination of stuff there.
    }
}

Then the test driver would render the image into .png and compare that the result is the same, (or similar enough), as the one on disk.

We would need a tool to easily compare the failing images and to easily accept the change. Maybe some kind of a dashboard that shows a list of all different image, with the two images side by side, or "blinking", with highlight over the difference. Which would allow to easily bless the differences.

We would also be able to see the difference between the different renderer (software (buffer or line by line), skia, femtovg)

Maybe in addition to just the slint file, we might need some scripting to test the result after or during animation (to make sure the partial cache works correctly)

I think it's fine for the snapshot images to be in the git repo. If we keep the image size small, their binary size should also be small enough and shouldn't be a too much of a problem, even if these file often change.

akiross commented 2 years ago

Just adding a few info that might be related or interesting for this issue.

Snapshot/conformance testing is something I've been using on a project of mine and this is one of the reasons why, some time back, I was suggesting to add headless rendering to texture/image: https://github.com/slint-ui/slint/issues/704

While my slint code has no this kind of tests, some other code has snapshot tests and I'm using https://insta.rs/ which works fine. I've been using a simple python script to show images when necessary, but it seems that insta version 1.21 has a command to show images; didn't test it though.