[Rcpp-devel] How to manage testing code for Rcpp based project?

Dirk Eddelbuettel edd at debian.org
Sat Aug 4 18:57:08 CEST 2012


On 4 August 2012 at 11:22, Peng Yu wrote:
| The example in RcppArmadillo_0.3.2.4/inst/unitTests has some problem
| in the sense that, each file is too large --- if there is a little
| change the whole test file should be run, which takes more time than

Before you look at RcppArmadillo, look at Rcpp itself:

   - 22 unit test files

   - 349 unit test functions

   - 770 unit tests

It is far from perfect. In fact, the CRAN gatekeepers now complain that
testing takes too long (!!) and have forced us to disable a number of these
tests so that the testing part takes no longer than about one minute.

R itself has three competing unit test frameworks. We went with RUnit as it
permits 

   - testing when developing (and I have a simple script below)

   - testing via R CMD check, and 

   - testing once installed.  

We added a solution to have a vignette summarize the tests.

RUnit works, but the setup is not the easiest. If someone has ideas for
better solutions, by all means implement those.  Unit testing has helped us
many times, and I consider it to be a very important part of package
development. 

But tools can always get better. So suggestions welcome, and in the meantime
RUnit continues to get the job done for me.

Dirk

PS Below is a simple helper script 'runit.sh' which I use to run just one
runit.*.R file. It is a little Rcpp-centric as it uses inline and Rcpp plus
whatever other package one may be testing.


#!/bin/sh

set -u 
set -e

progname=`basename $0`
options='p:h?'
 
usage_and_exit()
{
    echo ""
    echo "Usage: $progname [-p package[,package2,..]] [-?|-h]"
    echo "  Run unit test script for R package"
    echo ""
    echo "Options:"
    echo "  -p package[,package2,..]]  load additional package(s)"
    echo "  -h                         show this help"
    echo ""
    echo "The RUnit and inline packages are automatically loaded."
    echo ""
    exit 0
}

while getopts "$options" i 
do 
    case "$i" in
	p)
	    pkg=",$OPTARG"
	    shift 
	    shift
	    ;;
	h|?)
	    usage_and_exit
	    ;;
    esac
done

if [ ! -f $1 ]; then
    echo "Error: No file '$1' found"
    exit 1
fi

file=`pwd`/$1

r -i -t -linline,RUnit${pkg} -e"cppfunction <- function(...) cxxfunction(..., plugin=\"Rcpp\"); runTestFile(\"$file\")"


-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list