if [ -z "$SAGE_LOCAL" ] ; then
    echo >&2 "SAGE_LOCAL undefined ... exiting"
    echo >&2 "Maybe run 'sage -sh'?"
    exit 1
fi

CUR=`pwd`

if [ "x$SAGE_DEBUG" = xyes ] ; then
    CFLAGS="$CFLAGS -g -O0" # No optimisation, aids debugging.
else
    CFLAGS="$CFLAGS -g -O2" # Normal optimisation.
fi

export CFLAGS

for di in "$CUR"/src/examples/doc/chap* ; do
    echo "Testing in $di"
    cd "$di"
    for i in `ls | grep -v bin` ; do
        echo "Testing $i ..."
        sage-python23 $i
        if [ $? -ne 0 ]; then
            echo >&2 "Error: test $di/$i failed"
            exit 1
        fi
    done
done
