-
Notifications
You must be signed in to change notification settings - Fork 6
/
update-exp
executable file
·104 lines (97 loc) · 3.04 KB
/
update-exp
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
#!/bin/sh
# update expected outputs to match actual ones, if appropriate
PAGER=${PAGER:-more}
# send source file name and content to stdout. Inputs are file name and
# message text to follow it.
prefix () {
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "$1\n$2" | fmt -c -w 78
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
cat $1
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "$2" | fmt -c -w 78
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
}
# Determine whether to accept compiler output as expected. Inputs are:
# source file name
# compiler output file name
# current expected output file name, or empty for new test cases
agree () {
if [ -r "$3" ] ; then
action=diff
valid="yes accept|no keep|diff|unified|previous|current|quit"
else
action=current
valid="yes accept|no reject|current|quit"
fi
while true ; do
destination=$PAGER
case "$action" in
[A-Z]*) destination=cat
esac
case "$action" in
[dD]*)
(prefix "$1" 'Output Changes' ; \
dwdiff -c -d '()<>~!@:?.%#,\"' "$3" "$2" ) | $destination ;;
[uU]*)
(prefix "$1" 'Output Changes' ; \
diff -u "$3" "$2" ) | $destination ;;
[pP]*)
(prefix "$1" 'Previous Expected Output' ; \
cat "$3" ) | $destination ;;
[cC]*)
(prefix "$1" 'Current Output' ; \
cat "$2" ) | $destination ;;
ask) ;; # just ask again
esac
echo "Accept output for $1?"
echo "(upper case to see output without paging)"
read -p "$valid: " action
case "$action" in
[yYaA]*) return 0 ;; # 0 means true
[nNrR]*) return 1 ;; # non-0 means false
[qQ]*) echo "Quitting..." ; exit 0 ;;
[dDuUpP]*) if [ ! -r "$3" ] ; then
echo "No previous expected output!"
action=ask
fi ;;
[cC]) ;;
*) echo "Please answer $valid." ;;
esac
done
}
updatefile () {
exp=$(echo "$f" | sed 's/\.wybe/.exp/')
out=$(echo "$f" | sed 's/\.wybe/.out/')
if ! [ -r "$out" ] ; then
echo "No output file $out"
exit 1
fi
if [ -r "$exp" ] && diff -q "$exp" "$out" > /dev/null ; then
echo "Output for $f unchanged"
else
if agree "$f" "$out" "$exp" ; then
cp "$out" "$exp"
echo "Expected output for $f updated"
else
echo "Expected output for $f NOT changed"
fi
fi
}
if [ $# -eq 0 ] ; then
make || exit 1
make test
for f in test-cases/final-dump/*.wybe ; do
updatefile "$f"
done
for f in test-cases/execution/*.wybe ; do
updatefile "$f"
done
for f in test-cases/complex/exp/*.wybe ; do
updatefile "$f"
done
else
for f in "$@" ; do
updatefile "$f"
done
fi