Skip to content

Commit e3fb4a5

Browse files
committed
Mask current rextendr version in snapshot tests
1 parent 6c53282 commit e3fb4a5

6 files changed

+19
-14
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rextendr
22
Title: Call Rust Code from R using the 'extendr' Crate
33
Version: 0.3.1.9001
4-
Authors@R:
4+
Authors@R:
55
c(person(given = "Claus O.",
66
family = "Wilke",
77
role = "aut",

tests/testthat/_snaps/use_cran_defaults.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use_extendr()
55
Message
66
i First time using rextendr. Upgrading automatically...
7-
i Setting `Config/rextendr/version` to "0.3.1.9001" in the 'DESCRIPTION' file.
7+
i Setting `Config/rextendr/version` to "*.*.*" in the 'DESCRIPTION' file.
88
i Setting `SystemRequirements` to "Cargo (Rust's package manager), rustc" in the 'DESCRIPTION' file.
99
v Creating 'src/rust/src'.
1010
v Writing 'src/entrypoint.c'

tests/testthat/_snaps/use_extendr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use_extendr()
55
Message
66
i First time using rextendr. Upgrading automatically...
7-
i Setting `Config/rextendr/version` to "0.3.1.9001" in the 'DESCRIPTION' file.
7+
i Setting `Config/rextendr/version` to "*.*.*" in the 'DESCRIPTION' file.
88
i Setting `SystemRequirements` to "Cargo (Rust's package manager), rustc" in the 'DESCRIPTION' file.
99
v Creating 'src/rust/src'.
1010
v Writing 'src/entrypoint.c'

tests/testthat/helper.R

+13
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ skip_if_opted_out_of_dev_tests <- function() {
112112
testthat::skip("Dev extendr tests disabled")
113113
}
114114
}
115+
116+
#' Mask any version in snapshot files
117+
#' @param snapshot_lines Character vector, lines of the snapshot file
118+
#' @example
119+
#' expect_snapshot(some_operation(), transform = mask_any_version)
120+
#' @noRd
121+
mask_any_version <- function(snapshot_lines) {
122+
stringi::stri_replace_all_regex(
123+
snapshot_lines,
124+
"\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?",
125+
"*.*.*"
126+
)
127+
}

tests/testthat/test-use_cran_defaults.R

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_that("use_cran_defaults() modifies and creates files correctly", {
44
path <- local_package("testpkg")
55
# capture setup messages
66
withr::local_options(usethis.quiet = FALSE)
7-
expect_snapshot(use_extendr())
7+
expect_snapshot(use_extendr(), transform = mask_any_version)
88
expect_snapshot(use_cran_defaults())
99

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

2727

2828
test_that("vendor_pkgs() vendors dependencies", {
29-
mask_version_strings <- function(snapshot_lines) {
30-
stringi::stri_replace_all_regex(
31-
snapshot_lines,
32-
"\\d+\\.\\d+\\.\\d+",
33-
"*.*.*"
34-
)
35-
}
36-
3729
skip_if_not_installed("usethis")
3830

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

4537
package_versions <- vendor_pkgs(path, quiet = TRUE)
4638
expect_snapshot(cat_file("src", "rust", "vendor-config.toml"))
47-
expect_snapshot(package_versions, transform = mask_version_strings)
39+
expect_snapshot(package_versions, transform = mask_any_version)
4840
expect_true(file.exists(file.path("src", "rust", "vendor.tar.xz")))
4941
})

tests/testthat/test-use_extendr.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_that("use_extendr() sets up extendr files correctly", {
44
path <- local_package("testpkg")
55
# capture setup messages
66
withr::local_options(usethis.quiet = FALSE)
7-
expect_snapshot(use_extendr())
7+
expect_snapshot(use_extendr(), transform = mask_any_version)
88

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

0 commit comments

Comments
 (0)