-
Notifications
You must be signed in to change notification settings - Fork 120
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
Address testthat deprecation warnings + drop mockery #589
Changes from 4 commits
53ea0ba
b1c40c2
38e1635
8eadd93
4f1366a
f1729b0
b5e55ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
# this does not handle LCOV_EXCL_START ect. | ||
parse_gcov <- function(file, package_path = "") { | ||
if (!file.exists(file)) { | ||
if (!source_file_exists(file)) { | ||
return(NULL) | ||
} | ||
|
||
lines <- readLines(file) | ||
lines <- read_lines_impl(file) | ||
source_file <- rex::re_matches(lines[1], rex::rex("Source:", capture(name = "source", anything)))$source | ||
|
||
# retrieve full path to the source files | ||
source_file <- normalize_path(source_file) | ||
|
||
# If the source file does not start with the package path or does not exist ignore it. | ||
if (!file.exists(source_file) || !grepl(rex::rex(start, rex::regex(paste0(rex::escape(package_path), collapse = "|"))), source_file)) { | ||
if (!source_file_exists(source_file) || !grepl(rex::rex(start, rex::regex(paste0(rex::escape(package_path), collapse = "|"))), source_file)) { | ||
return(NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are required to remove the mockery dependency. I kept the commit self-contained. But basically, with The workaround I found is to create a wrapper function for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So for base functions you can assign a NULL binding in the package rather than using a wrapper function. See https://testthat.r-lib.org/reference/local_mocked_bindings.html?q=local_mock#base-functions. This works because when the name is used as a function call the NULL assigned value is not a callable function, so it is not included in the lookup and the base version gets used instead. Then when the mocking happens it can assign a function to the variable in the package's namespace. |
||
} | ||
|
||
|
@@ -46,9 +46,24 @@ parse_gcov <- function(file, package_path = "") { | |
# There are no functions for gcov, so we set everything to NA | ||
functions <- rep(NA_character_, length(values)) | ||
|
||
line_coverages_impl(source_file, matches, values, functions) | ||
} | ||
|
||
# For mocking (only use it within parse_gcov()) | ||
line_coverages_impl <- function(source_file, matches, values, functions) { | ||
olivroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
line_coverages(source_file, matches, values, functions) | ||
} | ||
|
||
# For mocking (only use it within parse_gcov()) | ||
source_file_exists <- function(path) { | ||
file.exists(path) | ||
} | ||
|
||
# For mocking (only use it within parse_gcov()) | ||
read_lines_impl <- function(path) { | ||
readLines(path) | ||
} | ||
|
||
olivroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clean_gcov <- function(path) { | ||
src_dir <- file.path(path, "src") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to use testthat mocking https://testthat.r-lib.org/reference/local_mocked_bindings.html?q=local_mock#namespaced-calls