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)
# Now inspect the log, which is a 'svSuiteData' object
is.svSuiteData(Log())
stats(Log())
metadata(Log())
Log()    # Print method
summary(Log())
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())
}
Run the code above in your browser using DataLab