[education/rkward/devel/workspace_output] rkward/rbackend/rpackages/rkwardtests: Allow to ignore generated commands. Add silent parameter to expectedError.

Thomas Friedrichsmeier null at kde.org
Sat Nov 7 16:35:12 GMT 2020


Git commit f228b149f6540b2ca1135d4187eab856c2d33d53 by Thomas Friedrichsmeier.
Committed on 07/11/2020 at 16:32.
Pushed by tfry into branch 'devel/workspace_output'.

Allow to ignore generated commands. Add silent parameter to expectedError.

M  +3    -2    rkward/rbackend/rpackages/rkwardtests/R/RKTest-class.R
M  +6    -5    rkward/rbackend/rpackages/rkwardtests/R/rktest.expectError.R
M  +1    -0    rkward/rbackend/rpackages/rkwardtests/R/rktest.runRKTestSuite.R
M  +1    -1    rkward/rbackend/rpackages/rkwardtests/R/rktest.setSuiteStandards.R
M  +18   -7    rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
M  +2    -0    rkward/rbackend/rpackages/rkwardtests/man/RKTest.Rd
M  +5    -3    rkward/rbackend/rpackages/rkwardtests/man/rktest.expectError.Rd

https://invent.kde.org/education/rkward/commit/f228b149f6540b2ca1135d4187eab856c2d33d53

diff --git a/rkward/rbackend/rpackages/rkwardtests/R/RKTest-class.R b/rkward/rbackend/rpackages/rkwardtests/R/RKTest-class.R
index 5c6b8d55..400a8ba8 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/RKTest-class.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/RKTest-class.R
@@ -10,6 +10,7 @@
 #' @slot libraries A charcter vector naming needed libraries
 #' @slot files A character vector naming needed files, path relative to the test standards directory
 #' @slot record.all.commands Should synchronization commands and commands to generate run-again-links be included in the command recording? Generally, this should be FALSE (the default).
+#' @slot ignore May include one of more of "output", "messages", "commands", for skipping comparison of these against the standard, completely.
 #' @name RKTest
 #' @import methods
 #' @keywords classes
@@ -18,8 +19,8 @@
 # @rdname RKTest-class
 
 setClass ("RKTest",
-		representation (id="character", call="function", fuzzy_output="logical", expect_error="logical", libraries="character", files="character", record.all.commands="logical"),
-		prototype(character(0), id=NULL, call=function () { stop () }, fuzzy_output=FALSE, expect_error=FALSE, libraries=character(0), files=character(0), record.all.commands=FALSE),
+		representation (id="character", call="function", fuzzy_output="logical", expect_error="logical", libraries="character", files="character", record.all.commands="logical", ignore="character"),
+		prototype(character(0), id=NULL, call=function () { stop () }, fuzzy_output=FALSE, expect_error=FALSE, libraries=character(0), files=character(0), record.all.commands=FALSE, ignore=character(0)),
 		validity=function (object) {
 			if (is.null (object at id)) return (FALSE)
 			return (TRUE)
diff --git a/rkward/rbackend/rpackages/rkwardtests/R/rktest.expectError.R b/rkward/rbackend/rpackages/rkwardtests/R/rktest.expectError.R
index 94ba890b..d4333db4 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/rktest.expectError.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/rktest.expectError.R
@@ -4,11 +4,12 @@
 #' \code{rktest.commandFailed()} runs the given statement(s), which is expected to produce an error. Returns TRUE, if the command failed, FALSE, if it succeeded.
 #' \code{rktest.exptectError()} runs the given statement(s), which is expected to produce an error. If the command succeeds, and error is produced.
 #'
-#' @note In both cases, the error message of the original command will still be printed (as a warning), but execution will continue afterwards.
+#' @note In both cases, the error message of the original command will still be printed, unless silent=TRUE (as a warning), but execution will continue afterwards.
 #' 
 #' @aliases rktest.commandFailed rktest.expectError
 #' @param expr Expression to evaluate
 #' @param message Error message to generate, if the expected error failed to occur. If NULL, the deparsed expression itself is cited.
+#' @param silent if TRUE suppress the error message itself (and any warnings).
 #' @rdname rktest.expectError
 #' @return TRUE if the command failed. rktest.commandFailed() returns FALSE, if the command did not fail.
 #' @author Thomas Friedrichsmeier \email{rkward-devel@@kde.org}
@@ -17,23 +18,23 @@
 #' @examples
 #' if(!rktest.commandFailed(stop("Expected error"))) stop("Failed to generate error")
 #' @export
-rktest.commandFailed <- function(expr){
+rktest.commandFailed <- function(expr, silent=FALSE){
   failed = TRUE
   try({
     eval.parent(expr)
     failed = FALSE
-  })
+  }, silent=silent)
   failed
 }
 
 #' @export
 #' @rdname rktest.expectError
-rktest.expectError <- function(expr, message=NULL){
+rktest.expectError <- function(expr, message=NULL, silent=FALSE){
   failed = TRUE
   try({
     eval.parent(expr)
     failed = FALSE
-  })
+  }, silent=silent)
   if(!failed) {
     if(is.null(message)) {
       message = deparse(substitute(expr))
diff --git a/rkward/rbackend/rpackages/rkwardtests/R/rktest.runRKTestSuite.R b/rkward/rbackend/rpackages/rkwardtests/R/rktest.runRKTestSuite.R
index b9a9c4f4..8535117d 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/rktest.runRKTestSuite.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/rktest.runRKTestSuite.R
@@ -27,6 +27,7 @@ rktest.runRKTestSuite <- function (suite, testroot=getwd (), test.id=NULL) {
 	  on.exit(rktest.resetEnvironment())
 	}
 
+	testroot <- testroot  # Need to force this, before calling setwd(), below (in case it's left at the default getwd())
 	result <- new ("RKTestResult")		# FALSE by default
 
 	if (!inherits (suite, "RKTestSuite")) return (result)
diff --git a/rkward/rbackend/rpackages/rkwardtests/R/rktest.setSuiteStandards.R b/rkward/rbackend/rpackages/rkwardtests/R/rktest.setSuiteStandards.R
index acb34ca1..24814e67 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/rktest.setSuiteStandards.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/rktest.setSuiteStandards.R
@@ -1,7 +1,7 @@
 #' Set RKWard plugin test suite standards
 #'
 #' @description
-#' Use this function after you plugin passed all tests to set the resulting code,
+#' Use this function after your plugin passed all tests to set the resulting code,
 #' output and R messages as the standard that will be compared to during following tests.
 #' 
 #' @title Set RKWard suite standards
diff --git a/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R b/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
index 27e79600..e0ac020e 100644
--- a/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
+++ b/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
@@ -162,13 +162,24 @@ rktest.runRKTest <- function (test, standard.path, suite.id) {
 	rktest.cleanTestFile (code_file)
 	rktest.cleanTestFile (message_file)
 
-	result at output_match = rktest.compare.against.standard (output_file, standard.path, test at fuzzy_output)
-	if (result at output_match == "MISMATCH") passed <- FALSE
-	result at message_match = rktest.compare.against.standard (message_file, standard.path)
-	if (result at message_match == "MISMATCH") passed <- FALSE
-	result at code_match = rktest.compare.against.standard (code_file, standard.path)
-	if (result at code_match == "MISMATCH") passed <- FALSE
-
+	if ("output" %in% test at ignore) {
+		result at output_match <- "ignored"
+	} else {
+		result at output_match = rktest.compare.against.standard (output_file, standard.path, test at fuzzy_output)
+		if (result at output_match == "MISMATCH") passed <- FALSE
+	}
+	if ("message" %in% test at ignore) {
+		result at message_match <- "ignored"
+	} else {
+		result at message_match = rktest.compare.against.standard (message_file, standard.path)
+		if (result at message_match == "MISMATCH") passed <- FALSE
+	}
+	if ("code" %in% test at ignore) {
+		result at code_match <- "ignored"
+	} else {
+		result at code_match = rktest.compare.against.standard (code_file, standard.path)
+		if (result at code_match == "MISMATCH") passed <- FALSE
+	}
 	result at passed <- passed
 
 	result
diff --git a/rkward/rbackend/rpackages/rkwardtests/man/RKTest.Rd b/rkward/rbackend/rpackages/rkwardtests/man/RKTest.Rd
index 8e39b792..0994ff5d 100644
--- a/rkward/rbackend/rpackages/rkwardtests/man/RKTest.Rd
+++ b/rkward/rbackend/rpackages/rkwardtests/man/RKTest.Rd
@@ -23,6 +23,8 @@ This class is used internally by \code{\link[rkwardtests:rktest.makeplugintests]
 \item{\code{files}}{A character vector naming needed files, path relative to the test standards directory}
 
 \item{\code{record.all.commands}}{Should synchronization commands and commands to generate run-again-links be included in the command recording? Generally, this should be FALSE (the default).}
+
+\item{\code{ignore}}{May include one of more of "output", "messages", "commands", for skipping comparison of these against the standard, completely.}
 }}
 
 \author{
diff --git a/rkward/rbackend/rpackages/rkwardtests/man/rktest.expectError.Rd b/rkward/rbackend/rpackages/rkwardtests/man/rktest.expectError.Rd
index 5539c007..bca79750 100644
--- a/rkward/rbackend/rpackages/rkwardtests/man/rktest.expectError.Rd
+++ b/rkward/rbackend/rpackages/rkwardtests/man/rktest.expectError.Rd
@@ -5,13 +5,15 @@
 \alias{rktest.expectError}
 \title{Helper functions to check for expected errors}
 \usage{
-rktest.commandFailed(expr)
+rktest.commandFailed(expr, silent = FALSE)
 
-rktest.expectError(expr, message = NULL)
+rktest.expectError(expr, message = NULL, silent = FALSE)
 }
 \arguments{
 \item{expr}{Expression to evaluate}
 
+\item{silent}{if TRUE suppress the error message itself (and any warnings).}
+
 \item{message}{Error message to generate, if the expected error failed to occur. If NULL, the deparsed expression itself is cited.}
 }
 \value{
@@ -22,7 +24,7 @@ TRUE if the command failed. rktest.commandFailed() returns FALSE, if the command
 \code{rktest.exptectError()} runs the given statement(s), which is expected to produce an error. If the command succeeds, and error is produced.
 }
 \note{
-In both cases, the error message of the original command will still be printed (as a warning), but execution will continue afterwards.
+In both cases, the error message of the original command will still be printed, unless silent=TRUE (as a warning), but execution will continue afterwards.
 }
 \examples{
 if(!rktest.commandFailed(stop("Expected error"))) stop("Failed to generate error")




More information about the rkward-tracker mailing list