diff --git a/DESCRIPTION b/DESCRIPTION index cdc19f97..68ecc894 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,7 +44,7 @@ Imports: cli, desc, dplyr, - glue, + glue (>= 1.7.0), jsonlite, pkgbuild (>= 1.4.0), processx, diff --git a/R/toml_serialization.R b/R/toml_serialization.R index e1218748..28af737e 100644 --- a/R/toml_serialization.R +++ b/R/toml_serialization.R @@ -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 diff --git a/tests/testthat/_snaps/use_cran_defaults.md b/tests/testthat/_snaps/use_cran_defaults.md index aa9b6355..84e5994e 100644 --- a/tests/testthat/_snaps/use_cran_defaults.md +++ b/tests/testthat/_snaps/use_cran_defaults.md @@ -186,13 +186,13 @@ # A tibble: 9 x 2 crate version - 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 *.*.* diff --git a/tests/testthat/test-use_cran_defaults.R b/tests/testthat/test-use_cran_defaults.R index 83ee5ad3..08185f02 100644 --- a/tests/testthat/test-use_cran_defaults.R +++ b/tests/testthat/test-use_cran_defaults.R @@ -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") @@ -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"))) })