forked from zrax/pycdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompyle_test.sh
executable file
·132 lines (117 loc) · 3.02 KB
/
decompyle_test.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
#!/bin/bash
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
testdir="$srcdir/tests"
testname="$1"
outdir="$2"
if [[ -z "$PYTHON_EXE" ]]; then
PYTHON_EXE="$(which python3)"
fi
if [[ -z "$testname" ]]; then
echo "Missing required parameter: testname" >&2
exit 1
fi
if [[ -z "$outdir" ]]; then
echo "Missing required parameter: outdir" >&2
exit 1
fi
shopt -s nullglob
compfiles=( "$testdir/compiled/$testname".?.?*.pyc )
xfcfiles=( "$testdir/xfail/$testname".?.?*.pyc )
shopt -u nullglob
if (( ${#compfiles[@]} + ${#xfcfiles[@]} == 0 )); then
echo "No compiled/xfail modules found for $testname.*.pyc"
exit 1
fi
mkdir -p "$outdir"
echo -ne "\033[1m*** $testname:\033[0m "
fails=0
xfails=0
upass=0
efiles=()
errors=()
upfiles=()
for pyc in "${compfiles[@]}" "${xfcfiles[@]}"; do
base="$outdir/$(basename "$pyc")"
./pycdc "$pyc" -o "$base.src.py" >"$base.err" 2>&1
if (( $? )) || [[ -s "$base.err" ]]
then
if [[ "$(dirname "$pyc")" =~ xfail ]]
then
let xfails+=1
else
let fails+=1
efiles+=("$(basename "$pyc")")
errors+=("$(cat "$base.err")")
fi
continue
fi
"$PYTHON_EXE" "$srcdir"/scripts/token_dump "$base.src.py" 2>"$base.tok.err" 1>"$base.tok.txt"
if (( $? )) || [[ -s "$base.tok.err" ]]
then
if [[ "$(dirname "$pyc")" =~ xfail ]]
then
let xfails+=1
else
let fails+=1
efiles+=("$(basename "$pyc")")
errors+=("$(cat "$base.tok.err")")
fi
continue
fi
diff -u "$testdir/tokenized/$testname.txt" "$base.tok.txt" >"$base.tok.diff"
if (( $? ))
then
if [[ "$(dirname "$pyc")" =~ xfail ]]
then
let xfails+=1
else
let fails+=1
efiles+=("$(basename "$pyc")")
errors+=("$base.tok.txt does not match $testdir/tokenized/$testname.txt:\n$(cat "$base.tok.diff")")
fi
else
if [[ "$(dirname "$pyc")" =~ xfail ]]
then
let upass+=1
upfiles+=("$(basename "$pyc")")
fi
fi
done
if (( $fails == 0 ))
then
if (( $xfails != 0 ))
then
if (( ${#compfiles[@]} == 0 ))
then
echo -e "\033[33mXFAIL ($xfails)\033[0m"
else
echo -e "\033[32mPASS (${#compfiles[@]})\033[33m + XFAIL ($xfails)\033[0m"
fi
else
echo -e "\033[32mPASS (${#compfiles[@]})\033[0m"
fi
else
if (( $xfails != 0 ))
then
echo -e "\033[31mFAIL ($fails of ${#compfiles[@]})\033[33m + XFAIL ($xfails)\033[0m"
else
echo -e "\033[31mFAIL ($fails of ${#compfiles[@]})\033[0m"
fi
for ((i=0; i<${#efiles[@]}; i++))
do
echo -e "\t\033[31m${efiles[i]}\033[0m"
echo -e "${errors[i]}\n"
done
fi
if (( $upass != 0 ))
then
echo -e "\033[1;34mUnexpected passes:\033[0m"
for ((i=0; i<${#upfiles[@]}; i++))
do
echo -e "\t\033[33m${upfiles[i]}\033[0m"
done
fi
if (( $fails != 0 ))
then
exit 1
fi