loading...

The 'svSuiteData' object contains results of all test run in one or more test suites. The checkxxx() functions and the runTest() method generate data (objects 'svTestData') contained in the default 'svSuiteData' named .Log and located in .GlobalEnv. It is then possible to display and report information it contains in various ways to analyze the results.

is.svSuiteData(x)

# S3 method for svSuiteData
stats(object, ...)

metadata(object, ...)

# S3 method for svSuiteData
metadata(
  object,
  fields = c("R.version", "sessionInfo", "time", "description"),
  ...
)

# S3 method for svSuiteData
print(x, all = FALSE, file = "", append = FALSE, ...)

# S3 method for svSuiteData
summary(object, ...)

protocol(object, type = "text", file = "", append = FALSE, ...)

# S3 method for default
protocol(object, type = "text", file = "", append = FALSE, ...)

# S3 method for svSuiteData
protocol(object, type = "text", file = "", append = FALSE, ...)

protocol_text(object, file = "", append = FALSE, ...)

# S3 method for svSuiteData
protocol_text(object, file = "", append = FALSE, ...)

protocol_junit(object, ...)

# S3 method for svSuiteData
protocol_junit(object, file = "", append = FALSE, ...)

Arguments

x

Any kind of object, or a 'svSuiteData' object in the case of print().

object

A 'svSuiteData' object.

...

Further arguments to pass to methods. Not used yet.

fields

Character vector. The name of all metadata items you want to extract for the object. The default value is an exhaustive list of all available metadata (i.e., defined by default) in the object, but you can add more: just add a corresponding attribute to your object.

all

Do we print concise report for all test, or only for the tests that fail or produce an error?

file

Character. The path to the file where to write the report. If file = "", the protocol report is output to the console.

append

Do we append to this file?

type

Character. The type of protocol report to create. For the moment, only type = "text" and type = "junit" are supported, but further types (HTML, LaTeX, Wiki, etc.) could be provided later.

Value

is.svSuiteData() returns TRUE if the object is an 'svSuiteData'. The various methods serve to extract or print content in the object.

Details

A 'svSuiteData' is, indeed, an environment. The results for the various tests runs are in non hidden (i.e., names not starting with a dot) objects that are of class 'svTestData' in this environment. Various other objects that control the execution of the test, their context, etc. are contained as hidden objects with name starting with a dot. Note that using an environment instead of a list for this object allows for a call by reference instead of a usual call by value in R, when passing this object to a function. This property is largely exploited in all svUnit functions to make sure results of test runs are centralized in the same log ('svSuiteData' object).

Author

Philippe Grosjean; Mario Frasca for the junit protocol.

Examples

clearLog()    # Clear any existing log

# Run some tests
checkTrue(1 < 2)
checkException(log("a"))
foo <- function(x, y = 2)
  return(x * y)
test(foo) <- function() {
  checkEqualsNumeric(4, foo(2))
  checkEqualsNumeric(6, foo(2, nonexisting))
  checkTrue(is.test(foo))
  warning("This is a warning")
  cat("Youhou from test!\n")  # Don't use, except for debugging!
  checkTrue(is.test(test(foo)))
  checkIdentical(attr(foo, "test"), test(foo))
  checkException(foo(2, nonexisting))
  #DEACTIVATED("My deactivation message")
  checkException(foo(2))  # This test fails
}
runTest(foo)
#> * : checkEqualsNumeric(6, foo(2, nonexisting)) run in less than 0.001 sec ... **ERROR**
#> Error in foo(2, nonexisting) : object 'nonexisting' not found
#> Youhou from test!
#> * : checkException(foo(2)) run in less than 0.001 sec ... **FAILS**
#> No exception generated!

# Now inspect the log, which is a 'svSuiteData' object
is.svSuiteData(Log())
#> [1] TRUE
stats(Log())
#>                kind timing                time unit msg
#> test(foo) **ERROR**      0 2022-05-10 07:44:22         
#> eval             OK      0 2022-05-10 07:44:22         
metadata(Log())
#> $.R.version
#>                _                           
#> platform       x86_64-pc-linux-gnu         
#> arch           x86_64                      
#> os             linux-gnu                   
#> system         x86_64, linux-gnu           
#> status                                     
#> major          4                           
#> minor          2.0                         
#> year           2022                        
#> month          04                          
#> day            22                          
#> svn rev        82229                       
#> language       R                           
#> version.string R version 4.2.0 (2022-04-22)
#> nickname       Vigorous Calisthenics       
#> 
#> $.sessionInfo
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C           LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] svUnit_1.0.6
#> 
#> loaded via a namespace (and not attached):
#>  [1] pillar_1.7.0      compiler_4.2.0    tools_4.2.0       digest_0.6.29    
#>  [5] downlit_0.4.0     memoise_2.0.1     evaluate_0.15     lifecycle_1.0.1  
#>  [9] tibble_3.1.7      pkgconfig_2.0.3   rlang_1.0.2       cli_3.3.0        
#> [13] curl_4.3.2        yaml_2.3.5        pkgdown_2.0.3     xfun_0.30        
#> [17] fastmap_1.1.0     withr_2.5.0       httr_1.4.3        knitr_1.39       
#> [21] xml2_1.3.3        systemfonts_1.0.4 desc_1.4.1        fs_1.5.2         
#> [25] vctrs_0.4.1       rprojroot_2.0.3   glue_1.6.2        R6_2.5.1         
#> [29] textshaping_0.3.6 processx_3.5.3    fansi_1.0.3       rmarkdown_2.14   
#> [33] callr_3.7.0       purrr_0.3.4       magrittr_2.0.3    whisker_0.4      
#> [37] ps_1.7.0          ellipsis_0.3.2    htmltools_0.5.2   ragg_1.2.2       
#> [41] utf8_1.2.2        cachem_1.0.6      crayon_1.5.1      svPkgdown_0.1.2  
#> 
#> $.time
#> [1] "2022-05-10 07:44:22 UTC"
#> 
Log()    # Print method
#> = A svUnit test suite run in less than 0.1 sec with:
#> 
#> * test(foo) ... **ERROR**
#> * eval ... OK
#> 
#> 
#> == test(foo) run in less than 0.1 sec: **ERROR**
#> 
#> //Pass: 5 Fail: 1 Errors: 1//
#> 
#> * : checkEqualsNumeric(6, foo(2, nonexisting)) run in less than 0.001 sec ... **ERROR**
#> Error in foo(2, nonexisting) : object 'nonexisting' not found
#> 
#> * : checkException(foo(2)) run in less than 0.001 sec ... **FAILS**
#> No exception generated!
#> 
#> == eval run in less than 0.1 sec: OK
#> 
#> //Pass: 2 Fail: 0 Errors: 0//
#> 
summary(Log())
#> = A svUnit test suite run in less than 0.1 sec with:
#> 
#> * test(foo) ... **ERROR**
#> * eval ... OK
#> 
#> 
#> == test(foo) run in less than 0.1 sec: **ERROR**
#> 
#> //Pass: 5 Fail: 1 Errors: 1//
#> 
#> === Failures
#> [7] : checkException(foo(2))
#> 
#> === Errors
#> [2] : checkEqualsNumeric(6, foo(2, nonexisting))
#> 
#> 
#> == eval run in less than 0.1 sec: OK
#> 
#> //Pass: 2 Fail: 0 Errors: 0//
#> 

if (FALSE) {
# To get a print of the test protocol on file, use:
protocol(Log(), type = "text", file = "RprofProtocol.out")
file.show("RprofProtocol.out")
unlink("RprofProtocol.out")
}

rm(foo)

if (FALSE) {
# Profiling of very simple test runs
library(utils)
createLog(description = "test profiling", deleteExisting = TRUE)
imax <- 3
jmax <- 100
l <- 50
Rprof()
for (i in 1:imax) {
  # Change the context for these tests
  .Log$..Test <- paste("Test", i, sep = "")
  .Log$..Tag <- paste("#", i, sep = "")
  res <- system.time({
    for (j in 1:jmax) checkTrue(i <= j, "My test")
  }, gcFirst = TRUE)[3]
  print(res)
  flush.console()
}
Rprof(NULL)
# Look at profile
summaryRprof()
unlink("Rprof.out")

# Look at the log
summary(Log())
}