Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variant support #147

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vdiffr (development version)

* Added support for snapshot variants (#125).


# vdiffr 1.0.7

* Revert back to C++11 to work around a GCC issue (#137).
Expand Down Expand Up @@ -95,7 +98,7 @@ a bugfix.
Font sizes are now precomputed for the first 50000 unicode points.
This allows deterministic computation of text box extents without
the freetype and harfbuzz dependencies.

Note: The main visible change of this update is that points now look
smaller. Points generated with the previous SVG engine were too large.

Expand Down
5 changes: 4 additions & 1 deletion R/expect-doppelganger.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#' Internally, this argument is passed to
#' [testthat::expect_snapshot_file()].
#'
#' @inheritParams testthat::expect_snapshot_file
#'
#' @section Debugging:
#' It is sometimes difficult to understand the cause of a failure.
Expand Down Expand Up @@ -96,7 +97,8 @@ expect_doppelganger <- function(title,
path = deprecated(),
...,
writer = write_svg,
cran = FALSE) {
cran = FALSE,
variant = NULL) {
testthat::local_edition(3)

fig_name <- str_standardise(title)
Expand Down Expand Up @@ -135,6 +137,7 @@ expect_doppelganger <- function(title,
testcase,
name = file,
cran = cran,
variant = variant,
compare = testthat::compare_file_text
),
expectation_failure = function(cnd) {
Expand Down
8 changes: 7 additions & 1 deletion man/expect_doppelganger.Rd

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

37 changes: 37 additions & 0 deletions tests/testthat/_snaps/bar/expect-doppelganger/variant.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions tests/testthat/_snaps/foo/expect-doppelganger/variant.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/testthat/test-expect-doppelganger.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ test_that("skips and unexpected errors reset snapshots (r-lib/testthat#1393)", {
expect_true(file.exists("test-snapshot/_snaps/snapshot/error-resets-snapshots.svg"))
expect_true(file.exists("test-snapshot/_snaps/snapshot/skip-resets-snapshots.svg"))
})

test_that("`expect_doppelganger()` supports variants", {
p1 <- ggplot2::ggplot()
p2 <- ggplot2::ggplot() + ggplot2::geom_histogram()
expect_doppelganger("variant", p1, variant = "foo")
expect_doppelganger("variant", p2, variant = "bar")
})
Loading