Skip to content

Commit

Permalink
Fix snapshot tests (#334)
Browse files Browse the repository at this point in the history
* Mask versions to stabilize test

* Update snapshot

* Fix new line issue

* Require latest {glue}
  • Loading branch information
Ilia-Kosenkov authored Jan 12, 2024
1 parent edc5476 commit 596ae98
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Imports:
cli,
desc,
dplyr,
glue,
glue (>= 1.7.0),
jsonlite,
pkgbuild (>= 1.4.0),
processx,
Expand Down
4 changes: 4 additions & 0 deletions R/toml_serialization.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ to_toml <- function(...,
.format_dbl = .format_dbl
)
body <- glue_collapse(body, "\n")
if (!nzchar(body)) {
body <- NULL
}

# The values can be (1) header and body, (2) header only, or (3) body only.
# In the case of (2) and (3) the other element is of length 0, so we need to
# remove them by `c()` first, and then concatenate by "\n" if both exists
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/_snaps/use_cran_defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@
# A tibble: 9 x 2
crate version
<chr> <chr>
1 extendr-api 0.6.0
2 extendr-macros 0.6.0
3 libR-sys 0.6.0
4 once_cell 1.19.0
5 paste 1.0.14
6 proc-macro2 1.0.70
7 quote 1.0.33
8 syn 2.0.42
9 unicode-ident 1.0.12
1 extendr-api *.*.*
2 extendr-macros *.*.*
3 libR-sys *.*.*
4 once_cell *.*.*
5 paste *.*.*
6 proc-macro2 *.*.*
7 quote *.*.*
8 syn *.*.*
9 unicode-ident *.*.*

10 changes: 9 additions & 1 deletion tests/testthat/test-use_cran_defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ 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 @@ -35,6 +43,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)
expect_snapshot(package_versions, transform = mask_version_strings)
expect_true(file.exists(file.path("src", "rust", "vendor.tar.xz")))
})

0 comments on commit 596ae98

Please sign in to comment.