Skip to content

Commit

Permalink
Make 'markdown = TRUE' check less brittle
Browse files Browse the repository at this point in the history
Closes #2073
  • Loading branch information
jennybc committed Nov 21, 2024
1 parent 487688b commit 8d8742b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions R/roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use_roxygen_md <- function(overwrite = FALSE) {
}

# FALSE: no Roxygen field
# TRUE: plain old "list(markdown = TRUE)"
# TRUE: matches regex targetting 'markdown = TRUE', with some whitespace slop
# NA: everything else
uses_roxygen_md <- function() {
desc <- proj_desc()
Expand All @@ -66,8 +66,7 @@ uses_roxygen_md <- function() {
}

roxygen <- desc$get_field("Roxygen", "")
if (identical(roxygen, "list(markdown = TRUE)") ||
identical(roxygen, "list(markdown = TRUE, r6 = FALSE)")) {
if (grepl("markdown\\s*=\\s*TRUE", roxygen)) {
TRUE
} else {
NA
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ test_that("use_roxygen_md() adds DESCRIPTION fields to naive package", {
expect_true(uses_roxygen_md())
})

test_that("use_roxygen_md() behaves for pre-existing Roxygen field", {
test_that("use_roxygen_md() finds 'markdown = TRUE' in presence of other stuff", {
skip_if_not_installed("roxygen2")

pkg <- create_local_package()
desc::desc_set(Roxygen = 'list(markdown = TRUE, r6 = FALSE, load = "source")')
desc::desc_set(Roxygen = 'list(markdown = TRUE, r6 = FALSE, load = "source", roclets = c("collate", "namespace", "rd", "roxyglobals::global_roclet"))')

expect_error(use_roxygen_md(), "already has")
local_check_installed()
expect_no_error(use_roxygen_md(overwrite = TRUE))
expect_no_error(use_roxygen_md())
expect_true(uses_roxygen_md())
})

0 comments on commit 8d8742b

Please sign in to comment.