Skip to content

Commit

Permalink
Only document in check if roxygen2 versions match
Browse files Browse the repository at this point in the history
Fixes #2263
  • Loading branch information
hadley committed Sep 2, 2020
1 parent 5c7a300 commit 3b85e21
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# devtools (development version)

* `check()` only re-documents if you have a matching version of roxygen2
(#2263).

* `pkgload::inst()` is no longer re-exported (#2218).

* Old `check_results()` function has been removed. It was not used by any
Expand Down
35 changes: 27 additions & 8 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
#'
#' @return An object containing errors, warnings, and notes.
#' @template devtools
#' @param document If `NA` and the package uses roxygen2, will
#' rerun [document()] prior to checking. Use `TRUE`
#' and `FALSE` to override this default.
#' @param document By default (`NULL`) will document if your installed
#' roxygen2 version matches the version declared in the `DESCRIPTION`
#' file. Use `TRUE` or `FALSE` to override the default.
#' @param build_args Additional arguments passed to `R CMD build`
#' @param check_dir the directory in which the package is checked
#' compatibility. `args = "--output=/foo/bar"` can be used to change the
Expand All @@ -54,7 +54,7 @@
#' CRAN.
#' @export
check <- function(pkg = ".",
document = NA,
document = NULL,
build_args = NULL,
...,
manual = FALSE,
Expand Down Expand Up @@ -84,10 +84,7 @@ check <- function(pkg = ".",
}
error_on <- match.arg(error_on)

# document only if package uses roxygen, i.e. has RoxygenNote field
if (identical(document, NA)) {
document <- !is.null(pkg$roxygennote)
}
document <- document %||% can_document(pkg)
if (document) {
document(pkg, quiet = quiet)
}
Expand Down Expand Up @@ -136,6 +133,28 @@ check <- function(pkg = ".",
)
}

can_document <- function(pkg) {
required <- pkg$roxygennote
if (is.null(required)) {
# Doesn't use roxygen2 at all
return(FALSE)
}

installed <- packageVersion("roxygen2")
if (required != installed) {
cli::cli_rule()
cli::cli_alert_info(
"Installed roxygen2 version ({installed}) doesn't match required version ({required})"
)
cli::cli_alert_danger("check() will not redocument this package")
cli::cli_rule()

FALSE
} else {
TRUE
}
}

#' @export
#' @rdname check
#' @param path Path to built package.
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test_that("can determine when to document", {
expect_false(can_document(list()))
# TODO: switch to expect_snapshot()
suppressMessages(expect_message(
expect_false(can_document(list(roxygennote = "15.0.00"))),
"doesn't match required"
))
expect_true(can_document(list(roxygennote = packageVersion("roxygen2"))))
})

0 comments on commit 3b85e21

Please sign in to comment.