Skip to content

Commit 957e65c

Browse files
Removed explicit sets and store everythin in covr object
1 parent 45a21ce commit 957e65c

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

R/config.R

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option_env$return_covr_result <- FALSE
66
option_env$slicing_points <- FALSE
77
option_env$log_level <- "INFO"
88
option_env$unknown_locations <- FALSE
9+
option_env$return_srcrefs <- FALSE
910

1011
#' Configures various options for this package. If no value is given for any
1112
#' option, it's default is used.
@@ -24,6 +25,8 @@ option_env$unknown_locations <- FALSE
2425
#' \item log_level The minimum level of logs that should be shown
2526
#' \item unknown_locations Whether to return the number of source refs flowr did not
2627
#' know about
28+
#' \item return_srcrefs Whether to return all srcrefs, the ones that were covered and the
29+
#' ones that were in the slice.
2730
#' }
2831
#' @return A list of all options and their values before the configuration.
2932
#'

R/utils.R

+40-26
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ measure <- function(expr, only_time = FALSE) {
8686

8787
build_return_value <- function(covr, covr_time,
8888
slicing_coverage, slicing_points, ana_time, slicing_time, query_time,
89-
unknown_locations) {
89+
unknown_locations,
90+
srcrefs) {
9091
if (get_option("measure_time") || get_option("return_covr_result") || get_option("slicing_points")) {
9192
res <- list(coverage = slicing_coverage)
9293
if (get_option("measure_time")) {
@@ -105,6 +106,9 @@ build_return_value <- function(covr, covr_time,
105106
if (get_option("unknown_locations")) {
106107
res$unknown_locations <- unknown_locations
107108
}
109+
if (get_option("return_srcrefs")) {
110+
res$srcrefs <- srcrefs
111+
}
108112
return(res)
109113
}
110114

@@ -146,7 +150,7 @@ build_loc2id_map <- function(nodes) {
146150
return(location_to_id)
147151
}
148152

149-
add_ids_to_coverage <- function(coverage) {
153+
add_slc_to_coverage <- function(coverage, slice) {
150154
logger::log_trace("Merging coverage and slice", namespace = "slicingCoverage")
151155
if ("result" %in% names(coverage)) {
152156
coverage <- coverage$result
@@ -173,6 +177,7 @@ add_ids_to_coverage <- function(coverage) {
173177
next
174178
}
175179
elem$flowr_ids <- ids
180+
elem$in_slice <- any(ids %in% slice)
176181
coverage[[file_and_srcref]] <- elem
177182
}
178183

@@ -194,24 +199,25 @@ add_ids_to_coverage <- function(coverage) {
194199
))
195200
}
196201

197-
remove_ids_from_coverage <- function(coverage) {
202+
remove_slc_from_coverage <- function(coverage) {
198203
for (i in seq_along(coverage)) {
199204
elem <- coverage[[i]]
200205
elem$flowr_ids <- NULL
206+
elem$in_slice <- NULL
201207
coverage[[i]] <- elem
202208
}
203209
return(coverage)
204210
}
205211

206-
recalculate_values <- function(coverage, exec_and_slc_ids) {
212+
recalculate_values <- function(coverage) {
207213
logger::log_trace("Adjusting coverage values", namespace = "slicingCoverage")
208214
for (i in seq_along(coverage)) {
209215
elem <- coverage[[i]]
210-
flowr_ids <- elem$flowr_ids
211-
if (is.null(flowr_ids)) { # This should not happen (see add_ids_to_coverage)
216+
in_slice <- elem$in_slice
217+
if (is.null(in_slice)) { # This should not happen (see add_ids_to_coverage)
212218
next
213219
}
214-
if (any(flowr_ids %in% exec_and_slc_ids)) { # No need to change anything as element is in the slice
220+
if (in_slice) { # No need to change anything as element is in the slice
215221
next
216222
}
217223

@@ -221,22 +227,24 @@ recalculate_values <- function(coverage, exec_and_slc_ids) {
221227
return(coverage)
222228
}
223229

224-
as_slicing_coverage <- function(coverage, slice) {
225-
coverage_with_ids <- add_ids_to_coverage(coverage)
226-
unknown_locations <- coverage_with_ids$unknown_locations
227-
coverage_with_ids <- coverage_with_ids$coverage
228-
229-
set_executed <- Filter(was_executed, coverage_with_ids) |>
230-
lapply(get_flowr_id) |>
231-
uneverything()
232-
set_slice <- unlist(slice)
233-
set_exec_and_slice <- intersect(set_executed, set_slice)
234-
235-
slicing_coverage <- recalculate_values(coverage_with_ids, set_exec_and_slice) |> remove_ids_from_coverage()
236-
230+
get_coverered_and_sliced_srcrefs <- function(slc_coverage) { # nolint: object_length_linter.
231+
all <- c()
232+
covered <- c()
233+
sliced <- c()
234+
for (srcref in names(slc_coverage)) {
235+
elem <- slc_coverage[[srcref]]
236+
all <- c(all, srcref)
237+
if (was_executed(elem)) {
238+
covered <- c(covered, srcref)
239+
}
240+
if (elem$in_slice) {
241+
sliced <- c(sliced, srcref)
242+
}
243+
}
237244
return(list(
238-
coverage = slicing_coverage,
239-
unknown_locations = unknown_locations
245+
all = all,
246+
covered = covered,
247+
sliced = sliced
240248
))
241249
}
242250

@@ -251,13 +259,19 @@ give_me_covr_and_i_do_the_rest <- function(covr_measure, sources, tests) { # nol
251259
slicing_points <- slicing_measure$slicing_points
252260
slicing_time <- slicing_measure$slicing_time
253261
query_time <- slicing_measure$query_time
254-
slicing_coverage <- as_slicing_coverage(covr, slicing_measure$slice)
255-
unknown_locations <- slicing_coverage$unknown_locations
256-
slicing_coverage <- slicing_coverage$coverage
262+
263+
coverage_with_slc <- add_slc_to_coverage(covr, slicing_measure$slice)
264+
unknown_locations <- coverage_with_slc$unknown_locations
265+
coverage_with_slc <- coverage_with_slc$coverage
266+
267+
srcrefs <- get_coverered_and_sliced_srcrefs(coverage_with_slc)
268+
269+
slicing_coverage <- recalculate_values(coverage_with_slc) |> remove_slc_from_coverage()
257270

258271
return(build_return_value(
259272
covr, covr_time,
260273
slicing_coverage, slicing_points, ana_time, slicing_time, query_time,
261-
unknown_locations
274+
unknown_locations,
275+
srcrefs
262276
))
263277
}

man/configure.Rd

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)