[c237fe]: pyke / testpyke Maximize Restore History

Download this file

testpyke    120 lines (107 with data), 2.9 kB

#!/bin/bash

# testpyke [-p python_command] [ errorfiles_file ]
#
# no arguments.
#
# run in pyke source directory to test all doctests.
# 
# exit status > 0 if errors found.

ERRORFILES="/tmp/testpyke.$$"
TMPFILE="/tmp/testpyke2.$$"

PYTHON="python3.0 -Wd"

# Go to pyke directory:
cd `dirname "$0"`

# Add parent directory to PYTHONPATH:
parent_dir=$(dirname $(pwd))
if [ "$PYTHONPATH" ]
then
    export PYTHONPATH="$parent_dir:$PYTHONPATH"
else
    export PYTHONPATH="$parent_dir"
fi

if [ $# -ge 2 -a "x$1" = x-p ]
then
    PYTHON="$2"
    shift 2
fi

> $ERRORFILES
NUM_ERRORS=0

# Do doctests for all .py files (except those generated by pyke):
for f in `find . -name '*.py' ! -name '*_[bf]c.py'`
do
    echo Testing "$f"
    if ! $PYTHON "$f"
    then
        echo "$f" >> $ERRORFILES
        NUM_ERRORS=$(($NUM_ERRORS + 1))
    fi
done

# Check that all of the PLY tables files are up to date:
cd krb_compiler
echo Testing scanner_tables.py
if [ scanner.py -nt scanner_tables.py ]
then
    echo "krb_compiler/scanner_tables.py" >> $ERRORFILES
    NUM_ERRORS=$(($NUM_ERRORS + 1))
fi
echo Testing krbparser_tables.py
if [ scanner.py -nt krbparser_tables.py -o \
     krbparser.py -nt krbparser_tables.py ]
then
    echo "krb_compiler/krbparser_tables.py" >> $ERRORFILES
    NUM_ERRORS=$(($NUM_ERRORS + 1))
fi
echo Testing kfbparser_tables.py
if [ scanner.py -nt kfbparser_tables.py -o \
     kfbparser.py -nt kfbparser_tables.py ]
then
    echo "krb_compiler/kfbparser_tables.py" >> $ERRORFILES
    NUM_ERRORS=$(($NUM_ERRORS + 1))
fi

# Check that the generated krb_compiler/compiler_bc.py file is up to date:
if [ $NUM_ERRORS -eq 0 ]
then
    echo Testing compiler.krb
    if [ ! -d compiled_krb ]
    then
        mkdir compiled_krb
    fi
    rm -f compiled_krb/compiler_bc.py*
    if $PYTHON -c "from pyke import krb_compiler; krb_compiler.compile_krb('compiler', 'compiled_krb', 'compiled_krb', 'compiler.krb')"
    then
        # Ignore differences in Krb_filename from being compiled on different
        # boxes...
        diff compiler_bc.py compiled_krb/compiler_bc.py |
            sed '
                /^[0-9]*c[0-9]*$/d
                /^---$/d
                /^[<>] Krb_filename = /d
            ' > $TMPFILE
        if [ -s $TMPFILE ]
        then
            echo "krb_compiler/compiler.krb not compiled!" >> $ERRORFILES
            NUM_ERRORS=$(($NUM_ERRORS + 1))
        else
            rm -f compiled_krb/compiler_bc.py*
        fi
    else
        echo "krb_compiler/compiler.krb" >> $ERRORFILES
        NUM_ERRORS=$(($NUM_ERRORS + 1))
    fi
fi

cd ..

# Final error summary:
if [ $NUM_ERRORS -eq 0 ]
then
    echo "No Errors!"
    rm -f $ERRORFILES $TMPFILE
else
    echo "********** ERRORS ************* $NUM_ERRORS files had errors:"
    cat $ERRORFILES
    if [ $# -gt 0 ]
    then
        sed 's,^\.,pyke,' $ERRORFILES >> "$1"
    fi
    rm -f $ERRORFILES $TMPFILE
    exit $NUM_ERRORS
fi