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/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"))) })