2121# ' (Environment variable: `R_TESTME_NAME`)
2222# ' --not-cran Set environment variable `NOT_CRAN=true`
2323# ' --covr=summary Estimate test code coverage with basic summary
24+ # ' --covr=tally Estimate test code coverage with full tally summary
2425# ' --covr=report Estimate test code coverage with full HTML report
2526# ' --debug Output debug messages
2627# ' (Environment variable: `R_TESTME_DEBUG`)
@@ -105,7 +106,7 @@ main <- function() {
105106 if (! nzchar(value )) {
106107 covr <- " summary"
107108 } else {
108- covr <- match.arg(value , choices = c(" summary" , " report" ))
109+ covr <- match.arg(value , choices = c(" summary" , " tally " , " report" ))
109110 }
110111 cmd_args <- cmd_args [- idx ]
111112 } else {
@@ -114,7 +115,7 @@ main <- function() {
114115 value <- as.logical(value )
115116 covr <- if (value ) " summary" else " none"
116117 } else {
117- covr <- match.arg(value , choices = " report" )
118+ covr <- match.arg(value , choices = c( " summary " , " tally " , " report" ) )
118119 }
119120 }
120121 if (covr != " none" ) {
@@ -289,51 +290,8 @@ testme_run_test <- function(testme) {
289290 if (testme [[" debug" ]]) message(" Running test script: " , sQuote(testme [[" script" ]]))
290291 testme [[" status" ]] <- " failed"
291292 if (testme [[" covr" ]] != " none" ) {
292- source_dirs <- c(" R" , " src" )
293- source_dirs <- source_dirs [utils :: file_test(" -d" , source_dirs )]
294- source_files <- dir(source_dirs , pattern = " [.]R$" , full.names = TRUE )
295- stopifnot(length(source_files ) > 0 )
296-
297- assign(" .packageName" , testme [[" package" ]], envir = globalenv())
298-
299- # # Attach imported packages
300- # library(testme[["package"]], character.only = TRUE)
301- # desc <- utils::packageDescription(testme[["package"]])
302- # pkgs <- desc[["Imports"]]
303- # pkgs <- strsplit(pkgs, split = ",", fixed = TRUE)[[1]]
304- # pkgs <- gsub("[[:space:]]", "", pkgs)
305- # lapply(pkgs, FUN = library, character.only = TRUE)
306-
307- # # Copy imports
308- ns <- getNamespace(testme [[" package" ]])
309- ns <- parent.env(ns )
310- for (name in names(ns )) {
311- obj <- get(name , envir = ns , inherits = FALSE )
312- assign(name , obj , envir = globalenv(), inherits = FALSE )
313- }
314-
315- # # Copy non-exported 'NativeSymbolInfo':s
316- ns <- getNamespace(testme [[" package" ]])
317- for (name in names(ns )) {
318- if (! exists(name , mode = " list" , envir = ns , inherits = FALSE )) next
319- obj <- get(name , mode = " list" , envir = ns , inherits = FALSE )
320- if (! inherits(obj , " NativeSymbolInfo" )) next
321- assign(name , obj , envir = globalenv(), inherits = FALSE )
322- }
323-
324- # # Register S3 methods
325- library(testme [[" package" ]], character.only = TRUE )
326- ns <- getNamespace(testme [[" package" ]])
327- ns2 <- ns [[" .__S3MethodsTable__." ]]
328- for (name in names(ns2 )) {
329- pattern <- " (.*)[.]([^.]+)$"
330- genname <- gsub(pattern , " \\ 1" , name )
331- class <- gsub(pattern , " \\ 2" , name )
332- method <- ns2 [[name ]]
333- registerS3method(genname , class , method , envir = ns )
334- }
335-
336- cov <- covr :: file_coverage(source_files , test_files = testme [[" script" ]])
293+ pkg_env <- pkgload :: load_all()
294+ cov <- covr :: environment_coverage(pkg_env [[" env" ]], test_files = testme [[" script" ]])
337295 # # Keep source files with non-zero coverage
338296 tally <- covr :: tally_coverage(cov )
339297 tally <- subset(tally , value > 0 )
@@ -344,11 +302,6 @@ testme_run_test <- function(testme) {
344302 source(testme [[" script" ]], echo = TRUE )
345303 }
346304 testme [[" status" ]] <- " success"
347-
348- # ## In case test script overwrote some elements in 'testme'
349- # for (name in names(testme_config)) {
350- # testme[[name]] <- testme_config[[name]]
351- # }
352305 }
353306
354307
@@ -392,7 +345,11 @@ testme_run_test <- function(testme) {
392345 message(" Source files covered by the test script:" )
393346 if (length(cov ) > 0 ) {
394347 print(cov )
395- if (testme [[" covr" ]] == " report" ) {
348+ if (" tally" %in% testme [[" covr" ]]) {
349+ tally <- covr :: tally_coverage(cov )
350+ print(tally )
351+ }
352+ if (" report" %in% testme [[" covr" ]]) {
396353 html <- covr :: report(cov , browse = FALSE )
397354 browseURL(html )
398355 Sys.sleep(5.0 )
0 commit comments