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
11 changes: 11 additions & 0 deletions R/roxygen-examples-find.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ find_dont_seqs <- function(bare) {
find_dont_closings <- function(bare, dont_openings) {
opening <- cumsum(bare == "{")
closing <- cumsum(bare == "}")
if (sum(closing) == 0L) {
rlang::abort(paste0(
"Failed to find closing braces for a \\dont* statement in a roxygen ",
"code example. This is most likely caused by nested \\donttest, ",
"\\dontrun or \\dontshow statement. These are not supported with ",
"{styler}, not even when {styler} is turned off for these lines as per ",
"the documentation at ",
"https://styler.r-lib.org/articles/styler.html#ignoring-certain-lines. ",
"See also GitHub issue https://github.com/r-lib/styler/issues/498."
))
}
diff <- opening - closing
level_dont <- diff[dont_openings]
match_closing <- intersect(
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-roxygen-examples-parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ test_that("donts can be parsed", {
)
})

test_that("Nested dont* statements return informative error message", {
expect_error(
style_roxygen_code_example_one(
c(
"#' @examples", "#' # styler: off", "#' \\donttest{", "#' \\dontshow{",
"#' 1+1", "#' }", "#' }", "#' # styler: on"
),
transformers = tidyverse_style(scope = "spaces"), base_indention = 2L
),
regexp = "nested \\\\donttest"
)
})

test_that("braces examples can be parsed", {
expect_equal(
parse_roxygen(
Expand Down
Loading