Chris@118: Chris@182: set -e Chris@119: Chris@182: mypath=$(dirname $0) Chris@182: Chris@182: case "$(pwd)/$mypath" in Chris@182: *" "*) Chris@182: echo 1>&2 Chris@182: echo "ERROR: Test scripts do not handle paths containing spaces (yes, I know)" 1>&2 Chris@182: echo "(Path is: \"$(pwd)/$mypath\")" 1>&2 Chris@182: exit 1;; Chris@182: *) Chris@182: ;; Chris@182: esac Chris@182: Chris@204: version=1.3 Chris@204: nextversion=1.4 Chris@138: Chris@119: testdir=$mypath/.. Chris@119: r=$testdir/../sonic-annotator Chris@119: Chris@119: audiopath=$testdir/audio Chris@118: Chris@118: percplug=vamp:vamp-example-plugins:percussiononsets Chris@126: amplplug=vamp:vamp-example-plugins:amplitudefollower Chris@118: testplug=vamp:vamp-test-plugin:vamp-test-plugin Chris@30: Chris@30: fail() { Chris@30: echo "Test failed: $1" Chris@30: exit 1 Chris@30: } Chris@30: Chris@30: csvcompare() { Chris@30: # permit some fuzz in final few digits Chris@30: a="$1" Chris@30: b="$2" Chris@30: perl -p -e 's/(\d+\.\d{6})\d+/$1/' "$a" > "${a}__" Chris@30: perl -p -e 's/(\d+\.\d{6})\d+/$1/' "$b" > "${b}__" Chris@30: cmp -s "${a}__" "${b}__" Chris@30: rv=$? Chris@30: rm "${a}__" "${b}__" Chris@30: return $rv Chris@30: } Chris@30: Chris@75: csvcompare_ignorefirst() { Chris@75: # a bit like the above, but ignoring first column (and without temp files) Chris@75: out=`cat "$1" "$2" | cut -d, -f2- | perl -p -e 's/(\d+\.\d{6})\d+/$1/' | sort | uniq -c | grep -v ' 2 '` Chris@75: return `[ -z "$out" ]` Chris@75: } Chris@75: Chris@196: midicompare() { Chris@196: a="$1" Chris@196: b="$2" Chris@196: od -c "$a" > "${a}__" Chris@196: od -c "$b" > "${b}__" Chris@196: cmp -s "${a}__" "${b}__" Chris@196: rv=$? Chris@196: rm "${a}__" "${b}__" Chris@196: return $rv Chris@196: } Chris@196: Chris@204: jsoncompare() { Chris@204: a="$1" Chris@204: b="$2" Chris@204: cmp -s "$a" "$b" Chris@204: } Chris@204: Chris@108: faildiff() { Chris@108: echo "Test failed: $1" Chris@108: if [ -n "$2" -a -n "$3" ]; then Chris@108: echo "Output follows:" Chris@108: echo "--" Chris@196: cat "$2" Chris@108: echo "--" Chris@108: echo "Expected output follows:" Chris@108: echo "--" Chris@196: cat "$3" Chris@108: echo "--" Chris@108: echo "Diff:" Chris@108: echo "--" Chris@196: sdiff -w78 "$2" "$3" Chris@196: echo "--" Chris@196: fi Chris@196: exit 1 Chris@196: } Chris@196: Chris@196: faildiff_od() { Chris@196: echo "Test failed: $1" Chris@196: if [ -n "$2" -a -n "$3" ]; then Chris@196: echo "Output follows:" Chris@196: echo "--" Chris@196: od -c "$2" Chris@196: echo "--" Chris@196: echo "Expected output follows:" Chris@196: echo "--" Chris@196: od -c "$3" Chris@196: echo "--" Chris@196: echo "Diff:" Chris@196: echo "--" Chris@196: od -w8 -c "$3" > "${3}__" Chris@196: od -w8 -c "$2" | sdiff -w78 - "${3}__" Chris@196: rm "${3}__" Chris@108: echo "--" Chris@108: fi Chris@108: exit 1 Chris@108: } Chris@75: Chris@191: failshow() { Chris@191: echo "Test failed: $1" Chris@191: if [ -n "$2" ]; then Chris@191: echo "Output follows:" Chris@191: echo "--" Chris@191: cat $2 Chris@191: echo "--" Chris@191: fi Chris@191: exit 1 Chris@191: } Chris@108: Chris@191: check_json() { Chris@191: test -f $1 || \ Chris@191: fail "Fails to write output to expected location $1 for $2" Chris@191: cat $1 | json_verify -q || \ Chris@191: failshow "Writes invalid JSON to location $1 for $2" $1 Chris@191: rm -f $1 Chris@191: } Chris@191: Chris@191: