forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review
executable file
·424 lines (372 loc) · 7.45 KB
/
review
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/bin/bash
#
# review - Review the diff between expected output and actual output in Units
#
# Copyright (C) 2016 Masatake YAMATO
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
print_help()
{
echo Usage:
printf " %-20s %-30s %s\n" "$0" "help|--help|-h" "show this message"
printf " %-20s %-30s %s\n" "$0" "[list] [-b]" "list failed Units and Tmain"
help_list
printf " %-20s %-30s %s\n" "$0" "inspect [-b]" "inspect difference interactively"
help_inspect
exit $1
}
is_known_bug()
{
[[ $1 == *.b ]]
return $?
}
do_list ()
{
local d
local n
local a
local including_known_bugs
for a in "$@"; do
case $a in
(-b)
including_known_bugs=-b
;;
(-*)
echo "unknown option: ${a}" 1>&2
exit 1
;;
(*)
echo "unexpected argument ${a}" 1>&2
exit 1
;;
esac
done
for d in $(find Units -name "DIFF.tmp"); do
n=$(dirname "$d")
if (( ! is_known_bug $(basename "$n") ) || [[ -n ${including_known_bugs} ]] ) \
&& [[ -e "$n"/expected.tags ]]; then
echo ${n}
fi
done
for d in $(find Tmain -name "*-diff.txt"); do
n=$(dirname "$d")
echo ${n}
done | sort -u
}
help_list()
{
printf " %-20s %-30s %s\n" "" "-b" "list .b (known bug) marked cases"
}
diff_post_processor()
{
local cmd=cat
if which colordiff > /dev/null 2>&1; then
cmd=colordiff
elif which pygmentize > /dev/null 2>&1; then
cmd="pygmentize -l diff"
fi
$cmd
}
units_inspect_cmd_accept ()
{
local from=./Units/$1/FILTERED.tmp
local to=./Units/$1/expected.tags
local r
if [[ ! -e "${from}" ]]; then
echo "./Units/$1/FILTERED.tmp is not found" 1>&2
echo "Remove DIFF.tmp?"
read -p "[Y/n] "
if [[ "$REPLY" == Y ]]; then
rm ./Units/$t/DIFF.tmp
echo "Removed: DIFF.tmp"
r=1
else
echo "Kept: DIFF.tmp"
r=0
fi
return $r
fi
echo "Do you really want do following shell command?"
echo
echo " mv \"$from\"" '\'
echo " \"$to\" "
echo
read -p "[Y/n] "
if [[ "$REPLY" == Y ]]; then
mv "$from" "$to"
echo "Renamed: $from => $to"
r=0
echo "Remove DIFF.tmp, too?"
read -p "[Y/n] "
if [[ "$REPLY" == Y ]]; then
rm ./Units/$t/DIFF.tmp
echo "Removed: DIFF.tmp"
else
echo "Kept: DIFF.tmp"
fi
else
echo "Aborted"
r=1
fi
return $r
}
units_inspect_cmd_skip ()
{
echo "SKIPPING $1" 1>&2
}
units_inspect_cmd_show_generic ()
{
local tcase=$1
local file=$2
shift 2
local f=./Units/${tcase}/${file}
if [[ -r "$f" ]]; then
"$@" "$f"
else
echo "No ${file}" 1>&2
fi
echo '---'
echo '# ' "$f"
}
units_inspect_cmd_show_diff ()
{
units_inspect_cmd_show_generic $1 DIFF.tmp cat | diff_post_processor
}
units_inspect_show_args_ctags ()
{
units_inspect_cmd_show_generic $1 args.ctags cat
}
pygmentize_or_cat ()
{
# It seems that pygmentize ignores the empty lines at the head of input.
if [ -z "$(head -1 $1)" ]; then
cat -n $1
elif which pygmentize > /dev/null 2>&1; then
pygmentize -O "style=colorful,linenos=1" $1 2>/dev/null || cat -n $1
else
cat -n $1
fi
}
units_inspect_show_input ()
{
local tcase=$1
units_inspect_cmd_show_generic $tcase $(basename ./Units/${tcase}/input.*) pygmentize_or_cat
}
# See https://stackoverflow.com/questions/65533232/bash-extglob-pattern-matching-breaks-when-enclosed-in-a-function
shopt -s extglob
units_inspect_show_expected_tags ()
{
local tcase=$1
(
shopt -s extglob
units_inspect_cmd_show_generic $tcase $(basename ./Units/${tcase}/expected.tags?\(-*\)) "cat" "-n"
)
}
shopt -u extglob
inspect_cmd_quit ()
{
echo "BYE" 1>&2
exit 0
}
inspect_cmd_unknown()
{
echo "unknown command: $REPLY" 1>&2
echo "Just return to show menu" 1>&2
}
help_inspect ()
{
printf " %-20s %-30s %s\n" "" "-b" "inspect .b (known bug) marked cases"
}
do_units_inspect()
{
local next=0
local r
local t=$1
select r in '<a>ccept' '<s>kip (or <n>)' '<S>hell' '<d>iff' 'show args.<c>tags' 'show <i>nput' '<e>xpected tags' '<q>uit'; do
case $r-$REPLY in
("<a>ccept"-*|-a)
if units_inspect_cmd_accept "$t"; then
next=1
fi
;;
("<s>kip (or <n>)"-*|-s|-!|-skip|-n|-next)
units_inspect_cmd_skip "$t"
next=1
;;
("<S>hell"-*|-S)
inspect_cmd_shell Units "$t"
;;
("<d>iff"-*|-d|-=|-diff)
units_inspect_cmd_show_diff "$t"
;;
("<q>uit"-*|-q|-quit)
inspect_cmd_quit
;;
("show args.<c>tags"-*|-c|-A|-args.ctags)
units_inspect_show_args_ctags "$t"
;;
("show <i>nput"-*|-i|-input)
units_inspect_show_input "$t"
;;
("<e>xpected tags"-*|-e|-expected.tags)
units_inspect_show_expected_tags "$t"
;;
(*)
inspect_cmd_unknown
;;
esac
if [[ $next == 1 ]]; then
break
fi
done
}
function inspect_cmd_shell
{
local prefix=$1
local t=$2
(
cd $prefix/$t
PS1="review> " bash
)
}
function tmain_inspect_run
{
local t=$1
make tmain UNITS=$(basename $t .d)
}
tmain_inspect_cmd_show_diff_generic()
{
local prefix=$1
local t=$2
local c=$3
cat $prefix/$t/$c-diff.txt | diff_post_processor
}
tmain_inspect_cmd_show_diff_all()
{
local prefix=$1
local t=$2
local c
for c in stdout stderr exit; do
if [[ -e "$prefix/$t/$c-diff.txt" ]]; then
echo '### ' "$c"
tmain_inspect_cmd_show_diff_generic "$prefix" "$t" "$c"
fi
done
}
do_tmain_inspect()
{
local next=0
local r
local t=$1
select r in '<n>ext' '<d>iff' '<S>hell' '<R>un' '<q>uit'; do
case $r-$REPLY in
("<n>ext"-*|-n)
next=1
;;
("<d>iff"-*|-d)
tmain_inspect_cmd_show_diff_all Tmain "$t"
;;
("<S>hell"-*|-S)
inspect_cmd_shell Tmain "$t"
;;
("<R>un"-*|-R)
tmain_inspect_run "$t"
;;
("<q>uit"-*|-q|-quit)
inspect_cmd_quit
;;
esac
if [[ $next == 1 ]]; then
break
fi
done
}
count ()
{
echo $#
}
do_inspect ()
{
local a
local t0
local t
local including_known_bugs
for a in "$@"; do
case $a in
(-b)
including_known_bugs=-b
;;
(-*)
echo "unknown option: ${a}" 1>&2
exit 1
;;
(*)
echo "unexpected argument ${a}" 1>&2
exit 1
;;
esac
done
local T=$(do_list ${including_known_bugs});
local total=$(count $T)
local i=1
for t0 in $T; do
PS3="[$i/$total [ $t0 ]]? "
i=$(( i + 1 ))
t=${t0#Units/}
t=${t#Tmain/}
if [[ "$t0" =~ ^Units ]]; then
do_units_inspect "$t"
else
do_tmain_inspect "$t"
fi
done
}
main ()
{
local action
while [[ $# -gt 0 ]]; do
case $1 in
(help|--help|-h)
print_help 0
;;
(list)
action=$1
shift
break
;;
(inspect)
action=$1
shift
break
;;
(*)
print_help 1 1>&2
;;
esac
done
if [[ -z "$action" ]]; then
action=inspect
fi
if ! [[ -d ./Units ]]; then
echo "$0: cannot find ./Units directory" 1>&2
exit 1
fi
if ! [[ -d ./Tmain ]]; then
echo "$0: cannot find ./Tmain directory" 1>&2
exit 1
fi
do_${action} "$@"
}
main "$@"