Learn R Programming

testCoverage (version 0.1.02)

reportCoverage: Low level function to perform code coverage test .

Description

This function reports on the test coverage provided by a suite of unit tests on a set of source files. Either a package or a disorganised set of files may be used but if a package is being used the source must be available.

Usage

reportCoverage(packagename = "", packagedir = getwd(), htmlwd = getwd(), rdir = file.path(packagedir, "R"), unittestdir = file.path(packagedir, "inst", "tests"), sourcefiles = NULL, executionfiles = NULL, reportfile = file.path(htmlwd, "coverage_report.html"), outputfile = file.path(htmlwd, "traceOutput.txt"), ignorelist = "", writereport = TRUE, clean = FALSE, verbose = TRUE, refnamespaces = NULL, isrunit = FALSE, runitfileregexp = "^test_.+\\.[rR]$", runitfuncregexp = "^test.+")

Arguments

packagename
Name of package. Optional if sourcefiles and executionfiles are specified instead.
packagedir
Path to package directory. Optional if sourcefiles and executionfiles are specified instead.
htmlwd
Directory to output HTML reports. Uses getwd() by default.
rdir
Source code directory. Assumes R/ if not specified.
unittestdir
Unit test directory. Assumes inst/tests/ if not specified.
sourcefiles
Character vector of absolute file paths of source code. Optional if a package is specified.
executionfiles
Character vector of absolute file paths of unit tests to run. Optional is a package is specified.
reportfile
Report filename. "test.html" by default.
outputfile
Output filename. "traceOutput.txt" by default.
ignorelist
Ignore list. Empty by default.
clean
Should trace tables be removed? FALSE by default.
writereport
Should an HTML be created? Default is TRUE.
refnamespaces
Vector of namespaces where ::: referecing should be intercepted. NULL by default.
isrunit
Are the tests RUnit? Assumes testthat by default.
runitfileregexp
Regexp to check runit filenames against.
runitfuncregexp
Regexp to check runit function names against.

Value

List where output$A contains a matrix of trace counts and output$B contains a sublist with counts for individual unit test files.

Details

The source files and unit test files must be specified either by passing the packagedir parameter and letting the function use default folders or by specifiying a vector of filenames in sourcefiles and executionfiles.

Generated HTML reports will be opened in the default browser. An internet connection is required to download external javascript resources that enable code annotation.

See Also

vignette("testCoverage", package = "testCoverage")

Examples

Run this code
## Not run: 
# reportCoverage(
#  sourcefiles = system.file("examples/add/R/add.R", package = "testCoverage"),
#  executionfiles = system.file("examples/add/inst/tests/testthat/",
#   c("tests0/test_add0.R", "tests1/test_add1.R"), package = "testCoverage"))
# 
# #If the unit tests are in the inst/tests folder the unittestdir parameter is
# #unnecessary.
# reportCoverage(
#  packagedir = system.file("examples/add/", package = "testCoverage"),
#  unittestdir = system.file("examples/add/inst/tests/testthat/tests1",
#    package = "testCoverage"))
# ## End(Not run)

Run the code above in your browser using DataLab