#!/bin/sh

# Simple test that we can call a simple validator

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat << EOF > testfe.py
import sys

from formencode.validators import Int
from formencode.api import Invalid

def run():
    check = Int(min=0, max=10)
    if check.to_python('5') != 5:
        return False
    # Check too large
    try:
        check.to_python('11')
        return False
    except Invalid:
        pass
    # Check too small
    try:
        check.to_python('-1')
        return False
    except Invalid:
        pass
    return True


if __name__ == "__main__":
   if not run():
       sys.exit(1)
EOF

for py in $(py3versions -s) python3; do
   $py testfe.py
done
