Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt tests to upcoming {patrick} release #2709

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 7 additions & 10 deletions tests/testthat/test-fixed_regex_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("fixed_regex_linter blocks simple disallowed usages", {
})

patrick::with_parameters_test_that(
"fixed_regex_linter is robust to unrecognized escapes error",
"fixed_regex_linter is robust to unrecognized escapes error for {char}",
{
expect_lint(
sprintf(R"{grep('\\%s', x)}", char),
Expand All @@ -56,14 +56,11 @@ patrick::with_parameters_test_that(
fixed_regex_linter()
)
},
.cases = local({
char <- c(
"^", "$", "{", "}", "(", ")", ".", "*", "+", "?",
"|", "[", "]", R"(\\)", "<", ">", "=", ":", ";", "/",
"_", "-", "!", "@", "#", "%", "&", "~"
)
data.frame(char = char, .test_name = char)
})
char = c(
"^", "$", "{", "}", "(", ")", ".", "*", "+", "?",
"|", "[", "]", R"(\\)", "<", ">", "=", ":", ";", "/",
"_", "-", "!", "@", "#", "%", "&", "~"
)
)

test_that("fixed_regex_linter catches regex like [.] or [$]", {
Expand Down Expand Up @@ -326,7 +323,7 @@ local({
skip_cases <- character()
}
patrick::with_parameters_test_that(
"fixed replacements are correct",
"fixed replacements of {regex_expr} with {fixed_expr} is correct",
{
# TODO(google/patrick#19): handle this more cleanly by skipping up-front
skip_if(
Expand Down
23 changes: 9 additions & 14 deletions tests/testthat/test-pipe_continuation_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,55 +138,50 @@ test_that("pipe-continuation linter handles native pipe", {

local({
linter <- pipe_continuation_linter()
valid_code <- c(
# all on one line
.cases <- tibble::tribble(
~code_string, ~.test_name,
trim_some("
my_fun <- function() {
a %>% b()
}
"),
"), "two on one line",
trim_some("
my_fun <- function() {
a %>% b() %>% c()
}
"),
"), "three on one line",
trim_some("
with(
diamonds,
x %>% head(10) %>% tail(5)
)
"),
"), "three inside with()",
trim_some("
test_that('blah', {
test_data <- diamonds %>% head(10) %>% tail(5)
})
"),

# two different single-line pipelines
"), "three inside test_that()",
trim_some("
{
x <- a %>% b %>% c
y <- c %>% b %>% a
}
"),

# at most one pipe-character per line
"), "two different single-line pipelines",
trim_some("
my_fun <- function() {
a %>%
b() %>%
c()
}
")
"), "at most one pipe-character per line"
)
patrick::with_parameters_test_that(
"valid nesting is handled",
# nolint next: unnecessary_nesting_linter. TODO(#2334): Remove this nolint.
{
expect_lint(code_string, NULL, linter)
},
.test_name = valid_code,
code_string = valid_code
.cases = .cases
)
})

Expand Down
Loading