Package 'genthat'

Title: A Framework for Unit Tests Generation
Description: Generates 'testthat' compatible unit tests by tracing the execution of runnable R code, recording the arguments and return values of function calls, and turning them into reproducible test cases.
Authors: Filip Krikava [aut, cre], Roman Tsegelskyi [aut], Petr Maj [aut], Filippo Ghibellini [ctb], Michal Vacha [ctb], Lei Zhao [ctb]
Maintainer: Filip Krikava <[email protected]>
License: GPL (>= 2)
Version: 0.1.8
Built: 2026-07-16 23:53:36 UTC
Source: https://github.com/PRL-PRG/genthat

Help Index


Creates a copy of traces captured so far and returns them as R list.

Usage

copy_traces(tracer)

Decorates functions in an environment

Description

Decorates all symbols form the given environment for which 'is.function' is 'TRUE'.

Usage

decorate_environment(env, decorator = get_decorator(),
  record_fun = substitute(genthat:::record_trace), exclude = character())

Arguments

envir

an environment that shall be decorated or a character scalar that will be resolved using 'as.environment("package:....")'. In the latter case, the package will also be loaded in the case it has not been loaded yet.


Decorates given functions

Description

Given function will be decorated in their defining environment.

Usage

decorate_function(fun, name = substitute(fun),
  record_fun = substitute(genthat:::record_trace),
  decorator = get_decorator(), env = parent.frame())

Arguments

fun

the function that shall be decorated


Downloads R package

Description

Downloads R package.

Usage

download_package(package, destdir, version = NULL,
  repos = getOption("repos"), type = "source", extract = TRUE,
  force = FALSE, quiet = TRUE, ...)

Generate test case code from a trace

Description

Given a genthat trace it generates a corresponding test case

Usage

generate_test(trace, ...)

Arguments

trace

trace value

include_trace_dump

whether to include raw trace at the beginning of the test the trace is formatted using 'str' function.


generate test from a trace

Description

given a trace, it generates a test and stores it in a file

Usage

generate_test_file(trace, output_dir, ...)

Value

a data frame with the following pkg : chr fun : chr filename : chr (can be NA in which case error must be a chr) error : chr (can be NA in which case code must be NA) elapsed : numeric (can be NA)


genthat: A framework for unit tests generation

Description

genthat: A framework for unit tests generation


Gets the latest package version

Description

Returns the latest version of a given package that is available in the given repository.

Usage

get_package_version(package, repos = getOption("repos"), type = "source")

Clears the captured traces

Usage

reset_traces(tracer)

Resets decorated function back to its original

Description

Reverts decorated function back to their state they were before calling 'decorate_function'.

Usage

reset_function(fun, name = substitute(fun), decorator = get_decorator(),
  env = parent.frame())

Stores given trace to the tracer

Usage

store_trace(tracer, trace)

Decorate all functions from given package and runs package code

Description

Decorates all functions in a package and then generates test cases based on the code contained in the package examples, vignettes and tests.

Usage

trace_package(pkgs, files_to_run, output_dir = ".", decorator = "on.exit",
  tracer = "set", action = c("stats", "export", "generate"),
  working_dir = tempfile(pattern = "genthat-trace-"), quiet = TRUE,
  lib_paths = NULL)

Arguments

output_dir

the name of the directory where to output traces or NULL if traces should not be saved