-
Notifications
You must be signed in to change notification settings - Fork 337
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorreporter 📝
Description
Currently when creating the name for testing contexts, context_name()
removes all instances of "\\.[Rr]
" in the name, not only the terminal one. If following convention to match the test-*.R
filename with the function name it tests may sometimes require a .R
to exist internally. For example:
test-calculate.RobustMetrics.R
reprex::reprex({
library(testthat)
writeLines(
"test_that('multiplication works', { expect_equal(2 * 2, 4) })",
"test-calculate.RobustMetrics.R"
)
# Context below has '.R' removed from file name
# Resulting in `calculateobustMetrics`
test_file("test-calculate.RobustMetrics.R")
})
This of course doesn't usually happen using tidyverse
function naming conventions, but some organizations may have differing style guides preventing this adherence.
Suggest a more strict regular expression within context_name()
, for example:
context_name <- function (filename) {
filename <- gsub("^test-", "", filename) # add regex starts-with '^'; could use `sub()` instead
filename <- gsub("[.][Rr]$", "", filename) # add regex ends-with '$'; could use `sub()` instead
filename
}
As mentioned above, one could also use sub()
rather than gsub()
, since we're only interested in the starting (^
) and terminal ($
) pattern.
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorreporter 📝