diff --git a/tests/testthat/test-return_linter.R b/tests/testthat/test-return_linter.R index b05b3abd3..58a5d1cf9 100644 --- a/tests/testthat/test-return_linter.R +++ b/tests/testthat/test-return_linter.R @@ -691,6 +691,20 @@ test_that("except_regex= argument works", { list(rex::rex("All functions must have an explicit return()."), line_number = 5L), linter ) + + # capture group doesn't cause issues, #2678 + expect_lint( + trim_some(" + TestFun <- function() { + non_return() + } + AssertFun <- function() { + non_return() + } + "), + NULL, + return_linter(return_style = "explicit", except_regex = "^(Test|Assert)") + ) }) test_that("except= and except_regex= combination works", { diff --git a/tests/testthat/test-todo_comment_linter.R b/tests/testthat/test-todo_comment_linter.R index 103f9c8fc..b7793d1d8 100644 --- a/tests/testthat/test-todo_comment_linter.R +++ b/tests/testthat/test-todo_comment_linter.R @@ -57,4 +57,11 @@ test_that("except_regex= excludes valid TODO", { NULL, todo_comment_linter(except_regex = c("TODO\\(#[0-9]+\\):", "fixme\\(#[0-9]+\\):")) ) + + # ignore captured groups + expect_lint( + "# TODO(a)", + NULL, + todo_comment_linter(except_regex = "TODO\\((a|abc)\\)") + ) }) diff --git a/tests/testthat/test-unreachable_code_linter.R b/tests/testthat/test-unreachable_code_linter.R index 167909d50..b54d3b11e 100644 --- a/tests/testthat/test-unreachable_code_linter.R +++ b/tests/testthat/test-unreachable_code_linter.R @@ -687,6 +687,19 @@ test_that("allow_comment_regex= works", { NULL, linter_x1x2 ) + + # might contain capture groups, #2678 + expect_lint( + trim_some(" + function() { + stop('a') + # a + # ab + } + "), + NULL, + unreachable_code_linter(allow_comment_regex = "#\\s*(a|ab|abc)") + ) }) test_that("allow_comment_regex= obeys covr's custom exclusion when set", {