From 57600bb13ee4fbfa765e6e885438b2cf8bb358fe Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Fri, 4 Sep 2026 09:53:03 -0700 Subject: [PATCH] test: skip image snapshots when raster is not installed The image snapshots in test-Plot-snapshots.R were recorded with the full Suggests set installed, and they are not portable to a run without it -- not because the rendering differs, but because the *names* do. Several tests build a `rasts` list and then double its length inside `if (requireNamespace("raster", quietly = TRUE))`. Snapshot file names come from `fn()` (helper-testInit.R), which pulls from a running `counter` over those lists. Drop `raster` and every list shortens, so each name after the first raster block lines up against a different plot. "internal functions in Plot" additionally computes `val <- (testNum - 1) %% (length(rasts) / 2) + 1`, hard-coding the doubling, so without raster it renders plots 1 and 2 twice and never renders 3 or 4. This is exactly the `_R_CHECK_DEPENDS_ONLY_` leg that PredictiveEcology/actions' shared R-CMD-check matrix runs: 11 failures there, all in this file, all of them a reference image compared against the wrong plot. Maintaining a second set of reference images for that configuration would be a lot of pixels for no extra signal, so skip the image comparisons when raster is absent. The nosuggests leg keeps its real purpose -- the package loads and its non-image tests pass without Suggests. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB --- tests/testthat/test-Plot-snapshots.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/testthat/test-Plot-snapshots.R b/tests/testthat/test-Plot-snapshots.R index 381647a..7dcb92a 100644 --- a/tests/testthat/test-Plot-snapshots.R +++ b/tests/testthat/test-Plot-snapshots.R @@ -1,6 +1,17 @@ +## The image snapshots in this file were all recorded with the full Suggests set +## installed, and `raster` in particular changes what gets recorded: several +## tests double the length of their `rasts` list when `raster` is available, and +## snapshot file names come from a running `counter` over those lists (see `fn()` +## in helper-testInit.R). With `raster` absent -- as on the `_R_CHECK_DEPENDS_ONLY_` +## CI leg -- the same names line up against different plots, so every snapshot +## after the first `requireNamespace("raster")` block compares the wrong image. +## Rather than maintain a second set of reference images, skip the image tests +## when `raster` is missing; the rest of the suite still exercises the package. + ## block B test_that("image content is not error-free", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) on.exit( @@ -80,6 +91,7 @@ test_that("image content is not error-free", { # # ## block C test_that("plotting colors", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) on.exit( { @@ -130,6 +142,7 @@ test_that("plotting colors", { # ## test.png 10 to 11 test_that("internal functions in Plot", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) on.exit( { @@ -208,6 +221,7 @@ test_that("internal functions in Plot", { ## block E 15 to test_that("Plot 2 is not error-free", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) on.exit( { @@ -462,6 +476,7 @@ test_that("setColors is not error-free", { # block G test_that("Plot with base is not error-free", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) on.exit( { @@ -584,6 +599,7 @@ test_that("Plot messages and warnings and errors", { ## block I test_that("rePlot doesn't work", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) for (os in oses) { fil <- fn(tmpdir, desc, counter, os, envir = envirHere) @@ -640,6 +656,7 @@ test_that("Plot - going through package coverage", { # block K test_that("Plot lists", { prevLastPlotNumber <- 48 + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) clearPlot() @@ -751,6 +768,7 @@ test_that("Plot functions NOT in quickPlot, i.e. redefining Plot", { }) test_that("Issue 20; arr working", { + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) files <- dir(system.file("maps", package = "quickPlot"), full.names = TRUE, pattern = "tif") @@ -775,6 +793,7 @@ test_that("Issue 20; arr working", { test_that("Issue 32 Plot factors lower case id", { prevLastPlotNumber <- 51 + skip_if_not_installed("raster") testInit("terra", opts = list(quickPlot.verbose = TRUE), dev = FALSE) for (colPalette in 1:2) {