PLearn test-suite is still in development by its author Christian Dorion, but it is already usable and should probably be used by anyone who wants to ensure his code does not get broken accidentally.
Each test is a program or a PLearn script, which process some files (such as datasets), and outputs something to the standard output and error, and possibly to other files. The goal of the test-suite is to compare these results, run with a recently-compiled copy of PLearn, to the reference results created by the first run of the test.
The following instructions are a step-by-step example, for a test named PL_Var_utils, testing the Var class. It is not officially supported by Christian, and may not work anymore on a later version of the test-suite.
In addition, those who already know of the test-suite may find the PLearn object class PTest useful to write C++ tests that do not make the test-suite explode both in size and execution time (in addition to provide understandable floating numbers diff through the PLearn diff command applied on objects).
$ mkdir ${PLEARNDIR}/plearn/var/test $ svn add ${PLEARNDIR}/plearn/var/test $ cd ${PLEARNDIR}/plearn/var/test
$ mkdir Var_utils $ svn add Var_utils $ cd Var_utils
$ pytest add
$ pyskeleton PTest VarUtilsTest
PLEARN_IMPLEMENT_OBJECT( arUtilsTest, "Test various functions in Var_utils", "" );
// In VarUtilsTest::perform pout << my_function(x) << endl; MAND_LOG << my_function(x) << endl;
// In VarUtilsTest.h map<string, Vec> vec_results; // In VarUtilsTest::declareOptions declareOption(ol, "vec_results", &VarUtilsTest::vec_results, OptionBase::learntoption, "Test Vec results."); // In VarUtilsTest::perform vec_results["my_function"] = my_function(x);
#include <plearn/var/test/VarUtilsTest.h>
Typically you will run plearn_tests, on a .plearn or .pyplearn script (this script will describe one or more objects of your PTest subclass, with its specific options):
Test( name = "PL_Var_util", description = "Test various functions in Var_utils", program = GlobalCompilableProgram( name = "plearn_tests", compiler = "pymake", compile_options = "" ), arguments = "varutils_test.plearn", resources = [ "varutils_test.plearn" ], precision = 1e-06, disabled = False )
But if your PTest object does not need extra options, you can save the use of a script:
Test( name = "PL_Var_util", description = "Test various functions in Var_utils", program = GlobalCompilableProgram( name = "plearn", compiler = "pymake", compile_options = "" ), arguments = "PLEARNDIR:scripts/command_line_object.plearn " \ "'object=VarUtilsTest()'", resources = [ ], precision = 1e-06, disabled = False )
$ pytest results -n PL_Var_util
$ svn add VarUtilsTest.h VarUtilsTest.cc
Test( name = "PL_Var_util", description = "Test various functions in Var_utils", program = GlobalCompilableProgram( name = "plearn", compiler = "pymake", compile_options = "" ), arguments = "varutils_test.plearn", resources = [ "varutils_test.plearn" ], precision = 1e-06, disabled = False )
$ pytest results -n PL_Var_util
$ svn add varutils_test.plearn
$ pytest run
$ pytest confirm
$ svn propedit svn:ignore .pytestAnd in the editor it opens, type:
*.compilation_log run_results
$ cd ${PLEARNDIR} $ svn status <-- to check which files you need to commit $ svn commit commands/plearn_tests_inc.h plearn/var/test \ -m "New test: VarUtilsTest"