MyNixOS website logo
Description

Fuzz-Test R Functions.

Test function arguments with a wide array of inputs, and produce reports summarizing messages, warnings, errors, and returned values.

fuzzr

Project Status: Active - The project has reached a stable, usablestate and is being activelydeveloped. CRAN_Status_Badge Travis-CI BuildStatus AppVeyor BuildStatus

fuzzr implements some simple “fuzz tests” for your R functions, passing in a wide array of inputs and returning a report on how your function reacts.

Installation

install.package("fuzzr")

# Or, for the development version:
devtools::install_github("mdlincoln/fuzzr")

Usage

Tests are set by passing functions that return named lists of input values. These values will be passed as function arguments. Several default suites are provided with this package, such as test_char, however you may implement your own by passing a function that returns a similarly-formatted list.

library(fuzzr)
str(test_char())
#> List of 8
#>  $ char_empty         : chr(0) 
#>  $ char_single        : chr "a"
#>  $ char_single_blank  : chr ""
#>  $ char_multiple      : chr [1:3] "a" "b" "c"
#>  $ char_multiple_blank: chr [1:4] "a" "b" "c" ""
#>  $ char_with_na       : chr [1:3] "a" "b" NA
#>  $ char_single_na     : chr NA
#>  $ char_all_na        : chr [1:3] NA NA NA

Evaluate a function argument by supplying fuzz_function its quoted name, the tests to run, along with any other required static values. fuzz_function returns a fuzz_results object that stores conditions raised by a function (message, warning, or error) along with any value returned by that function.

fuzz_results <- fuzz_function(fun = lm, arg_name = "subset", data = iris, 
                              formula = Sepal.Length ~ Petal.Width + Petal.Length, 
                              tests = test_all())
#> Warning: `cross_n()` is deprecated; please use `cross()` instead.

#> Warning: `cross_n()` is deprecated; please use `cross()` instead.
#> Warning: at_depth() is deprecated, please use `modify_depth()` instead

You can render these results as a data frame:

fuzz_df <- as.data.frame(fuzz_results)
knitr::kable(head(fuzz_df))
subsetdataformulaoutputmessageswarningserrorsresult_classesresults_index
char_emptyirisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA1
char_singleirisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA2
char_single_blankirisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA3
char_multipleirisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA4
char_multiple_blankirisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA5
char_with_nairisSepal.Length ~ Petal.Width + Petal.LengthNANANA0 (non-NA) casesNA6

You can also access the value returned by any one test by matching the argument tested with its test name:

model <- fuzz_value(fuzz_results, subset = "int_multiple")
coefficients(model)
#>  (Intercept)  Petal.Width Petal.Length 
#>          0.8           NA          3.0

Multiple-argument tests

Specify multiple-argument tests with p_fuzz_function, passing a named list of arguments and tests to run on each. p_fuzz_function will test every combination of argument and variable.

fuzz_p <- p_fuzz_function(agrep, list(pattern = test_char(), x = test_char()))
#> Warning: `cross_n()` is deprecated; please use `cross()` instead.

#> Warning: `cross_n()` is deprecated; please use `cross()` instead.
#> Warning: at_depth() is deprecated, please use `modify_depth()` instead
length(fuzz_p)
#> [1] 64
knitr::kable(head(as.data.frame(fuzz_p)))
patternxoutputmessageswarningserrorsresult_classesresults_index
char_emptychar_emptyNANANAinvalid ‘pattern’ argumentNA1
char_singlechar_emptyNANANANAinteger2
char_single_blankchar_emptyNANANA‘pattern’ must be a non-empty character stringNA3
char_multiplechar_emptyNANAargument ‘pattern’ has length > 1 and only the first element will be usedNAinteger4
char_multiple_blankchar_emptyNANAargument ‘pattern’ has length > 1 and only the first element will be usedNAinteger5
char_with_nachar_emptyNANAargument ‘pattern’ has length > 1 and only the first element will be usedNAinteger6

Matthew Lincoln.

Metadata

Version

0.2.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows