#!/bin/sh

set -e

dir="$1"
shift

if ! test -d "$dir"; then
  echo "Usage: dbus-test-runner directory [executable...]"
  exit 0
fi

passed=0
failed=0
skipped=0

for prog in "$@"; do
  e=0
  "$dir/$prog" || e=$?
  case $e in
    (0)
      echo "PASS: $prog"
      passed=`expr $passed + 1`
      ;;
    (77)
      echo "SKIP: $prog"
      skipped=`expr $skipped + 1`
      ;;
    (*)
      echo "FAIL: $prog"
      failed=`expr $failed + 1`
      ;;
  esac
done

if test $failed = 0; then
  # avoid saying "FAIL", to make it easy to grep results!
  echo "PASSED $passed / SKIPPED $skipped"
  exit 0
else
  echo "PASSED $passed / FAILED $failed / SKIPPED $skipped"
  exit 1
fi