diff --git a/DESCRIPTION b/DESCRIPTION index ee7fbe2..fc01758 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pkgstats Title: Metrics of R Packages -Version: 0.2.0.041 +Version: 0.2.0.046 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/cran-data-fn-names.R b/R/cran-data-fn-names.R index 769b64b..8667e83 100644 --- a/R/cran-data-fn-names.R +++ b/R/cran-data-fn-names.R @@ -159,6 +159,8 @@ pkgstats_fns_from_archive <- function (path, #' #' @family archive #' @export + +# nocov start pkgstats_fns_update <- function (prev_results = NULL, results_file = NULL, chunk_size = 1000L, @@ -253,3 +255,4 @@ pkgstats_fns_update <- function (prev_results = NULL, invisible (out) } +# nocov end diff --git a/R/cran-data-update.R b/R/cran-data-update.R index 2db4f1b..2ffde9f 100644 --- a/R/cran-data-update.R +++ b/R/cran-data-update.R @@ -11,6 +11,8 @@ RELEASE_TAG <- "v0.1.6" #' @return Local path to directory containing updated results. #' @family archive #' @export + +# nocov start pkgstats_update <- function (upload = TRUE) { requireNamespace ("callr") @@ -102,6 +104,7 @@ pkgstats_update <- function (upload = TRUE) { ) } } +# nocov end dl_prev_data <- function (results_path, what = "all") { what <- match.arg (what, c ("all", "current", "fn_names")) diff --git a/codemeta.json b/codemeta.json index c92f109..1c772d1 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/pkgstats", "issueTracker": "https://github.com/ropensci-review-tools/pkgstats/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.2.0.041", + "version": "0.2.0.046", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-cran-update.R b/tests/testthat/test-cran-update.R new file mode 100644 index 0000000..777fe84 --- /dev/null +++ b/tests/testthat/test-cran-update.R @@ -0,0 +1,115 @@ +test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true") | + identical (Sys.getenv ("GITHUB_WORKFLOW"), "test-coverage")) + +skip_if (!test_all) + +test_that ("cran data update functions", { + + results_path <- fs::path (fs::path_temp (), "pkgstats-data") + fs::dir_create (results_path) + + f <- dl_prev_data (results_path, what = "current") + expect_type (f, "character") + expect_length (f, 1L) + expect_true (fs::file_exists (f)) + + x <- readRDS (f) + expect_s3_class (x, "data.frame") + expect_equal (ncol (x), 95L) + expect_true (nrow (x) > 20000L) + + expect_silent ( + check_prev_results (x) + ) + + new <- list_new_cran_updates (x) + expect_type (new, "character") + if (length (new) > 0L) { + expect_true (all (grepl ("\\_[0-9]", new))) + } + + fs::dir_delete (results_path) +}) + +test_that ("download tarball", { + + pkg <- "odbc" + u <- paste0 ("https://cran.r-project.org/package=", pkg) + qry <- httr2::request (u) + resp <- httr2::req_perform (qry) + # No 'xml' or 'rvest' here, so process as raw text: + b <- httr2::resp_body_string (resp) + b <- strsplit (b, ",\\s") [[1]] + tarball <- grep ("\\.tar\\.gz", b, value = TRUE) + ptn <- "odbc\\_[0-9]\\.[0-9]\\.[0-9]\\.tar\\.gz" + tarball <- regmatches (tarball, regexpr (ptn, tarball)) + tarball <- gsub ("\\.tar\\.gz$", "", tarball) + + results_path <- fs::path (fs::path_temp (), "pkgstats-data") + fs::dir_create (results_path) + + path <- dl_one_tarball (results_path, tarball) + expect_true (fs::file_exists (path)) + + fs::dir_delete (results_path) +}) + +# Some pkgs define an "exportPattern" in the namespace, and use that to define +# exported functions. These call the separate `aliases_from_rd()` function, +# which is covered in these tests. The selected package was identified using +# the following code: +# +# flist <- fs::dir_ls (path_to_tarballs, regexp = "\\.tar\\.gz$") +# dat <- pbapply::pblapply (flist, function (f) { +# +# tb <- tryCatch (extract_tarball (f), error = function (e) NULL) +# ret <- NULL +# if (!is.null (tb)) { +# nmsp <- get_namespace_contents (tb) +# if (any (grepl ("exportPattern", nmsp))) { +# ret <- c (unname (f), as.character (file.size (f))) +# } +# fs::dir_delete (tb) +# } +# +# return (ret) +# }) +# dat <- do.call (rbind, dat) +# rownames (dat) <- NULL +# dat <- data.frame (pkg = basename (dat [, 1]), size = as.numeric (dat [, 2])) +# dat <- dat [order (dat$size), ] +# +test_that ("fn_names_from_export_ptn", { + + pkg <- "abodOutlier" + u <- paste0 ("https://cran.r-project.org/package=", pkg) + qry <- httr2::request (u) + resp <- httr2::req_perform (qry) + # No 'xml' or 'rvest' here, so process as raw text: + b <- httr2::resp_body_string (resp) + b <- strsplit (b, ",\\s") [[1]] + tarball <- grep ("\\.tar\\.gz", b, value = TRUE) + ptn <- "abodOutlier\\_[0-9]\\.[0-9]\\.tar\\.gz" + tarball <- regmatches (tarball, regexpr (ptn, tarball)) + tarball <- gsub ("\\.tar\\.gz$", "", tarball) + + results_path <- fs::path (fs::path_temp (), "pkgstats-data") + fs::dir_create (results_path) + + path <- dl_one_tarball (results_path, tarball) + expect_true (fs::file_exists (path)) + + fn_nms <- pkgstats_fn_names (path) + expect_s3_class (fn_nms, "data.frame") + expect_equal (ncol (fn_nms), 3L) + expect_equal (names (fn_nms), c ("package", "version", "fn_name")) + expect_true (nrow (fn_nms) > 0L) + + fs::dir_delete (results_path) + + pkg <- fs::path (fs::path_temp (), gsub ("\\_.*$", "", tarball)) + if (fs::dir_exists (pkg)) { + fs::dir_delete (pkg) + } + +}) diff --git a/tests/testthat/test-pkgstats.R b/tests/testthat/test-pkgstats.R index 3ce9f1c..16756b1 100644 --- a/tests/testthat/test-pkgstats.R +++ b/tests/testthat/test-pkgstats.R @@ -95,3 +95,36 @@ test_that ("pkgstats", { expect_true ("stats" %in% ext$package) expect_true (length (unique (ext$package)) > 15L) }) + +skip_if (!test_all) + +test_that ("pkgstats with tabs", { + + if (!test_all) { + Sys.setenv ("PKGSTATS_CRAN_TESTS" = "true") + } + + path <- system.file ("extdata", "pkgstats_9.9.tar.gz", package = "pkgstats") + path <- extract_tarball (path) + flist <- fs::dir_ls (fs::path (path, "R"), type = "file", recurse = TRUE) + f <- flist [which (basename (flist) == "loc.R")] + x <- readLines (f) + x <- gsub ("^\\s{12}", "\\\t\\\t\\\t", x) + x <- gsub ("^\\s{8}", "\\\t\\\t", x) + x <- gsub ("^\\s{4}", "\\\t", x) + writeLines (x, f) + + # message is now produced once per session by readr, but can only be + # suppressed by Suggesting yet another package, `tidyselect`. + # expect_message ( + s <- pkgstats (path) + + if (!test_all) { + Sys.unsetenv ("PKGSTATS_CRAN_TESTS") + } + + expect_s3_class (s$loc, "tbl_df") + expect_true (s$loc$ntabs [s$loc$dir == "R"] > 0L) + + fs::dir_delete (path) +})