Skip to content

Commit

Permalink
appends ids to test names instead of appending as attributes
Browse files Browse the repository at this point in the history
Issue:
    IDs were stored in in test result attributes.
    When tests didn't run due to errors (not test expectation failures), results were missing.
Solution:
    IDs are now stored in test names and parsed later.
Update:
    Tests are marked as failed for any generic errors, not just failing expectations.
  • Loading branch information
zsigmas committed Jun 19, 2024
1 parent 72eda62 commit f56bdbd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
53 changes: 34 additions & 19 deletions inst/validation/utils-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,42 @@ local({
} # This should be covered by pack of constants but just in case
} else {
spec_id_chr <- spec_id
}
structure(desc, spec_id = spec_id_chr, spec = spec)
}
paste0(desc, "__spec_ids{", paste0(spec_id_chr, collapse = ";"), "}")
},
get_spec = function(result) {
lapply(
result,
function(x) {
first_result <- try(
x[[1]][["test"]],
silent = TRUE
)
if (inherits(first_result, "try-error")) {
list(spec_id = NULL, desc = NULL)
} else {
list(
spec_id = attr(first_result, "spec_id", exact = TRUE),
spec = attr(first_result, "spec", exact = TRUE)
)
}
get_spec = function(test, specs) {
spec_ids <- utils::strcapture(
pattern = "__spec_ids\\{(.*)\\}",
x = test,
proto = list(spec = character())
)[["spec"]]

spec_ids <- strsplit(spec_ids, split = ";")

specs_and_id <- list()

for (idx in seq_along(spec_ids)){
ids <- spec_ids[[idx]]
if(all(!is.na(ids))){

Check warning on line 131 in inst/validation/utils-validation.R

View workflow job for this annotation

GitHub Actions / Lintr 🔍 / ghcr.io/boehringer-ingelheim/r_4.3.2_cran_2024.01.12:latest

file=inst/validation/utils-validation.R,line=131,col=11,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.

Check warning on line 131 in inst/validation/utils-validation.R

View workflow job for this annotation

GitHub Actions / Lintr 🔍 / ghcr.io/boehringer-ingelheim/r_4.3.2_cran_2024.01.12:latest

file=inst/validation/utils-validation.R,line=131,col=29,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 131 in inst/validation/utils-validation.R

View workflow job for this annotation

GitHub Actions / Lintr 🔍 / ghcr.io/boehringer-ingelheim/r_4.3.2_cran_2024.01.12:latest

file=inst/validation/utils-validation.R,line=131,col=29,[paren_body_linter] There should be a space between a right parenthesis and a body expression.
this_specs <- list()
for (sub_idx in seq_along(ids)) {
id <- ids[[sub_idx]]
this_specs[[sub_idx]] <- eval(str2expression(paste0("specs$", id)))
}
)
specs_and_id[[idx]] <- list(
spec_id = ids,
spec = this_specs
)
} else {
specs_and_id[[idx]] <- list(
spec_id = NULL,
spec = NULL
)
}
}
specs_and_id
}


)
})
5 changes: 2 additions & 3 deletions inst/validation/val_report_child.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ suppressPackageStartupMessages(stopifnot(requireNamespace("devtools")))
# Parse tests ----
tests <- as.data.frame(params[["tests"]])
tests[["validation_data"]] <- vdoc[["get_spec"]](tests[["result"]])
tests[["validation_data"]] <- vdoc[["get_spec"]](tests[["test"]], vdoc[["specs"]])
tests[["spec_id"]] <- sapply(tests[["validation_data"]], function(x) x[["spec_id"]])
tests[["spec"]] <- sapply(tests[["validation_data"]], function(x) x[["spec"]])
tests[["spec_id_paste"]] <- vapply(tests[["spec_id"]], function(x) paste(x, collapse = "\n"), FUN.VALUE = character(1))
Expand All @@ -49,8 +49,7 @@ undeclared_spec <- tested_spec[!tested_spec %in% declared_spec]
spec_tests[["are_declared"]] <- sapply(spec_tests[["spec_id"]], function(x) all(x %in% declared_spec))
# Count tests in the different categories ----
mask_failed <- !!spec_tests[["failed"]]
mask_failed <- !!spec_tests[["failed"]] | spec_tests[["error"]]
mask_skipped <- !!spec_tests[["skipped"]]
mask_declared <- spec_tests[["are_declared"]]
n_pass_dec <- sum(!mask_failed & !mask_skipped & mask_declared)
Expand Down

0 comments on commit f56bdbd

Please sign in to comment.