-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-yaml-testcases.sh.in
executable file
·215 lines (185 loc) · 7.16 KB
/
run-yaml-testcases.sh.in
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
# This is a shell script that will loop over the *.yaml files of the specified
# transducer type found in this dir
# and run them through the Apertium Quality morph-test.py tool.
#
# It takes one argument: the transducer type.
#
# The script is typically called by a simple shell script listed in the TESTS
# variable in the Makefile.am file, and will then be automatically called when
# issuing 'make check'
#
# This script only contains the loop, and will for each found yaml file call
# the actual test runner.
echo "DEPRECATED run-yaml-testcases.sh MAYBE CALLED FROM $0"
# Wrong usage - short instruction:
if ! test $# -ge 2 ; then
echo
echo "Usage: $0 TRANSDUCER YAMLSUBDIR [HALFTEST]"
echo
echo "were:"
echo " TRANSDUCER is the type of transducer targeted"
echo " for testing: gt-norm, gt-desc, etc. It will loop"
echo " over all yaml tests for the specified TRANSDUCER."
echo " YAMLSUBDIR specifies the subdir containing yaml"
echo " yaml test files - the default is ./ (ie the current"
echo " dir). This makes it possible to move all yaml files"
echo " out of the test dir, making for a much cleaner"
echo " directory."
echo " SCRIPTDIR directory of yaml runner stuff"
echo " [HALFTEST] (optional) is one of the strings 'ana' or 'gen',"
echo " indicating that the test runs should only run"
echo " the analyser or generator tests respectively."
echo
exit 77
fi
###### Variables: #######
transducer=$1
yaml_file_subdir=$2
testerpath=$3
halftest=$4
Fail=0
testtotalsfile=testtotals.tmp.txt
# Remove summary file before we start:
rm -f $testtotalsfile
if test "x$yaml_file_subdir" = "x" ; then
yaml_file_subdir=.
fi
# relpath=$(cd -P "$(dirname "$0")" && pwd)
testrunner=run-morph-tester.sh
relpath=.
while test ! -x $testerpath/$testrunner ; do
relpath="$relpath/.."
# echo relpath: $relpath # debug
if test "$(cd $relpath && pwd)" = "/" ; then
echo "$0: No test runner found!"
exit 77
fi
done
# Build filename suffix dependent on the content of $halftest
if test "$halftest" == "" \
-o "$halftest" == "full" \
-o "$halftest" == "both"; then
suffix="yaml"
halftest="full"
summaryhalftext=""
elif test "$halftest" == "speller" ; then
suffix="$halftest.yaml"
summaryhalftext=""
else
suffix="$halftest.yaml"
if test "$halftest" == "ana"; then
summaryhalftext="analysing "
elif test "$halftest" == "gen"; then
summaryhalftext="generating "
else
echo "No suitable tests found for $halftest tests."
exit 1;
fi
fi
# Check that there are test files fitting the required patterns, otherwise
# FAIL with 77.
# The "*_$transducer.[~]????.$suffix" pattern is for fst-specific yaml files:
testfiles=$(find $srcdir/$yaml_file_subdir -name "*_$transducer.$suffix" -or \
-name "*_$transducer.????.$suffix" -or \
-name "*_$transducer.~????.$suffix")
if test "x$testfiles" == "x"; then
echo
echo \
"** No YAML files matching: $srcdir/$yaml_file_subdir/*_$transducer.$suffix"
echo \
"** No YAML files matching: $srcdir/$yaml_file_subdir/*_$transducer.????.$suffix"
echo \
"** No YAML files matching: $srcdir/$yaml_file_subdir/*_$transducer.~????.$suffix"
exit 77
fi
# First collect and run the general (non-fst-specific) test files:
testfiles=$(find $srcdir/$yaml_file_subdir -name "*_$transducer.$suffix" )
# One empty line in the beginning:
echo ""
i=0
# Loop over the available yaml files (all fst types), and run the tests:
for file in $testfiles; do
(( i += 1 ))
leadtext=$(echo "YAML test $i: ")
source $testerpath/run-morph-tester.sh \
$transducer $file $testerpath $halftest all $leadtext
done
# Machinery to be able to handle yaml tests for specific fst technologies:
# Online documentation used for help:
# http://wiki.bash-hackers.org/syntax/pe
# https://coderwall.com/p/mlyhlg/prefix-all-elements-of-a-bash-variable-with-a-string
# http://stackoverflow.com/questions/9293887/in-bash-how-do-i-convert-a-space-delimited-string-into-an-array
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
# Define all possible fst types:
allfsttypes="hfst foma xfst"
# Define fst types currently being enabled, to be replaced with autoconf stuff:
current_fsttypes=
@CAN_HFST_TRUE@current_fsttypes="$current_fsttypes hfst"
@CAN_XFST_TRUE@current_fsttypes="$current_fsttypes xfst"
@CAN_FOMA_TRUE@current_fsttypes="$current_fsttypes foma"
# Turn the list into an array, while also removing the current fst type:
neg_arr=( $(echo ${allfsttypes} \
| tr ' ' '\n' \
| grep -v "$current_fsttypes" \
| tr '\n' ' ' ) )
# Create an array of negated types, ie types prepended with ~ as in '~xfst':
nontypes=${neg_arr[@]/#/\~}
# Make a list of both the current and negative fst types:
posneg_fsttypes=$(echo $current_fsttypes $nontypes)
# Turn the list into an array:
posneg_fst_arr=( $(echo $posneg_fsttypes ) )
# Prepend each element in the array with the transducer name:
filepart1=(${posneg_fst_arr[@]/#/${transducer}\.})
# Then add the suffix from the earlier processing:
filepart2=(${filepart1[@]/%/\.${suffix}})
# Finally prepend the fileglob including directories:
filepattern=(${filepart2[@]/#/${srcdir}\/${yaml_file_subdir}\/*_})
### DEBUG PRINTS:
# echo "allfsttypes 143: $allfsttypes"
# echo "current_fsttypes: $current_fsttypes"
# echo "negation fst type array content:"
# for ii in ${neg_arr[@]}; do echo $ii; done
# echo "nontypes: $nontypes"
# echo "posneg_fsttypes 155: $posneg_fsttypes"
# echo "filepart1:"
# for ii in ${filepart1[@]}; do echo $ii; done
# echo "filepart2:"
# for ii in ${filepart2[@]}; do echo $ii; done
# echo "filepattern:"
# for ii in ${filepattern[@]}; do echo $ii; done
# Loop over the available yaml files (specific fst types), and run the tests:
for file in ${filepattern[@]}; do
if ! test -f "$file" ; then
continue
fi
(( i += 1 ))
leadtext=$(echo "YAML test $i: ")
source $testerpath/run-morph-tester.sh \
$transducer $file $testerpath $halftest specified $leadtext
done
totalpasses=$( echo $( cat $testtotalsfile | tr ' ' '\n' | cut -d'/' -f1 \
| tr '\n' ' ' | sed 's/ / + /g' | sed 's/ + $//' ) | bc )
totalfails=$( echo $( cat $testtotalsfile | tr ' ' '\n' | cut -d'/' -f2 \
| tr '\n' ' ' | sed 's/ / + /g' | sed 's/ + $//' ) | bc )
totaltotals=$( echo $( cat $testtotalsfile | tr ' ' '\n' | cut -d'/' -f3 \
| tr '\n' ' ' | sed 's/ / + /g' | sed 's/ + $//' ) | bc )
rm -f $testtotalsfile
red="\033[1;31m"
green="\033[0;32m"
orange="\033[0;33m"
yellow="\033[1;33m"
blue="\033[0;34m"
light_blue="\033[0;36m"
reset="\033[m"
bold=$(tput smso)
offbold=$(tput sgr0)
#bold=$(tput bold)
#normal=$(tput sgr0)
printf "${bold}SUMMARY${offbold} for the "
printf "${orange}$summaryhalftext$transducer${reset} fst(s): "
printf "${green}PASSES: ${totalpasses}${reset} / "
printf "${red}FAILS: ${totalfails}${reset} / "
printf "${blue}TOTAL: ${totaltotals}${reset}\n"
source $testerpath/error-handling-stubs.sh
echo "DEPRECATED run-yaml-testcases.sh MAYBE CALLED FROM $0"