Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tolerate empty fields in Depends #152

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# desc (development version)

* An empty `Depends` field is now properly normalized and formatted.
(#148, @kevinushey)

# desc 1.4.3

* `$set()` and `desc_set()` now can omit checks if `check = FALSE`
Expand Down
3 changes: 2 additions & 1 deletion R/deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ parse_deps <- function(type, deps) {
deps <- str_trim(strsplit(deps, ",")[[1]])
deps <- lapply(strsplit(deps, "\\("), str_trim)
deps <- lapply(deps, sub, pattern = "\\)$", replacement = "")
deps <- deps[vapply(deps, function(x) length(x) != 0, FUN.VALUE = logical(1))]
res <- data.frame(
stringsAsFactors = FALSE,
type = if (length(deps)) type else character(),
package = vapply(deps, "[", "", 1),
version = vapply(deps, "[", "", 2)
)
res$version <- gsub("\\s+", " ", res$version)
res$version [ is.na(res$version) ] <- "*"
res$version[is.na(res$version)] <- "*"
res
}

Expand Down
4 changes: 2 additions & 2 deletions R/str.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ format.DescriptionField <- function(x, ..., width = 75) {

format.DescriptionDependencyList <- function(x, ...) {
paste0(
cli::col_blue(x$key), ":\n",
paste0(
cli::col_blue(x$key), if (nzchar(x$value)) ":\n" else ":",
if (nzchar(x$value)) paste0(
" ",
sort(str_trim(strsplit(color_bad(x), ",", fixed = TRUE)[[1]])),
collapse = ",\n"
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,19 @@ test_that("extra whitespace is removed from deps, but kept in raw data", {
fixed = TRUE
)
})

test_that("empty fields are accepted during normalization", {

x <- desc("!new")
x$set("Depends", "")
x$normalize()
expect_equal(x$get("Depends"), c(Depends = ""))

file <- tempfile("desc-")
on.exit(unlink(file), add = TRUE)
x$write(file)
d <- desc(file)

expect_equal(d$get("Depends"), c(Depends = ""))

})
Loading