Skip to content

Commit

Permalink
Improve names, implement simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed May 5, 2024
1 parent 047296a commit 6467734
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
11 changes: 8 additions & 3 deletions R/allDeps.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ allDeps <- function(
cache = list()
)
{
pkg <- loadDescriptionFromWeb(name, version)
#kwb.utils::assignPackageObjects("kwb.package");name="abc";version=NA;depth=1L;max_depth=9L;cache=list()

stopifnot(is.na(version) || identical(version, pkg$version))
description <- loadDescriptionFromWeb(name, version)

deps <- parsePackageDeps(pkg)
stopifnot(
is.na(version) ||
identical(version, selectElements(description, "version"))
)

deps <- parsePackageDeps(description)

if (inherits(deps, "try-error") || nrow(deps) == 0L) {
return(NULL)
Expand Down
10 changes: 6 additions & 4 deletions R/parsePackageDeps.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# parsePackageDeps -------------------------------------------------------------

#' @importFrom remotes standardise_dep
parsePackageDeps <- function(pkg, dependencies = NA)
parsePackageDeps <- function(description, dependencies = NA)
{
deps <- tolower(remotes::standardise_dep(dependencies))
parsed <- lapply(pkg[intersect(deps, names(pkg))], remotes_parse_deps)
rbindAll(parsed, nameColumn = "type")
types <- tolower(remotes::standardise_dep(dependencies))

description[intersect(names(description), types)] %>%
lapply(remotes_parse_deps) %>%
rbindAll(nameColumn = "type")
}
13 changes: 3 additions & 10 deletions tests/testthat/test-function-allDeps.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#
# This file was generated by kwb.test::create_test_files(),
# launched by hsonne on 2024-05-02 17:58:25.
# Please modify the dummy functions so that real cases are
# tested. Then, delete this comment.
#
#library(testthat)

test_that("allDeps() works", {

f <- kwb.package:::allDeps

expect_error(
f()
# Argument "name" fehlt (ohne Standardwert)
)
expect_error(f())

f("abc")
})
22 changes: 13 additions & 9 deletions tests/testthat/test-function-parsePackageDeps.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#
# This file was generated by kwb.test::create_test_files(),
# launched by hsonne on 2024-05-02 18:06:13.
# Please modify the dummy functions so that real cases are
# tested. Then, delete this comment.
#
#library(testthat)

test_that("parsePackageDeps() works", {

f <- kwb.package:::parsePackageDeps

expect_error(
f()
# Argument "pkg" fehlt (ohne Standardwert)
expect_error(f())

description <- list(
package = "abc",
imports = "a(>= 1.1.1), b(>= 2.1),c(>= 3)"
)

result <- f(description)

expect_s3_class(result, "data.frame")
expect_identical(nrow(result), 3L)
expect_identical(names(result), c("name", "compare", "version", "type"))
expect_true(all(result$type == "imports"))

})

0 comments on commit 6467734

Please sign in to comment.