forked from rhdunn/cmudict-tools
-
Notifications
You must be signed in to change notification settings - Fork 30
/
run_tests.sh
executable file
·188 lines (153 loc) · 8.83 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
#
# Copyright (C) 2015 Reece H. Dunn
#
# This file is part of cmudict-tools.
#
# cmudict-tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cmudict-tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cmudict-tools. If not, see <http://www.gnu.org/licenses/>.
PYTHON=${PYTHON:-python}
LOG_FILE=run_tests.log
rm -rf ${LOG_FILE}
check() {
MESSAGE=$1
OUT_FILE=$2
shift
shift
RES_FILE=/tmp/cmudict_tools_test.out
echo "-------------------------------------------------------------------------------" >> ${LOG_FILE}
echo "command : ./cmudict-tools $@" >> ${LOG_FILE}
echo "expected : ${OUT_FILE}" >> ${LOG_FILE}
echo >> ${LOG_FILE}
echo -n "testing ${MESSAGE} ... " | tee -a ${LOG_FILE}
${PYTHON} ./cmudict-tools $@ 2>&1 | tee > ${RES_FILE}
diff ${OUT_FILE} ${RES_FILE} > /dev/null
if [[ $? -eq 0 ]] ; then
echo "pass" | tee -a ${LOG_FILE}
else
echo "fail" | tee -a ${LOG_FILE}
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> ${LOG_FILE}
diff -U0 ${OUT_FILE} ${RES_FILE} >> ${LOG_FILE}
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> ${LOG_FILE}
fi
}
check_metadata() {
PROGRAM=$1
MESSAGE=$2
OUT_FILE=$3
SRC_FILE=$4
case "${PROGRAM}" in
-)
PRESENT=yes
;;
*)
if type ${PROGRAM} >/dev/null 2>&1 ; then
PRESENT=yes
else
PRESENT=no
fi
;;
esac
RES_FILE=/tmp/cmudict_tools_test.out
echo "-------------------------------------------------------------------------------" >> ${LOG_FILE}
echo "command : ./metadata.py ${SRC_FILE}" >> ${LOG_FILE}
echo "expected : ${OUT_FILE}" >> ${LOG_FILE}
echo >> ${LOG_FILE}
echo -n "testing ${MESSAGE} ... " | tee -a ${LOG_FILE}
if [[ x${PRESENT} == xyes ]] ; then
${PYTHON} ./metadata.py ${SRC_FILE} 2>&1 | tee > ${RES_FILE}
diff ${OUT_FILE} ${RES_FILE} > /dev/null
if [[ $? -eq 0 ]] ; then
echo "pass" | tee -a ${LOG_FILE}
else
echo "fail" | tee -a ${LOG_FILE}
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> ${LOG_FILE}
diff -U0 ${OUT_FILE} ${RES_FILE} >> ${LOG_FILE}
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> ${LOG_FILE}
fi
else
echo "skip" | tee -a ${LOG_FILE}
fi
}
# Metadata Description Parser Tests ###########################################
check_metadata - "csv metadata parsing" tests/metadata.json tests/metadata.csv
check_metadata rapper "rdf turtle metadata parsing using rapper" tests/metadata.json tests/metadata-turtle
check_metadata rapper "rdf/xml metadata parsing using rapper" tests/metadata.json tests/metadata-rdfxml
check_metadata - "n-triples metadata parsing using rapper" tests/metadata.json tests/metadata-ntriples
# Parser Tests ################################################################
#
# NOTE: These tests also include validation check errors relating to parsing
# the specific file formats (i.e. formatting errors). They do not test other
# validation checks.
ARGS="print -Wall -Wno-unsorted --format=json"
check "cmudict format parsing" tests/cmudict.json ${ARGS} tests/cmudict
check "cmudict-weide format parsing" tests/cmudict-weide.json ${ARGS} tests/cmudict-weide
check "cmudict-new format parsing" tests/cmudict-new.json ${ARGS} tests/cmudict-new
check "festlex format parsing" tests/festlex.json ${ARGS} tests/festlex.scm
# File-Based Metadata #########################################################
ARGS="print -Wall -Wno-unsorted --format=json"
check "file metadata format key" tests/filemeta-format.json ${ARGS} tests/filemeta-format
# Formatter Tests #############################################################
ARGS="print -Wall -Wno-unsorted"
check "cmudict formatting" tests/format-cmudict ${ARGS} --format=cmudict tests/format-cmudict
check "cmudict-weide formatting" tests/format-cmudict-weide ${ARGS} --format=cmudict-weide tests/format-cmudict
check "cmudict-new formatting" tests/format-cmudict-new ${ARGS} --format=cmudict-new tests/format-cmudict
check "festlex formatting" tests/format-festlex.scm ${ARGS} --format=festlex tests/format-cmudict
# Sorting Tests ###############################################################
ARGS="print -Wnone"
check "sorting: default" tests/sorting-none ${ARGS} tests/sorting-none
check "sorting: air" tests/sorting-air ${ARGS} --sort=air tests/sorting-none
check "sorting: none" tests/sorting-none ${ARGS} --sort=none tests/sorting-none
check "sorting: weide" tests/sorting-weide ${ARGS} --sort=weide tests/sorting-none
# Phone Tests #################################################################
ARGS="print -Wnone -Winvalid-phonemes -Wmissing-stress --format=json"
check "default accent and phoneset" tests/phone_en-US-x-cmu.json ${ARGS} tests/phone_arpabet.upper
check "default accent, arpabet phones" tests/phone_en-US-x-arpabet.json ${ARGS} --source-phoneset=arpabet tests/phone_arpabet.upper
ARGS="print -Wnone -Winvalid-phonemes -Wmissing-stress --format=json --source-accent=en-US"
check "en-US accent, arpabet phones" tests/phone_en-US-x-arpabet.json ${ARGS} --source-phoneset=arpabet tests/phone_arpabet.upper
check "en-US accent, cmu phones" tests/phone_en-US-x-cmu.json ${ARGS} --source-phoneset=cmu tests/phone_arpabet.upper
check "en-US accent, cepstral phones" tests/phone_en-US-x-cepstral.json ${ARGS} --source-phoneset=cepstral tests/phone_arpabet.lower
check "en-US accent, festvox phones" tests/phone_en-US-x-festvox.json ${ARGS} --source-phoneset=festvox tests/phone_arpabet.lower
check "en-US accent, timit phones" tests/phone_en-US-x-timit.json ${ARGS} --source-phoneset=timit tests/phone_arpabet.lower
ARGS="print -Wnone -Winvalid-phonemes -Wmissing-stress --format=json --source-accent=en-GB-x-rp"
check "en-GB-x-rp accent, arpabet phones" tests/phone_en-GB-x-rp-arpabet.json ${ARGS} --source-phoneset=arpabet tests/phone_arpabet.upper
check "en-GB-x-rp accent, cepstral phones" tests/phone_en-GB-x-rp-cepstral.json ${ARGS} --source-phoneset=cepstral tests/phone_arpabet.lower
ARGS="print -Wnone -Winvalid-phonemes -Wmissing-stress --format=json --source-accent=en-US"
check "cmu phones in other case" tests/phone_en-US-x-cmu_othercase.json ${ARGS} --source-phoneset=cmu tests/phone_arpabet.lower
check "festvox phones in other case" tests/phone_en-US-x-festvox_othercase.json ${ARGS} --source-phoneset=festvox tests/phone_arpabet.upper
ARGS="print -Wnone -Winvalid-phonemes -Wmissing-stress --format=json --source-phoneset=arpabet"
check "accents/en-US.csv accent, arpabet phones" tests/phone_en-US-x-arpabet.json ${ARGS} --source-accent=accents/en-US.csv tests/phone_arpabet.upper
check "accents/en-GB-x-rp.csv accent, arpabet phones" tests/phone_en-GB-x-rp-arpabet.json ${ARGS} --source-accent=accents/en-GB-x-rp.csv tests/phone_arpabet.upper
# Validate Tests ##############################################################
ARGS="print -Wnone --format=json"
check "-Wnone" tests/phone_en-US-x-cmu_Wnone.json ${ARGS} tests/phone_arpabet.upper
# Print Tests #################################################################
ARGS="print -Wnone --source-phoneset=arpabet --accent=en-US"
check "printing en-US accent, arpabet phones" tests/phone_arpabet.upper ${ARGS} --phoneset=arpabet tests/phone_arpabet.upper
check "printing en-US accent, festvox phones" tests/phone_arpabet.lower ${ARGS} --phoneset=festvox tests/phone_arpabet.upper
ARGS="print -Wnone --source-phoneset=arpabet"
check "printing default accent, arpabet phones" tests/phone_arpabet.upper ${ARGS} --phoneset=arpabet tests/phone_arpabet.upper
check "printing default accent, festvox phones" tests/phone_arpabet.lower ${ARGS} --phoneset=festvox tests/phone_arpabet.upper
ARGS="print -Wnone --source-phoneset=arpabet --phoneset=ipa --output-encoding=utf-8"
check "printing ipa phones, utf-8 encoding, default accent" tests/phone_en-US.ipa ${ARGS} tests/phone_arpabet.upper
check "printing ipa phones, utf-8 encoding, en-US accent" tests/phone_en-US.ipa ${ARGS} --accent=en-US tests/phone_arpabet.upper
check "printing ipa phones, utf-8 encoding, en-GB-x-rp accent" tests/phone_en-GB-x-rp.ipa ${ARGS} --accent=en-GB-x-rp tests/phone_arpabet.upper
ARGS="print -Wnone --source-phoneset=arpabet --phoneset=ipa"
check "printing ipa phones, default encoding" tests/phone_en-US.ipa ${ARGS} tests/phone_arpabet.upper
check "printing ipa phones, ascii encoding" tests/phone_en-US.ipa ${ARGS} --output-encoding=ascii tests/phone_arpabet.upper
# Summary #####################################################################
if [[ `grep -P "^testing .* \\.\\.\\. fail$" ${LOG_FILE}` ]] ; then
exit 1
else
exit 0
fi