#!/bin/bash
Fail()
{
    echo "ERROR($0): $1"
    exit 1
}

[[ "$1" == "" || "$1" == "-v" ]] || Fail "Invalid command line options."

python --version || Fail "Cannot print python version"

echo "$0: running mypy"
cd ../source/python/astronomy || Fail "error changing to Python source directory"
mypy --strict --module astronomy || Fail "error checking types using mypy"
cd ../../../generate || Fail "error changing back to generate directory"
echo ""

echo "$0: running unit tests"
python test.py $1 all || Fail "Failed Python unit tests."
for file in temp/py_longitude_*.txt; do
    ./generate $1 check ${file} || Fail "Failed verification of file ${file}"
done

echo "$0: Generating Python test output."
time python test.py astro_check > temp/py_check.txt || Fail "Failure in Python astro_check"
./generate $1 check temp/py_check.txt || Fail "Verification failure for Python unit test output."

echo "$0: PASS"
exit 0
