Skip to content

Commit

Permalink
raise error if dep exists; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelru committed Jun 24, 2024
1 parent bc6ed21 commit b90ae5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/desc_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ desc_add_extra_deps <- function(d, x) {
if (length(x)) {
for (x_i in trimws(strsplit(x, "\\;")[[1]])) {
x_i_deparsed <- deparse_dep_str(x_i)
if (any(d$get_deps()$package == x_i_deparsed$package)) {
stop("Cannot add extra dependency '", x_i_deparsed$package, "' as it already exists in DESCRIPTION file.")
}
d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str)
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-desc_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ test_that("desc_remotes_cleanup accepts no Config/Need/verdepcheck", {
expect_contains(clean_d$get_remotes(), "tidyverse/dplyr@*release")
})

test_that("desc_add_extra_deps will add extra dependencies", {
d <- desc::desc("!new")
d <- desc_add_extra_deps(d, "foo (>= 1.2.3)")
expect_contains(d$get_deps(), data.frame(type = "Imports", package = "foo", version = ">= 1.2.3"))
})

test_that("desc_add_extra_deps raises error for already existing package", {
d <- desc::desc("!new")
d$set_dep("foo", "Imports", ">= 1.2.3")
expect_error(desc_add_extra_deps(d, "foo (>= 1.2.3)"), "already exists")
})

test_that("get_desc_field_pkgs allows for no Config/Needs/verdepcheck", {
d <- desc::desc(
file = verdepcheck:::local_description(
Expand Down

0 comments on commit b90ae5f

Please sign in to comment.