Skip to contents

These cases exercise two reported bugs with small, deterministic inputs. The vignette runs against the installed dependencies, which should pass both checks. The historical results below were obtained by running the same generated tests with older upstream revisions. For an introduction to recording and replaying failures, see the sample-alignment walkthrough.

Set up the cases

Use this temporary source tree to try both recipes. In your own package, put the @testCases blocks in the relevant R source files and declare the test dependencies in DESCRIPTION.

work <- tempfile("bioc-regressions-")
pkg <- file.path(work, "backendregressions")
dir.create(file.path(pkg, "R"), recursive = TRUE)
dir.create(file.path(pkg, "tests", "testthat"), recursive = TRUE)
dir.create(file.path(pkg, "longtests", "testthat"), recursive = TRUE)
writeLines(c(
  "Package: backendregressions",
  "Version: 0.0.1",
  "Encoding: UTF-8",
  "Suggests: DelayedArray, HDF5Array, Matrix, testthat (>= 3.3.0), withr",
  "Config/testthat/edition: 3"
), file.path(pkg, "DESCRIPTION"))
writeLines(character(), file.path(pkg, "NAMESPACE"))

Keep matrix attributes when the result has zero columns

DelayedArray #113 reported that multiplying an unnamed delayed matrix by a zero-column matrix returned list(NULL, NULL) as its dimension names. Base R returns NULL, which matters when downstream tests compare complete objects. A 2-by-3 input and a 3-by-0 multiplier reproduce the attribute mismatch, with a one-column multiplier as a control.

writeLines(r"(
#' @testCases delayed-matmul
#' list(
#'   cases = list("zero-columns" = list(suite = "tests")),
#'   test = {
#'     x <- matrix(1:6, nrow = 2L)
#'     y <- matrix(1:3, ncol = 1L)
#'     delayed <- DelayedArray::DelayedArray(x)
#'     expect_identical(as.matrix(delayed %*% y), x %*% y)
#'     empty <- y[, integer(), drop = FALSE]
#'     expect_identical(as.matrix(delayed %*% empty), x %*% empty)
#'   }
#' )
NULL
)", file.path(pkg, "R", "delayed-matmul.R"))

Preserve NaN during sparse coercion

HDF5Array #61 reported that a stored NaN survived a delayed operation and then became zero when coerced to dgCMatrix. The fix was in DelayedArray. The 2-by-2 fixture keeps a nonzero value, two structural zeros and a NaN. The test writes a real TENx HDF5 file, checks the backend and verifies the value before coercion. The final assertion compares the result to the expected dense matrix, including the missing value.

writeLines(r"(
#' @testCases tenx-coercion
#' list(
#'   cases = list("preserve-nan" = list(suite = "longtests")),
#'   test = {
#'     counts <- matrix(c(NaN, 0, 0, 2), nrow = 2L)
#'     dir <- withr::local_tempdir()
#'     file <- file.path(dir, "counts.h5")
#'     stored <- HDF5Array::writeTENxMatrix(counts, file, group = "counts")
#'     expect_s4_class(stored, "TENxMatrix")
#'     scaled <- stored * 10
#'     expect_true(is.nan(scaled[1L, 1L]))
#'     converted <- methods::as(scaled, "dgCMatrix")
#'     expect_s4_class(converted, "dgCMatrix")
#'     expect_identical(as.matrix(converted), counts * 10)
#'   }
#' )
NULL
)", file.path(pkg, "R", "tenx-coercion.R"))

Run both regressions

Generate the files and require both case IDs to complete without warnings. The HDF5 case lives in longtests to show how to keep a backend-specific check in a separate suite. Its fixture here takes little space.

invisible(roxygen2::roxygenise(
  pkg, roclets = "biocroxytest::tests_roclet", load_code = roxygen2::load_source
))
ids <- c("delayed-matmul/zero-columns", "tenx-coercion/preserve-nan")
report <- biocroxytest::run_test_plan(pkg, ids = ids, seed = 42L)
biocroxytest::check_test_plan(report, required = ids)
report$cases[c("id", "suite", "status")]
##                            id     suite    status
## 1 delayed-matmul/zero-columns     tests completed
## 2  tenx-coercion/preserve-nan longtests completed

Results on historical revisions

Each pair used separate libraries on macOS arm64 with R 4.4.3 and Bioconductor 3.20 dependencies, including S4Arrays 1.6.0 and SparseArray 1.6.2. Only DelayedArray changed within each pair. For the HDF5 case, both runs used HDF5Array 1.33.5 (revision 12fae3d).

Case DelayedArray revision that failed Observed mismatch DelayedArray revision that passed
delayed-matmul/zero-columns 0.29.7 (854795f) Dimension names were a list of two NULLs 0.29.8 (7edde30)
tenx-coercion/preserve-nan 0.31.9 (5afb60e) Coercion replaced NaN with 0 0.31.10 (1689c0f)

To repeat a historical failure, install the linked revision in an isolated library with its dependencies and start a fresh R session with that library first. Run the setup, case and generation chunks above, then use the chunk below in place of the current-dependency check. Set id to the case from the table and compare the printed diagnostic to that row. To replay in a later session, use a persistent work directory in the setup and keep it together with the versioned library. Replay restores the case’s seed and checks the source revision. The evidence records dependency versions for comparison.

id <- "tenx-coercion/preserve-nan"
failed <- biocroxytest::run_test_plan(pkg, ids = id, seed = 42L)
stopifnot(identical(failed$cases$status, "failed"))
cat(failed$cases$detail, "\n")

record <- file.path(work, "failure.rds")
biocroxytest::write_test_replay(failed, id, record)
replayed <- biocroxytest::replay_test_case(record, path = pkg)
stopifnot(isTRUE(replayed$comparison$same_failure))

Both historical failures replayed with matching signatures. To check a fix, run run_test_plan(pkg, ids = id) in the fixed library and pass its report to check_test_plan(report, required = id). The reduction here was manual. The named tests reuse the same small inputs and assertions across versions and distinguish an incorrect result from a case that could not run.

unlink(work, recursive = TRUE, expand = FALSE)