Skip to content

Commit

Permalink
Add some snapshot test infrastructure (#610)
Browse files Browse the repository at this point in the history
Fixes #608 

This does not add a wide gamut of tests - I imagine that the
`test_scenes` will provide some good fodder here.
There are some quality-of-life features included:

- You can use `VELLO_TEST_CREATE=all` to create new tests. It is
recommended to set this on your local machine (and it won't be set on
CI)
- You can use `VELLO_TEST_UPDATE=all` to update with new contents if the
test fails. (Note that if there's a minor change which passes the test,
this won't update)

These variables can also filter to specific tests if needed.
The saved snapshots are always created using the GPU renderer, but it is
set up to be easy to use the CPU renderer for tests as well.

Using `cargo nextest` for running tests is recommended; indeed, it seems
to be now required, as the tests segfault without it
  • Loading branch information
DJMcNab authored Jul 15, 2024
1 parent d2c1195 commit b103b03
Show file tree
Hide file tree
Showing 20 changed files with 2,123 additions and 1,444 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ env:
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p vello -p vello_encoding -p vello_shaders"
# List of packages that can not target wasm.
# `vello_tests` uses `nv-flip`, which doesn't support wasm.
NO_WASM_PKGS: "--exclude vello_tests"



# Rationale
Expand Down Expand Up @@ -120,10 +124,10 @@ jobs:
tool: cargo-hack

- name: cargo clippy
run: cargo hack clippy --workspace --locked --target wasm32-unknown-unknown --each-feature --optional-deps -- -D warnings
run: cargo hack clippy --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --each-feature --optional-deps -- -D warnings

- name: cargo clippy (auxiliary)
run: cargo hack clippy --workspace --locked --target wasm32-unknown-unknown --each-feature --optional-deps --tests --benches --examples -- -D warnings
run: cargo hack clippy --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --each-feature --optional-deps --tests --benches --examples -- -D warnings

test-stable:
name: cargo test
Expand Down Expand Up @@ -164,9 +168,15 @@ jobs:
sudo add-apt-repository ppa:kisak/turtle -y
sudo apt-get update
sudo apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest

- name: cargo test
run: cargo test --workspace --locked --all-features
# TODO: Maybe use --release; the CPU shaders are extremely slow when unoptimised
run: cargo nextest run --workspace --locked --all-features
env:
VELLO_CI_GPU_SUPPORT: ${{ matrix.gpu }}

Expand All @@ -187,7 +197,7 @@ jobs:

# TODO: Find a way to make tests work. Until then the tests are merely compiled.
- name: cargo test compile
run: cargo test --workspace --locked --target wasm32-unknown-unknown --all-features --no-run
run: cargo test --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --all-features --no-run

check-stable-android:
name: cargo check (aarch64-android)
Expand Down Expand Up @@ -263,6 +273,8 @@ jobs:
tool: cargo-hack

- name: cargo check
# We don't include ${{ env.NO_WASM_PKGS }} here, because `-p foo --exclude foo` doesn't work
# and none of our `NO_WASM_PKGS` have an MSRV.
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target wasm32-unknown-unknown --each-feature --optional-deps

doc:
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ thiserror = "1.0.61"
# NOTE: Make sure to keep this in sync with the version badge in README.md and vello/README.md
wgpu = { version = "0.20.0" }
log = "0.4.21"
image = { version = "0.25.1", default-features = false }

# Used for examples
clap = "4.5.4"
anyhow = "1.0.86"
pollster = "0.3.0"
web-time = "1.1.0"
wgpu-profiler = "0.17.0"
scenes = { path = "examples/scenes" }
3 changes: 2 additions & 1 deletion examples/headless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ workspace = true

[dependencies]
vello = { workspace = true }
scenes = { path = "../scenes" }
scenes = { workspace = true }

anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ workspace = true
vello = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
image = { version = "0.25.1", default-features = false, features = ["jpeg"] }
image = { workspace = true, features = ["jpeg"] }
rand = "0.8.5"

# for pico_svg
Expand Down
6 changes: 3 additions & 3 deletions examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mod mmark;
mod pico_svg;
mod simple_text;
mod svg;
mod test_scenes;
use std::path::PathBuf;
pub mod test_scenes;

use anyhow::{anyhow, Result};
use clap::Args;
pub use images::ImageCache;
pub use simple_text::SimpleText;
use std::path::PathBuf;
pub use svg::{default_scene, scene_from_files};
pub use test_scenes::test_scenes;
use test_scenes::test_scenes;

use vello::kurbo::Vec2;
use vello::peniko::Color;
Expand Down
Loading

0 comments on commit b103b03

Please sign in to comment.