#!/bin/sh

scriptdir="$(dirname "$0")"

killall snmpd snmptrapd >/dev/null 2>&1

export SNMP_VERBOSE=1 &&
export NOAUTODEPS=1 &&
export SNMP_SAVE_TMPDIR=1 &&
make -s &&
(
      cd testing &&
      if [ -e RUNFULLTESTS ] &&
	     perl -e 'require TAP::Harness;' >/dev/null 2>&1; then
          case "$(uname)" in
	      Darwin)
		  for g in default snmpv3 unit-tests; do
                      echo "==== Test group $g ===="
	              ./RUNFULLTESTS -g $g || exit $?
                      echo "==== End of test group $g ===="
		  done
		  ;;
	      FreeBSD)
		  for g in default snmpv3 transports unit-tests; do
                      echo "==== Test group $g ===="
	              ./RUNFULLTESTS -g $g || exit $?
                      echo "==== End of test group $g ===="
		  done
		  ;;
              *)
		  ./RUNFULLTESTS -g all -e dtls -e tls
		  ;;
          esac
      else
	  make -s test
      fi &&
      cd .. &&
      if grep -q "PERLTARGS='perlmodules'" config.log; then
          "$scriptdir/net-snmp-run-perl-tests"
      fi
) &&
# Disable the Python tests because these fail sporadically.
if false && grep -q with-python-modules config.log; then
    "$scriptdir/net-snmp-run-python-tests"
fi
