Skip to content

Commit

Permalink
Fix keyword in getCranPackageDatabase()
Browse files Browse the repository at this point in the history
and prove that this function returns exactly
the same as tools::CRAN_package_db()
  • Loading branch information
hsonne committed May 3, 2024
1 parent dd1df74 commit 9556248
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
9 changes: 8 additions & 1 deletion R/cran_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ currentCranVersion <- function(name)
#' @export
getCranPackageDatabase <- function()
{
readRDS(file(getUrl("cran_packages", package = "packages.rds")))
url <- getUrl("cran_package", package = "packages.rds")

system.time(db1 <- as.data.frame(readRDS(file(url))))

#system.time(db2 <- tools::CRAN_package_db())
#stopifnot(identical(db1, db2))

db1
}

# isOnCran ---------------------------------------------------------------------
Expand Down
33 changes: 5 additions & 28 deletions tests/testthat/test-function-getCranPackageDatabase.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
#
# This file was generated by kwb.test::create_test_files(),
# launched by hsonne on 2024-05-02 17:58:26.
# Please modify the dummy functions so that real cases are
# tested. Then, delete this comment.
#
#library(testthat)

test_that("getCranPackageDatabase() works", {

f <- kwb.package::getCranPackageDatabase

expect_error(
f()
# No such element in list 'urls':
# - 'cran_packages'
# Available elements (sorted):
# - 'cached_desc'
# - 'cran'
# - 'cran_archive'
# - 'cran_archive_file'
# - 'cran_contrib'
# - 'cran_package'
# - 'cran_package_file'
# - 'cran_rstudio'
# - 'github_api'
# - 'github_desc'
# - 'github_raw'
# - 'github_releases'
# - 'github_tags'
# - 'mran_snapshot'
# - 'package_filename'
#
)
result <- f()

expect_s3_class(result, "data.frame")
expect_true(all(c("Package", "Depends", "Imports") %in% names(result)))

})

0 comments on commit 9556248

Please sign in to comment.