#!/usr/bin/env bash

if [ -z "$SAGE_LOCAL" ]; then
    echo "SAGE_LOCAL undefined ... exiting"
    exit 1
fi

# Only test iconv on Solaris, HP-UX and Cygwin, as those are the only
# platforms on which the iconv shipped with Sage will be installed. On
# other platforms Sage uses the system's iconv.

case "$UNAME" in
SunOS)
    # We must test iconv, but on Solaris some tests will always fail.
    echo "If you see 3 core dumps, don't be too alarmed."
    echo "This is a known Solaris bug and can safely be ignored. See"
    echo "    http://trac.sagemath.org/sage_trac/ticket/8270"
    echo "It will probably be fixed in later releases of Solaris 10,"
    echo "and was fixed in build 66 of OpenSolaris:"
    echo "    http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6550204"
esac
case "$UNAME" in
CYGWIN|HP-UX|SunOS)

    cd src

    $MAKE check

    if [ $? -ne 0 ]; then
        echo "Error encountered while running the iconv test suite ... exiting"
        exit 1
    fi
    echo "All the tests for iconv passed."
    exit 0
    ;;
*) # Not CYGWIN, HP-UX or SunOS (Solaris)
    echo "iconv was not to be tested, since Sage will use the system's iconv"
    echo "and not the one shipped with Sage."
    echo "The iconv supplied by Sage is only used on Cygwin, HP-UX and Solaris."
    exit 0
esac

# NOT REACHED

