generateAllUnitTestsFromObject: Generate All Unit Tests From Object

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/generateAllUnitTestsFromObject.R

Description

Generate testthat code form an instrumented offensive programming object.

Usage

1
2
3
generateAllUnitTestsFromObject(object_o_1, sourceFile_s_1,
                               sourcePackage_s_1, targetFolder_s_1,
                               overwriteFile_b_1 = TRUE, verbose_b_1 = FALSE)

Arguments

object_o_1

the instrumented offensive programming object to consider

sourceFile_s_1

the source package file related to the offensive programming object

sourcePackage_s_1

the package name that holds the offensive programming object

targetFolder_s_1

the folder where to write produced testthat code files

overwriteFile_b_1

A boolean value, either TRUE or FALSE to switch on or off the overwritting of the output file. Beware, as it is on by default!

verbose_b_1

A boolean value, either TRUE or FALSE to switch on or off the processing verbosity!

Details

Generates automatically, all the testthat files with compliant testthat code, from the offensive programming object.

Value

A list with two fields named class and filenames. Former provides the class of the analyzed and mined offensive programming object, the latter gives back all produced testthat file names.

Note

This is rather easy to use function that implements a quite complex algorithm based on meta-programmation to generate testthat code.

Author(s)

Fabien Gelineau <neonira@gmail.com>

Maintainer: Fabien Gelineau <neonira@gmail.com>

References

See EvaluationMode for more information.

Refer to test_file from package testthat.

Refer to runTestCase from package wyz.code.offensiveProgramming.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(data.table)
library(wyz.code.offensiveProgramming)
library(wyz.code.testthat)

source_file <- 'code-samples/both-defs/good/full/AdditionTCFIG1.R'
source_package <- 'wyz.code.offensiveProgramming'
source(system.file(source_file, package = source_package))

object <- AdditionTCFIG1()
g <- gautfo(object, source_file, source_package, tempdir())
print(g)
# $class
# [1] "AdditionTCFIG1"
#
# $filenames
#                                                 filename overwritten
# 1:       /tmp/RtmpKLCrXA/test_AdditionTCFIG1-addDouble.R        TRUE
# 2:      /tmp/RtmpKLCrXA/test_AdditionTCFIG1-addInteger.R        TRUE
# 3:    /tmp/RtmpKLCrXA/test_AdditionTCFIG1-divideByZero.R        TRUE
# 4: /tmp/RtmpKLCrXA/test_AdditionTCFIG1-generateWarning.R        TRUE
# 5:   /tmp/RtmpKLCrXA/test_AdditionTCFIG1-generateError.R        TRUE
# 6:  /tmp/RtmpKLCrXA/test_AdditionTCFIG1-addMultiDouble.R        TRUE
# 7: /tmp/RtmpKLCrXA/test_AdditionTCFIG1-addMultiInteger.R        TRUE

wyz.code.testthat documentation built on Oct. 6, 2021, 9:07 a.m.