diff --git a/DESCRIPTION b/DESCRIPTION index 9d72006..a055fd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ BugReports: https://github.com/Polkas/pacs/issues Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 Depends: R (>= 3.5.0) Imports: curl, diff --git a/NAMESPACE b/NAMESPACE index 4f3d1e6..57acb7c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(match_flavors) export(pac_checkpage) export(pac_checkred) export(pac_compare_namespace) +export(pac_compare_news) export(pac_compare_versions) export(pac_deps) export(pac_deps_dev) @@ -28,6 +29,7 @@ export(pac_islast) export(pac_last) export(pac_lifeduration) export(pac_namespace) +export(pac_news) export(pac_size) export(pac_timemachine) export(pac_true_size) diff --git a/NEWS.md b/NEWS.md index e76e9c8..a716517 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,9 @@ # pacs 0.5.1.9000 +* add new functions: pac_news and pac_compare_news. Functions are NEWS file related. * update the tinyverse vignette with a new badge url. * fix a problem with app_deps on R 3.6. +* improve code base. # pacs 0.5.1 diff --git a/R/comapre.R b/R/comapre.R index 2208b84..4c5a58d 100644 --- a/R/comapre.R +++ b/R/comapre.R @@ -25,13 +25,10 @@ pac_compare_versions <- function(pac, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/") { fields <- expand_dependency(fields) - stopifnot((length(pac) == 1) && is.character(pac)) - stopifnot(is.null(old) || (length(old) == 1) && is.character(old)) - stopifnot(is.null(new) || (length(new) == 1) && is.character(new)) - stopifnot(is.character(repos)) - stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) + validate_compare_input(pac, old, new, lib.loc, repos) stopifnot(is_online()) + if (isFALSE(pac_isin(pac, repos))) { message( sprintf( @@ -101,13 +98,10 @@ pac_compare_namespace <- function(pac, new = NULL, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/") { - stopifnot((length(pac) == 1) && is.character(pac)) - stopifnot(is.null(old) || (length(old) == 1) && is.character(old)) - stopifnot(is.null(new) || (length(new) == 1) && is.character(new)) - stopifnot(is.character(repos)) - stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) + validate_compare_input(pac, old, new, lib.loc, repos) stopifnot(is_online()) + if (isFALSE(pac_isin(pac, repos))) { message( sprintf( @@ -162,3 +156,78 @@ pac_compare_namespace <- function(pac, structure(result, package = pac, old = old, new = new) } + +#' Compare NEWS files between specific CRAN packages versions +#' @description using the remote github CRAN mirror to compare NEWS files between specific packages versions. +#' @inheritParams standard_args +#' @param repos `character` vector repositories URLs to use. Used only for the validation. Default `https://cran.rstudio.com/` +#' @return `character` with NEWS content between specific versions. +#' @export +#' @examples +#' \dontrun{ +#' pacs::pac_compare_news("shiny", "1.0.0", "1.6.0") +#' # local version to newest one +#' pacs::pac_compare_news("shiny") +#' } +pac_compare_news <- function(pac, + old = NULL, + new = NULL, + lib.loc = .libPaths(), + repos = "https://cran.rstudio.com/") { + + + validate_compare_input(pac, old, new, lib.loc, repos) + stopifnot(is_online()) + + if (isFALSE(pac_isin(pac, repos))) { + return(NA) + } + + if (is.null(old)) { + stopifnot(pac %in% rownames(installed_packages(lib.loc = lib.loc))) + old <- pac_description(pac, local = TRUE)$Version + } + + if (is.null(new)) { + new <- pac_last(pac) + } + + stopifnot(utils::compareVersion(new, old) >= 0) + + if (utils::compareVersion(new, old) == 0) { + return(NA) + } + + version_pattern <- function(version) { + paste0("#.*", version) + } + + last_version <- pac_last(pac, repos = repos) + pac_news <- pac_news(pac, last_version, lib.loc = lib.loc, repos = repos) + + + old_version_reg <- regexpr(version_pattern(old), pac_news) + which_matched_old <- which(old_version_reg > 0)[1] + old_version_pos <- if (isTRUE(which_matched_old > 0)) { + which_matched_old + } else { + NA + } + + new_version_reg <- regexpr(version_pattern(new), pac_news) + which_matched_new <- which(new_version_reg > 0)[1] + new_version_pos <- if (isTRUE(which_matched_new > 0)) { + which_matched_new + } else { + NA + } + + if (is.na(old_version_pos) || is.na(new_version_pos)) { + return(NA) + } + + result <- pac_news[new_version_pos:max(c(old_version_pos - 1, 1))] + result +} + + diff --git a/R/description.R b/R/description.R index ea0ea1e..fda66c5 100644 --- a/R/description.R +++ b/R/description.R @@ -17,13 +17,7 @@ pac_description <- function(pac, local = FALSE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/") { - stopifnot((isFALSE(local)) || - (isTRUE(local) && (is.null(version) || isTRUE(utils::packageDescription(pac, lib.loc = lib.loc)$Version == version)))) - stopifnot(all(c(is.null(version), is.null(at))) || xor(!is.null(version), !is.null(at))) - stopifnot(is.null(at) || inherits(at, "Date")) - stopifnot(length(pac) == 1 && is.character(pac)) - stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) - stopifnot(is.null(version) || (length(version) == 1 && is.character(version))) + validate_pac_input(pac, version, at, local, lib.loc, repos) is_installed <- isTRUE(pac %in% rownames(installed_packages(lib.loc = lib.loc))) if ((!is_installed && local) || (!local && !is_online())) { @@ -84,12 +78,11 @@ pac_description_dcf_raw <- function(pac, version, repos = "https://cran.rstudio. silent = TRUE ) if (inherits(tt, "try-error")) { - result <- cran_archive_file(pac, version, repos, "DESCRIPTION") + result <- read_cran_file(pac, version, "DESCRIPTION", repos) } else { result <- as.list(read.dcf(ee)[1, ]) } unlink(ee) - structure(result, package = pac, version = version) } diff --git a/R/namespace.R b/R/namespace.R index 3857db6..a2d8120 100644 --- a/R/namespace.R +++ b/R/namespace.R @@ -14,13 +14,7 @@ #' pacs::pac_namespace("memoise", local = TRUE) #' } pac_namespace <- function(pac, version = NULL, at = NULL, local = FALSE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/") { - stopifnot((isFALSE(local)) || - (isTRUE(local) && (is.null(version) || isTRUE(utils::packageDescription(pac, lib.loc = lib.loc)$Version == version)))) - stopifnot(all(c(is.null(version), is.null(at))) || xor(!is.null(version), !is.null(at))) - stopifnot(is.null(at) || inherits(at, "Date")) - stopifnot(length(pac) == 1 && is.character(pac)) - stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) - stopifnot(is.null(version) || (length(version) == 1 && is.character(version))) + validate_pac_input(pac, version, at, local, lib.loc, repos) is_installed <- isTRUE(pac %in% rownames(installed_packages(lib.loc = lib.loc))) if ((!is_installed && local) || (!local && !is_online())) { @@ -86,7 +80,7 @@ pac_readnamespace_raw <- function(pac, version, repos = "https://cran.rstudio.co silent = TRUE ) if (inherits(tt, "try-error")) { - result <- cran_archive_file(pac, version, repos, "NAMESPACE") + result <- read_cran_file(pac, version, "NAMESPACE", repos) } else { result <- readLines(ee, warn = FALSE) unlink(ee) diff --git a/R/news.R b/R/news.R new file mode 100644 index 0000000..9488d3a --- /dev/null +++ b/R/news.R @@ -0,0 +1,94 @@ +#' Get NEWS for a package +#' @description Get NEWS for a package from CRAN or local +#' @inheritParams standard_args +#' @param repos `character` vector repositories URLs to use. Used only for the validation. Default `https://cran.rstudio.com/` +#' @return `character` with NEWS content. +#' @note Results are cached for 30 minutes with `memoise` package. +#' @export +#' @examples +#' \dontrun{ +#' pacs::pac_news("dplyr", version = "0.8.0") +#' pacs::pac_news("dplyr", at = as.Date("2019-02-01")) +#' } +pac_news <- function( + pac, + version = NULL, + at = NULL, + local = FALSE, + lib.loc = .libPaths(), + repos = "https://cran.rstudio.com/" +) { + + validate_pac_input(pac, version, at, local, lib.loc, repos) + + is_installed <- isTRUE(pac %in% rownames(installed_packages(lib.loc = lib.loc))) + if ((!is_installed && local) || (!local && !is_online())) { + return(NA) + } + + version_installed <- if (is_installed) { + utils::packageDescription(pac)$Version + } else { + NA + } + version_null <- is.null(version) + + if (local && is_installed && is.null(at) && (version_null || isTRUE(utils::compareVersion(version, version_installed) == 0))) { + news_name <- intersect(list.files(system.file(package = pac)), c("NEWS.md", "NEWS", "NEWS.Rmd")) + if (length(news_name) == 0) { + return(NA) + } + return(readLines(system.file(package = pac, news_name[1]), warn = FALSE)) + } else if (isTRUE(is_isin(pac, "https://cran.rstudio.com/"))) { + last_version <- pac_last(pac, repos = repos) + version <- if (!version_null) { + version + } else if (!is.null(at)) { + vv <- utils::tail(pac_timemachine(pac, at = at)$Version, 1) + if (isNA(vv) || is.null(vv)) { + return(NA) + } + vv + } else { + last_version + } + news_lines <- pac_readnews(pac, version, repos) + if (isTRUE(is.na(news_lines))) { + return(NA) + } else if (length(news_lines) == 0) { + return(NA) + } else { + return(news_lines) + } + } else { + return(NA) + } +} + + +pac_readnews_raw <- function(pac, version, repos = "https://cran.rstudio.com/") { + ee <- tempfile() + d_url <- sprintf( + "https://raw.githubusercontent.com/cran/%s/%s/NEWS", + pac, + version + ) + tt <- try( + { + suppressWarnings(utils::download.file(d_url, + destfile = ee, + quiet = TRUE + )) + }, + silent = TRUE + ) + if (inherits(tt, "try-error")) { + result <- read_cran_file(pac, version, "NEWS", repos) + } else { + result <- readLines(ee) + unlink(ee) + } + result +} + +pac_readnews <- memoise::memoise(pac_readnews_raw, cache = cachem::cache_mem(max_age = 30 * 60)) diff --git a/R/read_cran_file.R b/R/read_cran_file.R new file mode 100644 index 0000000..8b545cd --- /dev/null +++ b/R/read_cran_file.R @@ -0,0 +1,58 @@ +#' Read a file from CRAN +#' @description Read a file from CRAN package source. +#' @inheritParams standard_args +#' @keywords internal +read_cran_file <- function(pac, version, file, repos = "https://cran.rstudio.com/") { + stopifnot(is_online()) + + last_version <- pac_last(pac, repos) + + if (isTRUE(!is.null(version) && version != last_version)) { + base_url <- sprintf("https://cran.r-project.org/src/contrib/Archive/%s", pac) + } else { + base_url <- "https://cran.r-project.org/src/contrib" + version <- last_version + } + + d_url <- sprintf( + "%s/%s_%s.tar.gz", + base_url, + pac, + version + ) + + temp_tar <- tempfile(fileext = ".tar.gz") + + download <- try( + expr = { + suppressWarnings(utils::download.file(d_url, + destfile = temp_tar, + quiet = TRUE + )) + }, + silent = TRUE + ) + + if (inherits(download, "try-error")) { + result <- NA + } else { + temp_dir <- tempdir() + utils::untar(temp_tar, exdir = temp_dir) + if (file == "DESCRIPTION") { + result <- as.list(read.dcf(file.path(temp_dir, pac, "DESCRIPTION"))[1, ]) + } else if (file == "NAMESPACE") { + result <- readLines(file.path(temp_dir, pac, "NAMESPACE"), warn = FALSE) + } else if (file == "NEWS") { + news_name <- intersect(list.files(file.path(temp_dir, pac)), c("NEWS.md", "NEWS", "NEWS.Rmd")) + if (length(news_name) == 0) { + warning("NEWS file not found") + return(NA) + } + result <- readLines(file.path(temp_dir, pac, news_name[1]), warn = FALSE) + } else { + stop("Invalid file name") + } + } + unlink(temp_tar) + result +} diff --git a/R/read_github_file.R b/R/read_github_file.R new file mode 100644 index 0000000..b30c69e --- /dev/null +++ b/R/read_github_file.R @@ -0,0 +1,31 @@ +#' Read a file from a GitHub CRAN repository +#' @description Read a file from a GitHub CRAN repository. +#' @inheritParams standard_args +#' @note if the file is not found in the GitHub repository, it will try to find it in the CRAN archive. +#' @keywords internal +read_github_file <- function(pac, version, file, repos = "https://cran.rstudio.com/") { + stopifnot(is_online()) + ee <- tempfile() + d_url <- sprintf( + "https://raw.githubusercontent.com/cran/%s/%s/%s", + pac, + version, + file + ) + tt <- try( + expr = { + suppressWarnings(utils::download.file(d_url, + destfile = ee, + quiet = TRUE + )) + }, + silent = TRUE + ) + if (inherits(tt, "try-error")) { + result <- read_cran_file(pac, version, file, repos) + } else { + result <- readLines(ee) + unlink(ee) + } + result +} diff --git a/R/template_args.R b/R/template_args.R index 45b7cb9..65ce256 100644 --- a/R/template_args.R +++ b/R/template_args.R @@ -12,6 +12,7 @@ #' Default: `list(scope = character(0), flavor = NULL)` #' @param description_v `logical` if the dependencies version should be taken from description files, minimal required. By default installed versions are taken. Default: `FALSE` #' @param exclude_joint `integer` exclude packages which are dependencies of at least N other packages, not count main package dependencies. Default: `0` +#' @param file `character` file name to read. Possible values are `DESCRIPTION`, `NEWS` and `NAMESPACE`. #' @param fields `character` vector listing the types of dependencies, a subset of `c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")`. #' Character string "all" is shorthand for that vector, character string "most" for the same vector without "Enhances", character string "strong" (default) for the first three elements of that vector. #' Default: `c("Depends", "Imports", "LinkingTo")` diff --git a/R/utils.R b/R/utils.R index 9da1f5f..d85339b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -256,50 +256,6 @@ expand_dependency <- function(fields) { } } -cran_archive_file <- function(pac, version, repos, file) { - last_version <- pac_last(pac, repos) - - if (isTRUE(!is.null(version) && version != last_version)) { - base_url <- sprintf("https://cran.r-project.org/src/contrib/Archive/%s", pac) - } else { - base_url <- "https://cran.r-project.org/src/contrib" - version <- last_version - } - - d_url <- sprintf( - "%s/%s_%s.tar.gz", - base_url, - pac, - version - ) - - temp_tar <- tempfile(fileext = ".tar.gz") - - download <- try( - { - suppressWarnings(utils::download.file(d_url, - destfile = temp_tar, - quiet = TRUE - )) - }, - silent = TRUE - ) - - if (inherits(download, "try-error")) { - result <- structure(list(), package = pac, version = version) - } else { - temp_dir <- tempdir() - utils::untar(temp_tar, exdir = temp_dir) - # tabs are not acceptable - result <- switch(file, - DESCRIPTION = as.list(read.dcf(file.path(temp_dir, pac, "DESCRIPTION"))[1, ]), - NAMESPACE = readLines(file.path(temp_dir, pac, "NAMESPACE"), warn = FALSE) - ) - } - unlink(temp_tar) - result -} - read_html_table <- function(table_lines) { rr_range <- grep("]*>", table_lines) if (length(rr_range) != 2) { diff --git a/R/utils_validate.R b/R/utils_validate.R new file mode 100644 index 0000000..25a597e --- /dev/null +++ b/R/utils_validate.R @@ -0,0 +1,23 @@ + +#' validate pac input +#' @keywords internal +validate_pac_input <- function(pac, version, at, local, lib.loc, repos) { + stopifnot(length(pac) == 1 && is.character(pac)) + stopifnot(is.null(at) || inherits(at, "Date")) + stopifnot(is.null(version) || (length(version) == 1 && is.character(version))) + stopifnot(all(c(is.null(version), is.null(at))) || xor(!is.null(version), !is.null(at))) + stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) + stopifnot(is.character(repos)) + stopifnot((isFALSE(local)) || + (isTRUE(local) && (is.null(version) || isTRUE(utils::packageDescription(pac, lib.loc = lib.loc)$Version == version)))) +} + +#' validate compare input +#' @keywords internal +validate_compare_input <- function(pac, old, new, lib.loc, repos) { + stopifnot((length(pac) == 1) && is.character(pac)) + stopifnot(is.null(old) || (length(old) == 1) && is.character(old)) + stopifnot(is.null(new) || (length(new) == 1) && is.character(new)) + stopifnot(is.character(repos)) + stopifnot(is.null(lib.loc) || (all(lib.loc %in% .libPaths()) && (length(list.files(lib.loc)) > 0))) +} diff --git a/man/pac_compare_news.Rd b/man/pac_compare_news.Rd new file mode 100644 index 0000000..f1e0c7c --- /dev/null +++ b/man/pac_compare_news.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/comapre.R +\name{pac_compare_news} +\alias{pac_compare_news} +\title{Compare NEWS files between specific CRAN packages versions} +\usage{ +pac_compare_news( + pac, + old = NULL, + new = NULL, + lib.loc = .libPaths(), + repos = "https://cran.rstudio.com/" +) +} +\arguments{ +\item{pac}{\code{character} a package name.} + +\item{old}{\code{character} an old version of package, default local version. Default: \code{NULL}} + +\item{new}{\code{character} a new version of package, default newest version. Default: \code{NULL}} + +\item{lib.loc}{\code{character} vector of search paths with local packages. Default: \code{.libPaths()}} + +\item{repos}{\code{character} vector repositories URLs to use. Used only for the validation. Default \verb{https://cran.rstudio.com/}} +} +\value{ +\code{character} with NEWS content between specific versions. +} +\description{ +using the remote github CRAN mirror to compare NEWS files between specific packages versions. +} +\examples{ +\dontrun{ +pacs::pac_compare_news("shiny", "1.0.0", "1.6.0") +# local version to newest one +pacs::pac_compare_news("shiny") +} +} diff --git a/man/pac_news.Rd b/man/pac_news.Rd new file mode 100644 index 0000000..407a684 --- /dev/null +++ b/man/pac_news.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/news.R +\name{pac_news} +\alias{pac_news} +\title{Get NEWS for a package} +\usage{ +pac_news( + pac, + version = NULL, + at = NULL, + local = FALSE, + lib.loc = .libPaths(), + repos = "https://cran.rstudio.com/" +) +} +\arguments{ +\item{pac}{\code{character} a package name.} + +\item{version}{\code{character} version of a package. Default: \code{NULL}} + +\item{at}{\code{Date} from which to take the version. Default: \code{NULL}} + +\item{local}{\code{logical} if to use local repository (or newest remote packages). Default: \code{FALSE}} + +\item{lib.loc}{\code{character} vector of search paths with local packages. Default: \code{.libPaths()}} + +\item{repos}{\code{character} vector repositories URLs to use. Used only for the validation. Default \verb{https://cran.rstudio.com/}} +} +\value{ +\code{character} with NEWS content. +} +\description{ +Get NEWS for a package from CRAN or local +} +\note{ +Results are cached for 30 minutes with \code{memoise} package. +} +\examples{ +\dontrun{ +pacs::pac_news("dplyr", version = "0.8.0") +pacs::pac_news("dplyr", at = as.Date("2019-02-01")) +} +} diff --git a/man/read_cran_file.Rd b/man/read_cran_file.Rd new file mode 100644 index 0000000..b4c6b89 --- /dev/null +++ b/man/read_cran_file.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_cran_file.R +\name{read_cran_file} +\alias{read_cran_file} +\title{Read a file from CRAN} +\usage{ +read_cran_file(pac, version, file, repos = "https://cran.rstudio.com/") +} +\arguments{ +\item{pac}{\code{character} a package name.} + +\item{version}{\code{character} version of a package. Default: \code{NULL}} + +\item{file}{\code{character} file name to read. Possible values are \code{DESCRIPTION}, \code{NEWS} and \code{NAMESPACE}.} + +\item{repos}{\code{character} vector of repositories URLs to use. By default checking CRAN and newest Bioconductor per R version. Default \code{pacs::biocran_repos()}} +} +\description{ +Read a file from CRAN package source. +} +\keyword{internal} diff --git a/man/read_github_file.Rd b/man/read_github_file.Rd new file mode 100644 index 0000000..e7c4c2c --- /dev/null +++ b/man/read_github_file.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_github_file.R +\name{read_github_file} +\alias{read_github_file} +\title{Read a file from a GitHub CRAN repository} +\usage{ +read_github_file(pac, version, file, repos = "https://cran.rstudio.com/") +} +\arguments{ +\item{pac}{\code{character} a package name.} + +\item{version}{\code{character} version of a package. Default: \code{NULL}} + +\item{file}{\code{character} file name to read. Possible values are \code{DESCRIPTION}, \code{NEWS} and \code{NAMESPACE}.} + +\item{repos}{\code{character} vector of repositories URLs to use. By default checking CRAN and newest Bioconductor per R version. Default \code{pacs::biocran_repos()}} +} +\description{ +Read a file from a GitHub CRAN repository. +} +\note{ +if the file is not found in the GitHub repository, it will try to find it in the CRAN archive. +} +\keyword{internal} diff --git a/man/standard_args.Rd b/man/standard_args.Rd index bd93dc7..779950c 100644 --- a/man/standard_args.Rd +++ b/man/standard_args.Rd @@ -23,6 +23,8 @@ Default: \code{list(scope = character(0), flavor = NULL)}} \item{exclude_joint}{\code{integer} exclude packages which are dependencies of at least N other packages, not count main package dependencies. Default: \code{0}} +\item{file}{\code{character} file name to read. Possible values are \code{DESCRIPTION}, \code{NEWS} and \code{NAMESPACE}.} + \item{fields}{\code{character} vector listing the types of dependencies, a subset of \code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")}. Character string "all" is shorthand for that vector, character string "most" for the same vector without "Enhances", character string "strong" (default) for the first three elements of that vector. Default: \code{c("Depends", "Imports", "LinkingTo")}} diff --git a/man/validate_compare_input.Rd b/man/validate_compare_input.Rd new file mode 100644 index 0000000..f72794f --- /dev/null +++ b/man/validate_compare_input.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_validate.R +\name{validate_compare_input} +\alias{validate_compare_input} +\title{validate compare input} +\usage{ +validate_compare_input(pac, old, new, lib.loc, repos) +} +\description{ +validate compare input +} +\keyword{internal} diff --git a/man/validate_pac_input.Rd b/man/validate_pac_input.Rd new file mode 100644 index 0000000..d6da3c6 --- /dev/null +++ b/man/validate_pac_input.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_validate.R +\name{validate_pac_input} +\alias{validate_pac_input} +\title{validate pac input} +\usage{ +validate_pac_input(pac, version, at, local, lib.loc, repos) +} +\description{ +validate pac input +} +\keyword{internal} diff --git a/tests/testthat/test-compare.R b/tests/testthat/test-compare.R index 3664783..d8aa1f0 100644 --- a/tests/testthat/test-compare.R +++ b/tests/testthat/test-compare.R @@ -41,3 +41,18 @@ test_that("pacs::pac_comapre_namespace offline", { mockery::stub(pac_compare_namespace_offline, "is_online", FALSE) expect_error(pac_compare_namespace_offline("memoise", "0.2.1", "2.0.0"), "is_online\\(\\) is not TRUE") }) + + +test_that("pacs::pac_compare_news", { + skip_if_offline() + expect_identical(pac_compare_news("memoise", "2.0.0", "22.4.0"), NA) + expect_error(pac_compare_news("memoise", "22.8.0", "22.4.0"), "compareVersion") + expect_identical(pac_compare_news("WRONG"), NA) +}) + +test_that("pacs::pac_compare_news online", { + skip_if_offline() + expect_true(length(pac_compare_news("dplyr", "0.7.1", "1.0.0")) > 0) + expect_true(length(pac_compare_news("memoise", old = "1.0.0")) > 0) + expect_true(length(pac_compare_news("memoise", "1.0.0", "2.0.0")) > 0) +}) diff --git a/tests/testthat/test-description.R b/tests/testthat/test-description.R index 2b16723..0f89059 100644 --- a/tests/testthat/test-description.R +++ b/tests/testthat/test-description.R @@ -1,12 +1,3 @@ -test_that("cran_archive_file", { - skip_if_offline() - expect_true(length(cran_archive_file("dplyr", "1.0.0", "https://cran.rstudio.com/", "DESCRIPTION")) == 22) - expect_identical( - cran_archive_file("dplyr", "0.0.0.1", "https://cran.rstudio.com/", "DESCRIPTION"), - structure(list(), package = "dplyr", version = "0.0.0.1") - ) -}) - test_that("pacs::pac_description", { skip_if_offline() expect_true(length(pac_description("dplyr", version = "0.8.0")) == 23) @@ -14,7 +5,7 @@ test_that("pacs::pac_description", { pac_description("memoise", local = TRUE)$Version, pac_description("memoise", local = FALSE)$Version ) %in% c(0, -1)) - expect_identical(pac_description("dplyr", "1.1.1.1"), NA) + expect_identical(pac_description("dplyr", "10.1.1.1"), NA) expect_identical(pac_description("WRONG"), NA) expect_identical(pac_description("WRONG", local = TRUE), NA) expect_identical(pac_description("dplyr", "0.0.0.1"), NA) diff --git a/tests/testthat/test-namespace.R b/tests/testthat/test-namespace.R index 380d85e..2d094da 100644 --- a/tests/testthat/test-namespace.R +++ b/tests/testthat/test-namespace.R @@ -8,8 +8,8 @@ test_that("pac_parse_namespace", { test_that("pacs::pac_namespace", { skip_if_offline() - expect_identical(pac_readnamespace_raw("dplyr", "0.0.0.0.1"), structure(list(), package = "dplyr", version = "0.0.0.0.1")) - expect_true(length(cran_archive_file("dplyr", "0.8.0", repos = "https://cran.rstudio.com/", "NAMESPACE")) == 498) + expect_identical(pac_readnamespace_raw("dplyr", "0.0.0.0.1"), structure(NA, package = "dplyr", version = "0.0.0.0.1")) + expect_true(length(read_cran_file("dplyr", "0.8.0", repos = "https://cran.rstudio.com/", "NAMESPACE")) == 498) expect_true(length(pac_namespace("dplyr", version = "0.8.0")) == 10) expect_identical(sort(pac_namespace("memoise", local = TRUE)$exports), sort(base::getNamespaceExports("memoise"))) expect_identical(pac_namespace("dplyr", "1.1.1.1"), NA) diff --git a/tests/testthat/test-news.R b/tests/testthat/test-news.R new file mode 100644 index 0000000..e08b624 --- /dev/null +++ b/tests/testthat/test-news.R @@ -0,0 +1,12 @@ +test_that("valid input pacs::pac_news", { + skip_if_offline() + expect_true(is.character(pac_news("dplyr", version = "0.8.0"))) + expect_true(is.character(pac_news("dplyr", at = as.Date("2019-02-01")))) +}) + +test_that("invalid input pacs::pac_news", { + skip_if_offline() + expect_identical(pac_news("dplyr", version = "0.0.0.1"), NA) + expect_identical(pac_news("dplyr", version = "10.8.0.0"), NA) + expect_identical(pac_news("dplyr2", at = as.Date("2019-02-01")), NA) +}) diff --git a/tests/testthat/test-read_cran.R b/tests/testthat/test-read_cran.R new file mode 100644 index 0000000..b8b3441 --- /dev/null +++ b/tests/testthat/test-read_cran.R @@ -0,0 +1,15 @@ +test_that("pacs:::read_cran_file valid input", { + skip_if_offline() + expect_silent(pacs:::read_cran_file("memoise", "1.1.0", "DESCRIPTION", repos = "https://cran.rstudio.com/")) + expect_silent(pacs:::read_cran_file("memoise", "1.1.0", "NAMESPACE", repos = "https://cran.rstudio.com/")) + expect_silent(pacs:::read_cran_file("memoise", "1.1.0", "NEWS")) +}) + +test_that("pacs::read_cran_file expected output", { + skip_if_offline() + expect_true(length(read_cran_file("dplyr", "1.0.0", "DESCRIPTION", "https://cran.rstudio.com/")) == 22) + expect_identical( + read_cran_file("dplyr", "0.0.0.1", "DESCRIPTION", "https://cran.rstudio.com/"), + NA + ) +}) diff --git a/tests/testthat/test-read_github.R b/tests/testthat/test-read_github.R new file mode 100644 index 0000000..2a76a44 --- /dev/null +++ b/tests/testthat/test-read_github.R @@ -0,0 +1,13 @@ + +test_that("pacs:::read_github_file valid input", { + skip_if_offline() + expect_silent(pacs:::read_github_file("memoise", "1.1.0", "DESCRIPTION", repos = "https://cran.rstudio.com/")) + expect_silent(pacs:::read_github_file("memoise", "1.1.0", "NAMESPACE", repos = "https://cran.rstudio.com/")) + expect_silent(pacs:::read_github_file("memoise", "1.1.0", "NEWS")) +}) + +test_that("pacs:::read_github_file invalid input", { + skip_if_offline() + expect_identical(pacs:::read_github_file("dplyr", "0.8.0.2", "DESCRIPTION", repos = "https://cran.rstudio.com/"),NA) + expect_error(pacs:::read_github_file("dplyr2", "0.8.0", "NAMESPACE", repos = "https://cran.rstudio.com/"), NA) +}) diff --git a/tests/testthat/test-validate_input.R b/tests/testthat/test-validate_input.R new file mode 100644 index 0000000..12ca302 --- /dev/null +++ b/tests/testthat/test-validate_input.R @@ -0,0 +1,20 @@ +test_that("test valid validate_pac_input input", { + expect_silent(validate_pac_input("memoise", version = NULL, at = NULL, local = TRUE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) + expect_silent(validate_pac_input("memoise", version = "1.1.0", at = NULL, local = FALSE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) +}) + +test_that("test invalid validate_pac_input input", { + expect_error(validate_pac_input("memoise", version = "1.1.0", at = NULL, local = TRUE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) + expect_error(validate_pac_input("memoise", version = "1.1.0", at = as.Date("2019-02-01"), local = FALSE, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) +}) + +test_that("test valid validate_compare_input input", { + expect_silent(validate_compare_input("memoise", old = NULL, new = NULL, lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) + expect_silent(validate_compare_input("memoise", old = "1.1.0", new = "1.1.1", lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) +}) + +test_that("test invalid validate_compare_input input", { + expect_error(validate_compare_input(c("memoise", "sth"), old = "1.1.0", new = "1.1.1", lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) + expect_error(validate_compare_input("memoise", old = c("1.1.0", "1"), new = "1.1.1", lib.loc = .libPaths(), repos = "https://cran.rstudio.com/")) + expect_error(validate_compare_input("memoise", old = "1.1.0", new = "1.1.1", lib.loc = .libPaths(), repos = 2)) +})