Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ check <- function(
}
error_on <- match.arg(error_on)

document <- document %||% can_document(pkg)
document <- document %||% can_document(pkg$roxygennote)
if (document) {
if (!quiet) {
cat_rule("Documenting", col = "cyan", line = 2)
Expand Down Expand Up @@ -133,19 +133,17 @@ check <- function(
)
}

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

installed <- packageVersion("roxygen2")
if (required != installed) {
cli::cat_rule("Documenting", col = "red", line = 2)
cli::cli_inform(c(
i = "Installed roxygen2 version ({installed}) doesn't match required ({required})",
x = "{.fun check} will not re-document this package"
i = "Installed roxygen2 version ({installed}) doesn't match declared ({required})",
x = "{.fun check} will not re-document this package.",
i = "Do you need to re-run {.fun document}?"
))
FALSE
} else {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/_snaps/check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# can determine when to document

Code
result <- can_document("1.0.0", installed = "2.0.0")
Output
== Documenting =================================================================
Message
i Installed roxygen2 version (2.0.0) doesn't match declared (1.0.0)
x `check()` will not re-document this package.
i Do you need to re-run `document()`?

13 changes: 4 additions & 9 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
test_that("can determine when to document", {
expect_false(can_document(list()))
# TODO: switch to expect_snapshot()
expect_output(
expect_message(
expect_false(can_document(list(roxygennote = "15.0.00"))),
"doesn't match required"
)
)
expect_true(can_document(list(roxygennote = packageVersion("roxygen2"))))
expect_false(can_document(NULL))
expect_true(can_document("1.0.0", installed = "1.0.0"))
expect_snapshot(result <- can_document("1.0.0", installed = "2.0.0"))
expect_false(result)
})

test_that("fail instead of sending an email to wrong recipient", {
Expand Down