Skip to content

Commit

Permalink
Mask current rextendr version in snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia-Kosenkov committed Sep 8, 2024
1 parent 6c53282 commit e3fb4a5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rextendr
Title: Call Rust Code from R using the 'extendr' Crate
Version: 0.3.1.9001
Authors@R:
Authors@R:
c(person(given = "Claus O.",
family = "Wilke",
role = "aut",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/use_cran_defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use_extendr()
Message
i First time using rextendr. Upgrading automatically...
i Setting `Config/rextendr/version` to "0.3.1.9001" in the 'DESCRIPTION' file.
i Setting `Config/rextendr/version` to "*.*.*" in the 'DESCRIPTION' file.
i Setting `SystemRequirements` to "Cargo (Rust's package manager), rustc" in the 'DESCRIPTION' file.
v Creating 'src/rust/src'.
v Writing 'src/entrypoint.c'
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use_extendr()
Message
i First time using rextendr. Upgrading automatically...
i Setting `Config/rextendr/version` to "0.3.1.9001" in the 'DESCRIPTION' file.
i Setting `Config/rextendr/version` to "*.*.*" in the 'DESCRIPTION' file.
i Setting `SystemRequirements` to "Cargo (Rust's package manager), rustc" in the 'DESCRIPTION' file.
v Creating 'src/rust/src'.
v Writing 'src/entrypoint.c'
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ skip_if_opted_out_of_dev_tests <- function() {
testthat::skip("Dev extendr tests disabled")
}
}

#' Mask any version in snapshot files
#' @param snapshot_lines Character vector, lines of the snapshot file
#' @example
#' expect_snapshot(some_operation(), transform = mask_any_version)
#' @noRd
mask_any_version <- function(snapshot_lines) {
stringi::stri_replace_all_regex(
snapshot_lines,
"\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?",
"*.*.*"
)
}

Check warning on line 127 in tests/testthat/helper.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/helper.R,line=127,col=2,[trailing_blank_lines_linter] Missing terminal newline.
12 changes: 2 additions & 10 deletions tests/testthat/test-use_cran_defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("use_cran_defaults() modifies and creates files correctly", {
path <- local_package("testpkg")
# capture setup messages
withr::local_options(usethis.quiet = FALSE)
expect_snapshot(use_extendr())
expect_snapshot(use_extendr(), transform = mask_any_version)
expect_snapshot(use_cran_defaults())

expect_snapshot(cat_file("src", "Makevars"))
Expand All @@ -26,14 +26,6 @@ test_that("use_cran_defaults() quiet if quiet=TRUE", {


test_that("vendor_pkgs() vendors dependencies", {
mask_version_strings <- function(snapshot_lines) {
stringi::stri_replace_all_regex(
snapshot_lines,
"\\d+\\.\\d+\\.\\d+",
"*.*.*"
)
}

skip_if_not_installed("usethis")

path <- local_package("testpkg")
Expand All @@ -44,6 +36,6 @@ test_that("vendor_pkgs() vendors dependencies", {

package_versions <- vendor_pkgs(path, quiet = TRUE)
expect_snapshot(cat_file("src", "rust", "vendor-config.toml"))
expect_snapshot(package_versions, transform = mask_version_strings)
expect_snapshot(package_versions, transform = mask_any_version)
expect_true(file.exists(file.path("src", "rust", "vendor.tar.xz")))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("use_extendr() sets up extendr files correctly", {
path <- local_package("testpkg")
# capture setup messages
withr::local_options(usethis.quiet = FALSE)
expect_snapshot(use_extendr())
expect_snapshot(use_extendr(), transform = mask_any_version)

# DESCRITION file
version_in_desc <- stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", path)[[1]])
Expand Down

0 comments on commit e3fb4a5

Please sign in to comment.