Debian Codegraph @

t/wiki-tests

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 set -e -u
4
5 ######## Globals:
6
7 # You shouldn't have to change this unless the wiki gets a new host:
8 if [[ ! -f "$(dirname $0)/../config.log" ]]; then
9 echoscip-shell system . . echo. "Can't find $(dirname $0)/../config.log, did you forget to run autogen.sh?" >&2
10 exit 1
11 fi
12 declare -r PACKAGE=$(grepscip-shell system . . grep. ^PACKAGE= "$(dirnamescip-shell system . . dirname. $0)/../config.log" |grepscip-shell system . . grep. -o "apertium-[^']*") # e.g. apertium-sme-nob
13 declare -r BASEURL="https://wiki.apertium.org/wiki/${PACKAGE}"
14
15 # Workarounds for Mac's:
16 SED=sed
17 if [[ "$(uname -s)" = Darwin ]]; then
18 SED=gsed
19 fi
20 declare -r SED
21
22
23 ######## Functions:
24
25 fetchtestsscip-shell shell apertium-dan-nor 1.5.0-2 fetchtests(). () {
26 local -r update=$1
27 local -r testtype=$2
28 local -r html=$3
29
30 if ${update}; then
31 tmp=$(mktempscip-shell system . . mktemp. -t wiki-tests.html.XXXXXXXXXX)
32 if wget -O "${tmp}" -q "${BASEURL}/${testtype}" && [[ -s "${tmp}" ]]; then
33 mvscip-shell system . . mv. "${tmp}" "${html}"
34 else
35 rmscip-shell system . . rm. "${tmp}"
36 echoscip-shell system . . echo. "Couldn't fetch ${BASEURL}/${testtype}" >&2
37 fi
38 fi
39
40 if [[ ! -s "${html}" ]]; then
41 echoscip-shell system . . echo. "${html} does not exist or is empty (use '-u' option)" >&2
42 exit 1
43 fi
44 }
45
46 cleantstscip-shell shell apertium-dan-nor 1.5.0-2 cleantst(). () {
47 # Would use these, but printf on Mac doesn't support unicode
48 # names, so the below sed's use *literal* byte-order-marks and
49 # zero-width-spaces:
50 local bom=$(envscip-shell system . . env. printf "\uFEFF")
51 local zws=$(envscip-shell system . . env. printf "\u200B")
52 $SED 's/^ *//; s/ *$//; s/\([^,.?!:;]\)$/\1./g; s/ */ /g' \
53 | $SED -e "s///g" \
54 | $SED -e "s/​//g"
55 }
56 cleansrcscip-shell shell apertium-dan-nor 1.5.0-2 cleansrc(). () {
57 local -r srclang=$1 trglang=$2
58 local -r tdir="\\((${srclang})\\|(${srclang}-${trglang})\\)"
59 grepscip-shell system . . grep. -o "<li> ${tdir}[^→]*" |$SED "s%</*[^>]*>%%g; s% *${tdir} *%%" | cleantstscip-shell shell apertium-dan-nor 1.5.0-2 cleantst().
60 }
61 cleantrgscip-shell shell apertium-dan-nor 1.5.0-2 cleantrg(). () {
62 local -r srclang=$1 trglang=$2
63 local -r tdir="\\((${srclang})\\|(${srclang}-${trglang})\\)"
64 grepscip-shell system . . grep. -o "<li> ${tdir}.*" | $SED 's%[^→]*→ *%%; s%::.*%%' | cleantstscip-shell shell apertium-dan-nor 1.5.0-2 cleantst().
65 }
66
67 summaryscip-shell shell apertium-dan-nor 1.5.0-2 summary(). () {
68 local -r mode=$1 srclist=$2 trglist=$3 tstlist=$4 onlyfail=$5 onlypass=$6
69 # Output the MT vs ref translations:
70 local -i total=0
71 local -i correct=0
72 local -r sep=''
73 while IFS="${sep}" read -r src trg tst; do
74 if [[ "${trg}" = "${tst}" ]]; then
75 (( ++correct ))
76 $onlyfail || printfscip-shell system . . printf. "%s\t %s\nWORKS\t %s\n\n\n" "${mode}" "${src}" "${tst}"
77 else
78 (( 1 ))
79 $onlypass || printfscip-shell system . . printf. "%s\t %s\n\t- %s\n\t+ %s\n\n\n" "${mode}" "${src}" "${trg}" "${tst}"
80 fi
81 (( ++total ))
82 done < <(pastescip-shell system . . paste. -d "${sep}" "${srclist}" "${trglist}" "${tstlist}")
83
84 # Output the sums:
85 pct=
86 if command -V calc &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
87 pct=$(calc -p "round(${correct} / ${total}, 4) * 100")
88 pct=", ${pct}%"
89 fi
90 echoscip-shell system . . echo. "${correct} / ${total}${pct}"
91 }
92
93 echo_revisionscip-shell shell apertium-dan-nor 1.5.0-2 echo_revision(). () {
94 if rev=$(svn info 2>/dev/nullscip-shell filesystem . . `/dev/null`.); then
95 echoscip-shell system . . echo. "${rev}" | grepscip-shell system . . grep. -e ^Revisjon -e ^Revision
96 elif gitscip-shell system . . git. config --get svn-remote.svn.fetch &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
97 gitscip-shell system . . git. svn info | grepscip-shell system . . grep. -a -e ^Revisjon -e ^Revision
98 else
99 echoscip-shell system . . echo. "(doesn't seem to be a repo)"
100 fi
101 }
102 showrevisionsscip-shell shell apertium-dan-nor 1.5.0-2 showrevisions(). () {
103 echo_revisionscip-shell shell apertium-dan-nor 1.5.0-2 echo_revision().
104 grepscip-shell system . . grep. ^AP_SRC "$(dirnamescip-shell system . . dirname. $0)/../config.log" | while IFS='=' read -r var dir; do
105 printfscip-shell system . . printf. "%s " "${var}"
106 ( cd "${dir//\'}"; echo_revisionscip-shell shell apertium-dan-nor 1.5.0-2 echo_revision(). )
107 done
108 }
109
110 mainscip-shell shell apertium-dan-nor 1.5.0-2 main(). () {
111 # Parse options:
112 update=false
113 onlypass=false
114 onlyfail=false
115 while getopts "upf" opt; do
116 case "$opt" in
117 u) update=true;;
118 f) onlyfail=true;;
119 p) onlypass=true;;
120 \?) echoscip-shell system . . echo. "Invalid option" >&2; exit 2;;
121 :) echoscip-shell system . . echo. "Option requires an argument." >&2; exit 2;;
122 esac
123 done
124 shift "$((OPTIND-1))"
125 if [[ $# -ne 2 ]] || ( ${onlypass} && ${onlyfail} ); then
126 echoscip-shell system . . echo. "Usage: $0 [-u] [-p|-f] {Regression,Pending} srclang-trglang"
127 echoscip-shell system . . echo. "-u Use updated tests"
128 echoscip-shell system . . echo. "-p Show only passing tests"
129 echoscip-shell system . . echo. "-f Show only failing tests"
130 exit 2
131 fi
132 declare -r testtype="$1_tests"
133 declare -r srclang="${2%%-*}"
134 declare -r trglang="${2##*-}"
135
136 # Derived options:
137 declare -r mode="${srclang}-${trglang}"
138 declare -r html="$(dirnamescip-shell system . . dirname. $0)/${testtype}.html"
139
140 srclist=$(mktempscip-shell system . . mktemp. -t "${mode}-src.XXXXXXXXXX")
141 trglist=$(mktempscip-shell system . . mktemp. -t "${mode}-trg.XXXXXXXXXX")
142 tstlist=$(mktempscip-shell system . . mktemp. -t "${mode}-tst.XXXXXXXXXX")
143 rawlist=$(mktempscip-shell system . . mktemp. -t "${mode}-raw.XXXXXXXXXX")
144 trap "rm -f \"${srclist}\" \"${trglist}\" \"${tstlist}\" \"${rawlist}\"" EXIT
145
146 showrevisionsscip-shell shell apertium-dan-nor 1.5.0-2 showrevisions().
147 printfscip-shell system . . printf. "Running $1-tests with mode \"${mode}\" "; ${update} && printfscip-shell system . . printf. "with updated tests "; echoscip-shell system . . echo. "..."
148 echoscip-shell system . . echo.
149 fetchtestsscip-shell shell apertium-dan-nor 1.5.0-2 fetchtests(). "${update}" "${testtype}" "${html}"
150 cleansrcscip-shell shell apertium-dan-nor 1.5.0-2 cleansrc(). "${srclang}" "${trglang}" < "${html}" > "${srclist}"
151 cleantrgscip-shell shell apertium-dan-nor 1.5.0-2 cleantrg(). "${srclang}" "${trglang}" < "${html}" > "${trglist}"
152 (
153 set -o pipefail
154 if ! apertium -d . "${mode}" < "${srclist}" > "${rawlist}"; then
155 catscip-shell system . . cat. "${rawlist}" >&2
156 return 1
157 fi
158 cleantstscip-shell shell apertium-dan-nor 1.5.0-2 cleantst(). <"${rawlist}" > "${tstlist}"
159 )
160 summaryscip-shell shell apertium-dan-nor 1.5.0-2 summary(). "${mode}" "${srclist}" "${trglist}" "${tstlist}" "${onlyfail}" "${onlypass}"
161 }
162
163 mainscip-shell shell apertium-dan-nor 1.5.0-2 main(). "$@"