Learn R Programming

covr (version 4.0.0)

function_coverage: Calculate test coverage for a specific function.

Description

Calculate test coverage for a specific function.

Usage

function_coverage(fun, code = NULL, env = NULL, enc = parent.frame())

Value

A coverage object.

Arguments

fun

name of the function.

code

expressions to run.

env

environment the function is defined in.

enc

the enclosing environment which to run the expressions.

Parallel code

Code run in processes forked by parallel::mclapply(), parallel::mcparallel() and related functions (not available on Windows) is included in the coverage. While the code runs, parallel:::mcfork and parallel:::mcexit are patched so that the forked processes save their counts when they exit. To turn this off, set the option covr.fix_parallel_mcexit or the environment variable COVR_FIX_PARALLEL_MCEXIT to FALSE.

Examples

Run this code
add <- function(x, y) { x + y }
function_coverage(fun = add, code = NULL) # 0% coverage
function_coverage(fun = add, code = add(1, 2) == 3) # 100% coverage

Run the code above in your browser using DataLab