Skip to content

Commit 9756f25

Browse files
mcolhadley
andauthored
Suggest a fix if a mismatch in roxygen2 versions is found during check (#2636)
--------- Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
1 parent c23b34d commit 9756f25

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

R/check.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ check <- function(
8282
}
8383
error_on <- match.arg(error_on)
8484

85-
document <- document %||% can_document(pkg)
85+
document <- document %||% can_document(pkg$roxygennote)
8686
if (document) {
8787
if (!quiet) {
8888
cat_rule("Documenting", col = "cyan", line = 2)
@@ -133,19 +133,17 @@ check <- function(
133133
)
134134
}
135135

136-
can_document <- function(pkg) {
137-
required <- pkg$roxygennote
136+
can_document <- function(required, installed = packageVersion("roxygen2")) {
138137
if (is.null(required)) {
139-
# Doesn't use roxygen2 at all
140138
return(FALSE)
141139
}
142140

143-
installed <- packageVersion("roxygen2")
144141
if (required != installed) {
145142
cli::cat_rule("Documenting", col = "red", line = 2)
146143
cli::cli_inform(c(
147-
i = "Installed roxygen2 version ({installed}) doesn't match required ({required})",
148-
x = "{.fun check} will not re-document this package"
144+
i = "Installed roxygen2 version ({installed}) doesn't match declared ({required})",
145+
x = "{.fun check} will not re-document this package.",
146+
i = "Do you need to re-run {.fun document}?"
149147
))
150148
FALSE
151149
} else {

tests/testthat/_snaps/check.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# can determine when to document
2+
3+
Code
4+
result <- can_document("1.0.0", installed = "2.0.0")
5+
Output
6+
== Documenting =================================================================
7+
Message
8+
i Installed roxygen2 version (2.0.0) doesn't match declared (1.0.0)
9+
x `check()` will not re-document this package.
10+
i Do you need to re-run `document()`?
11+

tests/testthat/test-check.R

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
test_that("can determine when to document", {
2-
expect_false(can_document(list()))
3-
# TODO: switch to expect_snapshot()
4-
expect_output(
5-
expect_message(
6-
expect_false(can_document(list(roxygennote = "15.0.00"))),
7-
"doesn't match required"
8-
)
9-
)
10-
expect_true(can_document(list(roxygennote = packageVersion("roxygen2"))))
2+
expect_false(can_document(NULL))
3+
expect_true(can_document("1.0.0", installed = "1.0.0"))
4+
expect_snapshot(result <- can_document("1.0.0", installed = "2.0.0"))
5+
expect_false(result)
116
})
127

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

0 commit comments

Comments
 (0)