Skip to content

Commit

Permalink
add sentinel test
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 8, 2024
1 parent 8110e6f commit bcb3d2d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/testthat/_snaps/StatsandGeoms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# We do not need to update `silent_add()`.

Code
body
Output
{
if (is.null(scale)) {
return()
}
prev_aes <- self$find(scale$aesthetics)
if (any(prev_aes)) {
scalename <- self$scales[prev_aes][[1]]$aesthetics[1]
cli::cli_inform(c("Scale for {.field {scalename}} is already present.",
"Adding another scale for {.field {scalename}}, which will replace the existing scale."))
}
self$scales <- c(self$scales[!prev_aes], list(scale))
}

10 changes: 9 additions & 1 deletion tests/testthat/test-StatsandGeoms.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ test_that("Geom and Stat ggprotos are in fact ggprotos", {
expect_ggproto(StatEdgeDiagonal)
expect_ggproto(StatEdgeFan)
expect_ggproto(GeomDAGEdgePath)
expect_ggproto(ScalesListQuiet)
})

test_that("We do not need to update `silent_add()`.", {
# This is a sentinel test to see if upstream ggplot2 has made changes to
# the ggplot2:::Scales$add() method.
# If this test fails, the add method has likely changed and `silent_add()`
# may need to be updated in StatsandGeoms.R.
body <- body(environment(ggplot()$scales$add)$f)
expect_snapshot(body)
})

0 comments on commit bcb3d2d

Please sign in to comment.