Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Oct 27, 2024
1 parent 0bbf579 commit a68be7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/testthat/test-return_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-todo_comment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)\\)")
)
})
13 changes: 13 additions & 0 deletions tests/testthat/test-unreachable_code_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit a68be7e

Please sign in to comment.