Skip to content

Commit

Permalink
format_appendix: replace empty coverage table with note
Browse files Browse the repository at this point in the history
External scorers are responsible for providing the *.coverage.json,
and that file can have an overall coverage score but not per file
scores.  If there are no rows in the coverage table, replace the table
with a note to make it clear that this is expected rather than a
rendering error.

Thanks to @seth127 for the suggestion.

Re: #70 (comment)
  • Loading branch information
kyleam committed Aug 12, 2024
1 parent 24bdf6a commit e17a7c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/format-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ format_appendix <- function(extra_notes_data, return_vals = FALSE, scorecard_typ
} else {
stop("Unknown error type: ", err_type)
}
} else if (nrow(cov_results_df) == 0) {
cat("Per file test coverage not provided.")
} else {
cat(knitr::knit_print(cov_results_flex))
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-format-report-external.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,22 @@ describe("formatting functions with external scores", {
"check\noutput\n"
)
})

it("format_appendix: no per file coverage", {
results_dir <- local_create_external_results()
covfile <- get_result_path(results_dir, "coverage.json")
cov <- jsonlite::read_json(covfile)
cov[["files"]] <- list()
jsonlite::write_json(cov, covfile)

expect_output(
format_appendix(
list(
check_output = "anything",
cov_results_df = read_coverage_results(results_dir)
)
),
"Per file test coverage not provided"
)
})
})

0 comments on commit e17a7c9

Please sign in to comment.