From 8d8742b0fa9b0514799d47dd6f0cc56b33aca44c Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Thu, 21 Nov 2024 10:10:48 -0800 Subject: [PATCH] Make 'markdown = TRUE' check less brittle Closes #2073 --- R/roxygen.R | 5 ++--- tests/testthat/test-roxygen.R | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/R/roxygen.R b/R/roxygen.R index 1071c8c77..afbf3fb4b 100644 --- a/R/roxygen.R +++ b/R/roxygen.R @@ -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() @@ -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 diff --git a/tests/testthat/test-roxygen.R b/tests/testthat/test-roxygen.R index b3161bfa9..42a26ef61 100644 --- a/tests/testthat/test-roxygen.R +++ b/tests/testthat/test-roxygen.R @@ -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()) })