#!/bin/sh

# SPDX-FileCopyrightText: The authors of this work have dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

if command -v flake8 > /dev/null; then
  echo "flake8 --ignore=E501 src"
  flake8 --ignore=E501 src || exit 1
else
  echo "flake8 not found, skipping check"
fi

if command -v mypy > /dev/null; then
  echo "mypy --strict src"
  mypy --strict src || exit 1
else
  echo "mypy not found, skipping check"
fi

if command -v reuse > /dev/null; then
  echo "reuse lint --quiet"
  reuse lint --quiet || reuse lint || exit 1
else
  echo "reuse not found, skipping check"
fi

falderal doc/*.md || exit 1
for F in eg/*.eqthy.md; do
  case "$F" in
    *)
      echo "./bin/eqthy $F"
      ./bin/eqthy --traceback $F || exit 1
    ;;
    esac
done
for F in eg/incorrect/*.eqthy.md; do
  echo $F
  ./bin/eqthy $F 2>&1 >/tmp/eqthy.out
  R=$?
  [ $R -eq 0 ] && echo "fail" && cat /tmp/eqthy.out && exit 1
done
exit 0
