Title: | Wizardry Code Offensive Programming Test Generation |
---|---|
Description: | Allows to generate automatically 'testthat' code files from offensive programming test cases. Generated test files are complete and ready to run. Using 'wyz.code.testthat' you will earn a lot of time, reduce the number of errors in test case production, be able to test immediately generated files without any need to view or modify them, and enter a zero time latency between code implementation and industrial testing. As with 'testthat', you may complete provided test cases according to your needs to push testing further, but this need is nearly void when using 'wyz.code.offensiveProgramming'. |
Authors: | Fabien Gelineau <[email protected]> |
Maintainer: | Fabien Gelineau <[email protected]> |
License: | GPL-3 |
Version: | 1.1.20 |
Built: | 2024-11-09 04:07:34 UTC |
Source: | https://github.com/cran/wyz.code.testthat |
Generate testthat
code form an instrumented offensive programming object.
generateAllUnitTestsFromObject(object_o_1, sourceFile_s_1, sourcePackage_s_1, targetFolder_s_1, overwriteFile_b_1 = TRUE, verbose_b_1 = FALSE)
generateAllUnitTestsFromObject(object_o_1, sourceFile_s_1, sourcePackage_s_1, targetFolder_s_1, overwriteFile_b_1 = TRUE, verbose_b_1 = FALSE)
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
|
overwriteFile_b_1 |
A boolean value, either |
verbose_b_1 |
A boolean value, either |
Generates automatically, all the testthat
files
with compliant testthat
code,
from the offensive programming object.
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.
This is rather easy to use function that implements a quite complex algorithm
based on meta-programmation to generate testthat
code.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
See EvaluationMode
for more information.
Refer to test_file
from package
testthat
.
Refer to runTestCase
from package
wyz.code.offensiveProgramming
.
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
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
Generate one testthat
unit test file from an instrumented offensive
programming object. One test file per function is created. It holds all the
related tests, organized by evaluation mode.
See EvaluationMode
for more information.
generateUnitTestFile(filename_s_1, content_s, overwrite_b_1 = FALSE, verbose_b_1 = TRUE)
generateUnitTestFile(filename_s_1, content_s, overwrite_b_1 = FALSE, verbose_b_1 = TRUE)
filename_s_1 |
the name of the unit test file to generate |
content_s |
the content of the unit test file to generate |
overwrite_b_1 |
A boolean value, either |
verbose_b_1 |
A boolean value, either |
Returns the file name.
It might be different from the one provided, as
testthat
requires to follow some file naming conventions that are enforced by this function.
This function is provided for convenience. It may ease your own way to generate
testthat
code.
To put this package in action, simply use gautfo
that offers a much more straightforward way to get results.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to test_file
from package
testthat
.
Refer to runTestCase
from package wyz.code.offensiveProgramming
.
##---- typical example ---- fn <- file.path(tempdir(), 'myFile') fr <- generateUnitTestFile(fn, c("# a comment", "x <- 2")) cat(paste(readLines(fr$filename), collapse = '\n')) # a comment # x <- 2
##---- typical example ---- fn <- file.path(tempdir(), 'myFile') fr <- generateUnitTestFile(fn, c("# a comment", "x <- 2")) cat(paste(readLines(fr$filename), collapse = '\n')) # a comment # x <- 2
list package functions
opTestthatInformation()
opTestthatInformation()
A data.table
with following columns
name |
the object name |
category |
the category of the object describe by function name. Could be
|
nature |
either |
stratum |
the stratum the object belongs to. Values are |
phasing |
main usage phase of the object. Values are |
intent |
main global intent of the object. Values are |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
opTestthatInformation() opTestthatInformation()[stratum == 'CORE']
opTestthatInformation() opTestthatInformation()[stratum == 'CORE']
testthat
code
Produces testthat
code from an instrumented offensive
programming object.
testthatFactory()
testthatFactory()
Returns a function that manages dispatch depending on targeted offensive programming object test case evaluation mode value.
This function is provided for convenience. It may ease your own way to generate
testthat
code from an instrumented offensive programming object.
To put this package in action, simply use gautfo
that offers a
much more straightforward way to get results.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
See EvaluationMode
for more information.
Refer to test_file
from package
testthat
.
Refer to runTestCase
from package wyz.code.offensiveProgramming
.
##---- typical example ---- rv <- testthatFactory()(c(call('isTRUE', TRUE), call('isFALSE', FALSE)), 'correct') print(rv) # [[1]] # expect_true(isTRUE(TRUE)) # # [[2]] # expect_true(isFALSE(FALSE))
##---- typical example ---- rv <- testthatFactory()(c(call('isTRUE', TRUE), call('isFALSE', FALSE)), 'correct') print(rv) # [[1]] # expect_true(isTRUE(TRUE)) # # [[2]] # expect_true(isFALSE(FALSE))