Skip to content

Commit 8bdc4fb

Browse files
Merge pull request #1275 from r-lib/dev-roxygen-nested
more informative error message on nested dont statements in roxygen code examples
2 parents 9024d8f + 269ec40 commit 8bdc4fb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

R/roxygen-examples-find.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ find_dont_seqs <- function(bare) {
6161
find_dont_closings <- function(bare, dont_openings) {
6262
opening <- cumsum(bare == "{")
6363
closing <- cumsum(bare == "}")
64+
if (sum(closing) == 0L) {
65+
rlang::abort(paste0(
66+
"Failed to find closing braces for a \\dont* statement in a roxygen ",
67+
"code example. This is most likely caused by nested \\donttest, ",
68+
"\\dontrun or \\dontshow statement. These are not supported with ",
69+
"{styler}, not even when {styler} is turned off for these lines as per ",
70+
"the documentation at ",
71+
"https://styler.r-lib.org/articles/styler.html#ignoring-certain-lines. ",
72+
"See also GitHub issue https://github.com/r-lib/styler/issues/498."
73+
))
74+
}
6475
diff <- opening - closing
6576
level_dont <- diff[dont_openings]
6677
match_closing <- intersect(

tests/testthat/test-roxygen-examples-parse.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ test_that("donts can be parsed", {
4141
)
4242
})
4343

44+
test_that("Nested dont* statements return informative error message", {
45+
expect_error(
46+
style_roxygen_code_example_one(
47+
c(
48+
"#' @examples", "#' # styler: off", "#' \\donttest{", "#' \\dontshow{",
49+
"#' 1+1", "#' }", "#' }", "#' # styler: on"
50+
),
51+
transformers = tidyverse_style(scope = "spaces"), base_indention = 2L
52+
),
53+
regexp = "nested \\\\donttest"
54+
)
55+
})
56+
4457
test_that("braces examples can be parsed", {
4558
expect_equal(
4659
parse_roxygen(

0 commit comments

Comments
 (0)