Chris@118
|
1
|
Chris@182
|
2 set -e
|
Chris@119
|
3
|
Chris@182
|
4 mypath=$(dirname $0)
|
Chris@182
|
5
|
Chris@182
|
6 case "$(pwd)/$mypath" in
|
Chris@182
|
7 *" "*)
|
Chris@182
|
8 echo 1>&2
|
Chris@182
|
9 echo "ERROR: Test scripts do not handle paths containing spaces (yes, I know)" 1>&2
|
Chris@182
|
10 echo "(Path is: \"$(pwd)/$mypath\")" 1>&2
|
Chris@182
|
11 exit 1;;
|
Chris@182
|
12 *)
|
Chris@182
|
13 ;;
|
Chris@182
|
14 esac
|
Chris@182
|
15
|
Chris@287
|
16 version=1.5pre
|
Chris@257
|
17 nextversion=1.6
|
Chris@138
|
18
|
Chris@119
|
19 testdir=$mypath/..
|
Chris@119
|
20 r=$testdir/../sonic-annotator
|
Chris@119
|
21
|
Chris@119
|
22 audiopath=$testdir/audio
|
Chris@118
|
23
|
Chris@118
|
24 percplug=vamp:vamp-example-plugins:percussiononsets
|
Chris@126
|
25 amplplug=vamp:vamp-example-plugins:amplitudefollower
|
Chris@118
|
26 testplug=vamp:vamp-test-plugin:vamp-test-plugin
|
Chris@30
|
27
|
Chris@30
|
28 fail() {
|
Chris@30
|
29 echo "Test failed: $1"
|
Chris@30
|
30 exit 1
|
Chris@30
|
31 }
|
Chris@30
|
32
|
Chris@30
|
33 csvcompare() {
|
Chris@30
|
34 # permit some fuzz in final few digits
|
Chris@30
|
35 a="$1"
|
Chris@30
|
36 b="$2"
|
Chris@30
|
37 perl -p -e 's/(\d+\.\d{6})\d+/$1/' "$a" > "${a}__"
|
Chris@30
|
38 perl -p -e 's/(\d+\.\d{6})\d+/$1/' "$b" > "${b}__"
|
Chris@30
|
39 cmp -s "${a}__" "${b}__"
|
Chris@30
|
40 rv=$?
|
Chris@30
|
41 rm "${a}__" "${b}__"
|
Chris@30
|
42 return $rv
|
Chris@30
|
43 }
|
Chris@30
|
44
|
Chris@75
|
45 csvcompare_ignorefirst() {
|
Chris@75
|
46 # a bit like the above, but ignoring first column (and without temp files)
|
Chris@75
|
47 out=`cat "$1" "$2" | cut -d, -f2- | perl -p -e 's/(\d+\.\d{6})\d+/$1/' | sort | uniq -c | grep -v ' 2 '`
|
Chris@75
|
48 return `[ -z "$out" ]`
|
Chris@75
|
49 }
|
Chris@75
|
50
|
Chris@196
|
51 midicompare() {
|
Chris@196
|
52 a="$1"
|
Chris@196
|
53 b="$2"
|
Chris@196
|
54 od -c "$a" > "${a}__"
|
Chris@196
|
55 od -c "$b" > "${b}__"
|
Chris@196
|
56 cmp -s "${a}__" "${b}__"
|
Chris@196
|
57 rv=$?
|
Chris@196
|
58 rm "${a}__" "${b}__"
|
Chris@196
|
59 return $rv
|
Chris@196
|
60 }
|
Chris@196
|
61
|
Chris@204
|
62 jsoncompare() {
|
Chris@221
|
63 # The Sonic Annotator version number appears in the JAMS output --
|
Chris@221
|
64 # filter that out, and also reformat to ignore whitespace differences
|
Chris@204
|
65 a="$1"
|
Chris@204
|
66 b="$2"
|
Chris@287
|
67 cat "$a" | sed 's/Sonic Annotator v[0-9a-z.]*/Sonic Annotator vXXX/' | json_reformat > "${a}__"
|
Chris@287
|
68 cat "$b" | sed 's/Sonic Annotator v[0-9a-z.]*/Sonic Annotator vXXX/' | json_reformat > "${b}__"
|
Chris@221
|
69 cmp -s "${a}__" "${b}__"
|
Chris@208
|
70 rv=$?
|
Chris@208
|
71 rm "${a}__" "${b}__"
|
Chris@208
|
72 return $rv
|
Chris@204
|
73 }
|
Chris@204
|
74
|
Chris@261
|
75 SDIFF_WIDTH=140
|
Chris@261
|
76
|
Chris@108
|
77 faildiff() {
|
Chris@108
|
78 echo "Test failed: $1"
|
Chris@108
|
79 if [ -n "$2" -a -n "$3" ]; then
|
Chris@108
|
80 echo "Output follows:"
|
Chris@108
|
81 echo "--"
|
Chris@196
|
82 cat "$2"
|
Chris@108
|
83 echo "--"
|
Chris@261
|
84 echo "Expected output follows ($3):"
|
Chris@108
|
85 echo "--"
|
Chris@196
|
86 cat "$3"
|
Chris@108
|
87 echo "--"
|
Chris@226
|
88 echo "Diff (output on left, expected on right):"
|
Chris@108
|
89 echo "--"
|
Chris@261
|
90 sdiff -w${SDIFF_WIDTH} "$2" "$3"
|
Chris@196
|
91 echo "--"
|
Chris@196
|
92 fi
|
Chris@196
|
93 exit 1
|
Chris@196
|
94 }
|
Chris@196
|
95
|
Chris@196
|
96 faildiff_od() {
|
Chris@196
|
97 echo "Test failed: $1"
|
Chris@196
|
98 if [ -n "$2" -a -n "$3" ]; then
|
Chris@196
|
99 echo "Output follows:"
|
Chris@196
|
100 echo "--"
|
Chris@196
|
101 od -c "$2"
|
Chris@196
|
102 echo "--"
|
Chris@261
|
103 echo "Expected output follows ($3):"
|
Chris@196
|
104 echo "--"
|
Chris@196
|
105 od -c "$3"
|
Chris@196
|
106 echo "--"
|
Chris@196
|
107 echo "Diff:"
|
Chris@196
|
108 echo "--"
|
Chris@196
|
109 od -w8 -c "$3" > "${3}__"
|
Chris@261
|
110 od -w8 -c "$2" | sdiff -w${SDIFF_WIDTH} - "${3}__"
|
Chris@196
|
111 rm "${3}__"
|
Chris@108
|
112 echo "--"
|
Chris@108
|
113 fi
|
Chris@108
|
114 exit 1
|
Chris@108
|
115 }
|
Chris@75
|
116
|
Chris@191
|
117 failshow() {
|
Chris@191
|
118 echo "Test failed: $1"
|
Chris@191
|
119 if [ -n "$2" ]; then
|
Chris@191
|
120 echo "Output follows:"
|
Chris@191
|
121 echo "--"
|
Chris@191
|
122 cat $2
|
Chris@191
|
123 echo "--"
|
Chris@191
|
124 fi
|
Chris@191
|
125 exit 1
|
Chris@191
|
126 }
|
Chris@108
|
127
|
Chris@191
|
128 check_json() {
|
Chris@191
|
129 test -f $1 || \
|
Chris@191
|
130 fail "Fails to write output to expected location $1 for $2"
|
Chris@191
|
131 cat $1 | json_verify -q || \
|
Chris@191
|
132 failshow "Writes invalid JSON to location $1 for $2" $1
|
Chris@191
|
133 rm -f $1
|
Chris@191
|
134 }
|
Chris@191
|
135
|
Chris@191
|
136
|