[Rcpp-commits] r226 - in pkg: . inst inst/doc inst/unitTests tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 29 18:50:40 CET 2009


Author: romain
Date: 2009-12-29 18:50:40 +0100 (Tue, 29 Dec 2009)
New Revision: 226

Added:
   pkg/inst/doc/Makefile
   pkg/inst/doc/Rcpp-unitTests.R
   pkg/inst/doc/Rcpp-unitTests.Rnw
   pkg/inst/doc/index.html
   pkg/inst/unitTests/
   pkg/inst/unitTests/runTests.R
   pkg/inst/unitTests/runit.runit.R
   pkg/tests/
   pkg/tests/doRUnit.R
Modified:
   pkg/cleanup
   pkg/inst/doc/
Log:
prepare the package for unit testing

Modified: pkg/cleanup
===================================================================
--- pkg/cleanup	2009-12-29 16:27:26 UTC (rev 225)
+++ pkg/cleanup	2009-12-29 17:50:40 UTC (rev 226)
@@ -3,7 +3,7 @@
 	src/*.o src/*.so src/*.a src/*.d src/*.dll src/*.rc \
 	RcppSrc/*.o RcppSrc/*.a inst/Rcpp-version.txt \
 	inst/lib/libRcpp.so inst/lib/Rcpp*.h inst/lib/libRcpp.a \
-	inst/doc/*.cpp inst/doc/*.hpp inst/doc/*.R \
+	inst/doc/*.cpp inst/doc/*.hpp \
 	inst/doc/*.Rd inst/doc/*.aux inst/doc/*.log inst/doc/*.tex \
 	inst/doc/latex/*.aux inst/doc/latex/*.log \
 	inst/doc/auto \


Property changes on: pkg/inst/doc
___________________________________________________________________
Name: svn:ignore
   - RcppAPI.pdf
html
latex
man

   + RcppAPI.pdf
html
latex
man
Rcpp-unitTests.html



Added: pkg/inst/doc/Makefile
===================================================================
--- pkg/inst/doc/Makefile	                        (rev 0)
+++ pkg/inst/doc/Makefile	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,5 @@
+all: Rcpp-unitTests.html
+
+Rcpp-unitTests.html: Rcpp-unitTests.R
+	Rscript --default-packages="Rcpp,RUnit,utils,tools" Rcpp-unitTests.R
+

Added: pkg/inst/doc/Rcpp-unitTests.R
===================================================================
--- pkg/inst/doc/Rcpp-unitTests.R	                        (rev 0)
+++ pkg/inst/doc/Rcpp-unitTests.R	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,26 @@
+#!/usr/bin/r -t
+#
+# Copyright (C) 2009 Dirk Eddelbuettel
+# Copyright (C) 2009 Romain Francois
+#
+# This file is part of Rcpp.
+#
+# Rcpp is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Rcpp is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+pkg <- "Rcpp"
+path <- system.file("unitTests", package = pkg)
+testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs = path)
+tests <- runTestSuite(testSuite)
+printHTMLProtocol(tests, fileName="Rcpp-unitTests.html" )
+

Added: pkg/inst/doc/Rcpp-unitTests.Rnw
===================================================================
--- pkg/inst/doc/Rcpp-unitTests.Rnw	                        (rev 0)
+++ pkg/inst/doc/Rcpp-unitTests.Rnw	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1 @@
+

Added: pkg/inst/doc/index.html
===================================================================
--- pkg/inst/doc/index.html	                        (rev 0)
+++ pkg/inst/doc/index.html	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>R: Rcpp vignettes</title>
+<link rel="stylesheet" type="text/css" href="../../R.css">
+</head><body>
+<h2>Vignettes of package Rcpp </h2>
+<dl>
+<dt><a href="Rcpp-unitTests.html">unit tests</a>: unit test report
+<dd> 
+</dl>
+</body></html>

Added: pkg/inst/unitTests/runTests.R
===================================================================
--- pkg/inst/unitTests/runTests.R	                        (rev 0)
+++ pkg/inst/unitTests/runTests.R	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,57 @@
+pkg <- "Rcpp"
+
+if(require("RUnit", quietly = TRUE)) {
+
+    library(package=pkg, character.only = TRUE)
+    if(!(exists("path") && file.exists(path)))
+        path <- system.file("unitTests", package = pkg)
+
+    ## --- Testing ---
+
+    ## Define tests
+    testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs = path)
+
+    if(interactive()) {
+        cat("Now have RUnit Test Suite 'testSuite' for package '", pkg,
+            "' :\n", sep='')
+        str(testSuite)
+        cat('', "Consider doing",
+            "\t  tests <- runTestSuite(testSuite)", "\nand later",
+            "\t  printTextProtocol(tests)", '', sep="\n")
+    } else { ## run from shell / Rscript / R CMD Batch / ...
+        ## Run
+        tests <- runTestSuite(testSuite)
+
+        if(file.access(path, 02) != 0) {
+            ## cannot write to path -> use writable one
+            tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
+            dir.create(tdir)
+            pathReport <- file.path(tdir, "report")
+            cat("RUnit reports are written into ", tdir, "/report.(txt|html)",
+                sep = "")
+        } else {
+            pathReport <- file.path(path, "report")
+        }
+
+        ## Print results
+        # printTextProtocol(tests)
+        printTextProtocol(tests, fileName=paste(pathReport, ".txt", sep=""))
+        ## Print HTML version to a file
+        ## printHTMLProtocol has problems on Mac OS X
+        if (Sys.info()["sysname"] != "Darwin")
+        printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep=""))
+
+        ##  stop() if there are any failures i.e. FALSE to unit test.
+        ## This will cause R CMD check to return error and stop
+        if(getErrors(tests)$nFail > 0) {
+            stop("one of the unit tests failed")
+        }
+    }
+} else {
+    cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
+    "for package", pkg,"\n")
+}
+
+
+################################################################################
+

Added: pkg/inst/unitTests/runit.runit.R
===================================================================
--- pkg/inst/unitTests/runit.runit.R	                        (rev 0)
+++ pkg/inst/unitTests/runit.runit.R	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,7 @@
+
+test.runit <- function(){
+	checkTrue( TRUE, msg = "checking checkTrue" )
+	checkEquals( 1, 1, msg = "checking checkEquals" )
+	checkException( stop("boom"), msg = "checking checkException" )
+}
+

Added: pkg/tests/doRUnit.R
===================================================================
--- pkg/tests/doRUnit.R	                        (rev 0)
+++ pkg/tests/doRUnit.R	2009-12-29 17:50:40 UTC (rev 226)
@@ -0,0 +1,30 @@
+#### doRUnit.R --- Run RUnit tests
+####------------------------------------------------------------------------
+
+### borrowed from package fUtilities in RMetrics
+### http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/fUtilities/tests/doRUnit.R?rev=1958&root=rmetrics&view=markup
+
+### Originally follows Gregor Gojanc's example in CRAN package  'gdata'
+### and the corresponding section in the R Wiki:
+###  http://wiki.r-project.org/rwiki/doku.php?id=developers:runit
+
+### MM: Vastly changed:  This should also be "runnable" for *installed*
+##              package which has no ./tests/
+## ----> put the bulk of the code e.g. in  ../inst/unitTests/runTests.R :
+
+if(require("RUnit", quietly = TRUE)) {
+
+  ## --- Setup ---
+  pkg <- "Rcpp"
+  wd <- getwd()
+  
+  require( pkg, character.only=TRUE)
+
+  path <- system.file("unitTests", package = pkg)
+
+  stopifnot(file.exists(path), file.info(path.expand(path))$isdir)
+
+  source(file.path(path, "runTests.R"), echo = TRUE)
+} else {
+	print( "package RUnit not available, cannot run unit tests" )
+}



More information about the Rcpp-commits mailing list