#!/bin/bash

BWW2MXML=../bww2mxml

echo "------------------------------"
echo "Regression Tests for bww2mxml"
echo "------------------------------"
echo

testcount=0
failures=0

rwtest() {
      echo -n "testing load/save $1"
      REF=`basename $1 .bww`.xml
      $BWW2MXML $1 mops.xml &> /dev/null
      if diff -q $REF mops.xml &> /dev/null; then
            echo -e "\r\t\t\t\t\t\t...OK";
      else
            echo -e "\r\t\t\t\t\t\t...FAILED";
            failures=$(($failures+1));
            echo "+++++++++DIFF++++++++++++++"
            diff $REF mops.xml
            echo "+++++++++++++++++++++++++++"
      fi
      rm mops.xml
      testcount=$(($testcount+1))
      }

rwtestAll() {
      rwtest testBeams.bww
      rwtest testDuration.bww
      rwtest testGraces.bww
      rwtest testHello.bww
      rwtest testMidMeasureRepeat.bww
      rwtest testNotes.bww
      rwtest testNoTimeSig1.bww
      rwtest testNoTimeSig2.bww
      rwtest testRepeats.bww
      rwtest testTempo120.bww
      rwtest testTempo60.bww
      rwtest testTieTriplet.bww
      rwtest testTriplets.bww
      }

usage() {
      echo "usage: $0"
      echo "or: $0 <file>"
      echo
      exit 1
      }

if [ $# -eq 0 ]; then
      rwtestAll
elif [ $# -eq 1 ]; then
      rwtest $1
elif [ $# -ge 2 ]; then
      usage
fi

echo
echo "$testcount test(s), $failures failure(s)"
