#!/bin/sh

patchdir="${0%/*}"

error() {
  echo "$*" 1>&2
}

debugrun() {
  echo "$*"
  "$@" 2>&1
}

failed=""
for pd in /usr/bin/pd /usr/bin/pd64; do
  test -x "${pd}" || continue
  for f in "${patchdir}"/*-test.pd; do
    debugrun "${pd}" -batch -open "${f}" -send "runtest bang"
    if [ "$?" = "1" ]; then
       failed="${failed} ${pd}:${f%.pd}"
    fi
  done
done

if [ -n "${failed}" ]; then
  error "failed tests:"
  for f in ${failed}; do
    error "   $f"
  done
  exit 1
fi

exit 0
  
