Commit d04d92d1 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

updated Test tutorial/guidelines

parent 9b387872
......@@ -2,12 +2,18 @@
# TUTORIAL AND GUIDE FOR WRITING CDO TESTS! #
#=======================================================#
How to write Tests for CDO:
Important variables needed for test coverage checks:
Important variables needed for test coverage checks:
- STATS: contains simple operators. Needs to be inside a test. Otherwise the test is not recognized
- OPERTYPES: contains a prefix for operators e.g: monmean -> mon is in OPERTYPES and mean is in STATS, muss eine string variable sein
- FORMATS: cdo format string which we can use to know what module is tested for which formats
General Variables:
- RSTAT: used to hold the the test status
- RSTAT: is used to hold the the test status
General:
Please use tabwidth of 4
Empty lines can be marked with a '#'
One operator test execution should be a single line in the test results
so that NTEST is increased for each distinct operator call.
General Structure/Example:
#autoconf will replace this with a fitting bash premable
......@@ -40,10 +46,27 @@ How to write Tests for CDO:
done
done
done
ALTERNATIVE:
in the file cdoTestFunctions we defined the function runTest which takes the following parameters:
- NTEST: which number within this test of the operator
- CDOTEST: a short description
- CDOCOMMAND eg. "CDO $STAT $IFILE $OUTFILE"
- TESTCOMMAND: e.g diff command like "$CDO $FORMAT diff FILE1 FILE2"
this function handles the ok/not ok printing for given for CDOCOMMAND and TESTCOMMAND
HINTS:
let NTEST += 1 #Needs to be outside the if statement that enables single test execution
#=======================================================#
# Complete example for operator monstat #
#=======================================================#
# contains: naming conventions
# naming conventions
# looping oder opers
# single test execution if statement
# setting paths
#-------------------------------------------------------#
#! @BASH@
echo 1..4 # Number of tests to be executed.
#
......@@ -81,8 +104,49 @@ for STAT in $STATS; do
test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
fi
let NTEST+=1
done
#
exit 0
#=======================================================#
# ALTERNATIVE: Complete example for operator monstat #
#=======================================================#
# contains: usage of OPERTYPES
# usage of runTest()
#-------------------------------------------------------#
#! @BASH@
echo 1..4 # Number of tests to be executed.
#
test -n "$CDO" || CDO="@abs_top_builddir@/src/cdo $CDO_DEBUG"
test -n "$DATAPATH" || DATAPATH="@abs_top_srcdir@/test/data/"
#
IFILE1=$DATAPATH/ts_1d_1year
IFILE2=$DATAPATH/ts_mm_1991
#
FORMAT="-f srv -b 32"
OPERTYPES="mon"
STATS="add sub mul div"
#
NTEST=1
#
for OPERTYPE in $OPERTYPES; do
for STAT in $STATS; do
if [ -z "$1" ] || [ $NTEST == $1 ]; then
RSTAT=0
RFILE=$DATAPATH/${STAT}_ref
CDOTEST="$STAT"
OFILE=${STAT}_res
CDOCOMMAND="$CDO $FORMAT ${OPERTYPE}${STAT} $IFILE1 $IFILE2 $OFILE"
TESTCOMMAND="$CDO diff $OFILE $RFILE"
runTest "$NTEST" "$CDOTEST" "$CDOCOMMAND" "$TESTCOMMAND"
fi
let NTEST+=1
done
done
#
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment