Skip to content

Commit 16a349a

Browse files
fix for additional test code via package_coverage(..., code = .) (#481)
* fix running additional test code: write 'commands' line-by-line * Add note to news Co-authored-by: Jim Hester <[email protected]>
1 parent c21832c commit 16a349a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# covr (development version)
22

3+
* `package_coverage(code = )` now accepts character vectors of length greater than 1 (@bastistician, #481)
4+
35
* `report()` now provides a more detailed error message if the `DT` and `htmltools` dependencies are not installed (#500).
46

57
* Added `covr.record_tests` option. When `TRUE`, this enables the recording of

R/covr.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,9 @@ run_vignettes <- function(pkg, lib) {
734734
run_commands <- function(pkg, lib, commands) {
735735
outfile <- file.path(lib, paste0(pkg$package, "-commands.Rout"))
736736
failfile <- paste(outfile, "fail", sep = "." )
737-
cat(
738-
"library('", pkg$package, "')\n",
739-
commands, "\n", file = outfile, sep = "")
737+
writeLines(c(
738+
paste0("library('", pkg$package, "')"),
739+
commands), con = outfile)
740740
cmd <- paste(shQuote(file.path(R.home("bin"), "R")),
741741
"CMD BATCH --vanilla --no-timing",
742742
shQuote(outfile), shQuote(failfile))

tests/testthat/test-package_coverage.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ test_that("package_coverage with type == 'none' runs no test code", {
2929

3030
expect_equal(percent_coverage(cov), 0.00)
3131
})
32+
33+
test_that("package_coverage runs additional test code", {
34+
cov <- package_coverage("TestS4", type = "none", code = c("a(1)", "a(2)"))
35+
36+
expect_gt(percent_coverage(cov), 0.00)
37+
})

0 commit comments

Comments
 (0)