Skip to content

Commit

Permalink
Finalize changes
Browse files Browse the repository at this point in the history
* fix `.lintr` (used a deprecated function)
* fix a few lints
* Call styler on test-codecov.R and test-coveralls.R
* avoid `with_mock()` in test-utils.R
  • Loading branch information
olivroy committed Dec 12, 2024
1 parent 88a72ee commit 42822b7
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
linters: with_defaults(line_length_linter(120))
linters: linters_with_defaults(line_length_linter(120))
exclusions: list("inst/doc/how_it_works.R")
6 changes: 3 additions & 3 deletions R/cobertura.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param cov the coverage object returned from [package_coverage()]
#' @param filename the name of the Cobertura XML file
#' @export
to_cobertura <- function(cov, filename = "cobertura.xml"){
to_cobertura <- function(cov, filename = "cobertura.xml") {

loadNamespace("xml2")

Expand All @@ -24,7 +24,7 @@ to_cobertura <- function(cov, filename = "cobertura.xml"){
percent_per_function <- tapply(df$value, df$functions, FUN = function(x) (sum(x > 0) / length(x)))
lines_valid <- nrow(df)
lines_covered <- sum(df$value > 0)

d <- xml2::xml_new_document()

xml2::xml_add_child(d, xml2::xml_dtd(
Expand All @@ -34,7 +34,7 @@ to_cobertura <- function(cov, filename = "cobertura.xml"){
top <- xml2::xml_add_child(d,
"coverage",
"line-rate" = as.character(percent_overall),
"branch-rate" = "0",
"branch-rate" = "0",
`lines-covered` = as.character(lines_covered),
`lines-valid` = as.character(lines_valid),
`branches-covered` = "0",
Expand Down
2 changes: 1 addition & 1 deletion R/compiled.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
res <- withr::with_dir(src_path, {
compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))
})
if (!length(res) & length(gcov_inputs))
if (!length(res) && length(gcov_inputs))
warning('parsed gcov output was empty')
res
}
Expand Down
9 changes: 4 additions & 5 deletions R/covr.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ package_coverage <- function(path = ".",
code = character(),
install_path = temp_file("R_LIBS"),
...,
exclusions, pre_clean=TRUE) {
exclusions, pre_clean = TRUE) {

if (!missing(exclusions)) {
warning(
Expand Down Expand Up @@ -423,8 +423,7 @@ package_coverage <- function(path = ".",
# check for compiler
if (!uses_icc()) {
flags <- getOption("covr.flags")
}
else {
} else {
if (length(getOption("covr.icov")) > 0L) {
flags <- getOption("covr.icov_flags")
# clean up old icov files
Expand Down Expand Up @@ -672,7 +671,7 @@ clean_coverage_tests <- function(obj) {
for (i in seq_along(obj)) {
if (is.null(val <- obj[[i]]$value)) next
if (is.null(n <- nrow(obj[[i]]$tests$tally)) || n < val) next
obj[[i]]$tests$tally <- obj[[i]]$tests$tally[seq_len(val),,drop = FALSE]
obj[[i]]$tests$tally <- obj[[i]]$tests$tally[seq_len(val), , drop = FALSE]
}
}

Expand Down Expand Up @@ -709,7 +708,7 @@ merge_coverage_tests <- function(from, into = NULL) {
# modify trace test tallies
for (name in intersect(names(into), names(from))) {
if (name == "tests") next
from[[name]]$tests$tally[,1L] <- test_idx[from[[name]]$tests$tally[,1L]]
from[[name]]$tests$tally[, 1L] <- test_idx[from[[name]]$tests$tally[, 1L]]
into[[name]]$tests$tally <- rbind(into[[name]]$tests$tally, from[[name]]$tests$tally)
}

Expand Down
2 changes: 1 addition & 1 deletion R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ parse_icov <- function(lines, package_path = "") {
by = list(line=m1$line, functions=m1$functions), sum)
names(m2) <- c("line", "functions", "coverage")
}
matches <- m2[order(m2$line),]
matches <- m2[order(m2$line), ]

values <- as.numeric(matches$coverage > 0L)
functions <- matches$functions
Expand Down
4 changes: 2 additions & 2 deletions R/summary_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ print.coverage <- function(x, group = c("filename", "functions"), by = "line", .

overall_percentage <- percent_coverage(df, by = by)

cli::cli_inform(paste(
cli::cli_inform(paste0(
cli::style_bold(
"{attr(x, 'package')$package} {to_title(type)} Coverage: "
),
Expand All @@ -173,7 +173,7 @@ print.coverage <- function(x, group = c("filename", "functions"), by = "line", .

for (i in seq_along(by_coverage)) {
cli::cli_inform(
paste(
paste0(
cli::style_bold(names(by_coverage)[i], ": "),
format_percentage(by_coverage[i])
)
Expand Down
21 changes: 7 additions & 14 deletions R/trace_calls.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
if (is.atomic(x) || is.name(x) || is.null(x)) {
if (is.null(parent_ref)) {
x
}
else {
} else {
if (is_na(x) || is_brace(x)) {
x
} else {
key <- new_counter(parent_ref, parent_functions) # nolint
count(key, x)
}
}
}
else if (is.call(x)) {
} else if (is.call(x)) {
src_ref <- attr(x, "srcref") %||% impute_srcref(x, parent_ref)
if ((identical(x[[1]], as.name("<-")) || identical(x[[1]], as.name("="))) && # nolint
(is.call(x[[3]]) && identical(x[[3]][[1]], as.name("function")))) {
Expand All @@ -59,8 +57,7 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
} else {
as.call(recurse(x))
}
}
else if (is.function(x)) {
} else if (is.function(x)) {

# We cannot trace primitive functions
if (is.primitive(x)) {
Expand All @@ -83,17 +80,13 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
formals(x) <- new_formals
body(x) <- fun_body
x
}
else if (is.pairlist(x)) {
} else if (is.pairlist(x)) {
as.pairlist(recurse(x))
}
else if (is.expression(x)) {
} else if (is.expression(x)) {
as.expression(recurse(x))
}
else if (is.list(x)) {
} else if (is.list(x)) {
recurse(x)
}
else {
} else {
message("Unknown language class: ", paste(class(x), collapse = "/"))
x
}
Expand Down
8 changes: 4 additions & 4 deletions R/trace_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ count_test <- function(key) {
tests$.data[[4L]] <- .current_test$i

tests$.value <- .counters[[key]]$value
with(tests, tally[.value,] <- .data)
with(tests, tally[.value, ] <- .data)
}

#' Initialize a new test counter for a coverage trace
Expand Down Expand Up @@ -339,9 +339,9 @@ truncate_call <- function(call_obj, limit = 1e4) {
#'
is_current_test_finished <- function() {
is.null(.current_test$src) ||
.current_test$last_frame > sys.nframe() ||
!identical(.current_test$src_call, sys.call(which = .current_test$last_frame)) ||
!identical(.current_test$src_env, sys.frame(which = .current_test$last_frame - 1L))
.current_test$last_frame > sys.nframe() ||
!identical(.current_test$src_call, sys.call(which = .current_test$last_frame)) ||
!identical(.current_test$src_env, sys.frame(which = .current_test$last_frame - 1L))
}

#' Is the source bound to the expression
Expand Down
Loading

0 comments on commit 42822b7

Please sign in to comment.