-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtester.sh
executable file
·203 lines (189 loc) · 5.15 KB
/
tester.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
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
#!/bin/bash
#
# This script tests .tree files.
# usage: ./tester.sh [-c] [FILE.tree | treedir/]?
# the '-c' flag compiles the program and compares expected output
#
# File structure:
# .tree files go in tests/programs
# expected AST files go in tests/output_exp/FILE_exp
# expected compiled output files go in tests/output_res/FILE_res
# All other directories are only used by the script
#
# define suffixes
out='_out'
exp='_exp'
# define directories
progdict='tests/programs/'
outdict='tests/output_out/'
expdict='tests/output_exp/'
# define default option
options='./pltree'
# Make sure there's arguments
if [ $# -eq 0 ]
then
expdict='tests/output_res/'
exp='_res'
for f in $(ls $progdict)
do
# remove .tree extension
progname="${f%.*}"
# Make sure an expected output file is present
if ! [ -a ${expdict}${progname}${exp} ]
then
echo "Place ${progname}${exp} file in ${expdict} directory."
exit 2;
else
# make all the files and save output
make $progdict$progname &> /dev/null
$progdict$progname > "${outdict}${progname}${out}"
# check if there are diffs
if ! [[ $(diff -bw ${outdict}${progname}${out} ${expdict}${progname}${exp}) ]]
then
printf "${progdict}${progname}: \033[0;32mSUCCESS\033[0m\n"
else
printf "${progdict}${progname}: \033[0;31mFAILED\033[0m\n"
fi
# clean directory of all non-.tree files
find $progdict ! -name "*.tree" -type f -delete
fi
done
fi
make_calc() {
# run "make"; surpress output
make install &> /dev/null
# double check that calc was created
if ! [ -a pltree ]
then
echo 'Invoke lexer/parser to produce calc file.'
exit 2;
fi
}
# First, check for -c (compile) flag
while getopts ":c" opt; do
case $opt in
c)
# change variables if the -c flag is present
outdict='tests/output_com/'
expdict='tests/output_res/'
rundict='tests/output_run/'
out='_run'
exp='_res'
options='./pltree'
make_calc
for arg
do
# if it's a regular file
if [ -f $arg ]
then
# remove .tree extension
progname="${arg%.*}"
# Make sure an expected output file is present
if ! [ -a ${expdict}${progname}${exp} ]
then
echo "Place ${progname}${exp} file in ${expdict} directory."
exit 2;
else
# compile given file; save output
$options $arg "${outdict}${progname}.c"
gcc -Wall "${outdict}${progname}.c" -o "${outdict}${progname}"
rm -rf *.tmp
touch "${rundict}${progname}${out}"
"./${outdict}${progname}" > "${rundict}${progname}${out}"
# check if there are diffs
if ! [[ $(diff -bw ${rundict}${progname}${out} ${expdict}${progname}${exp}) ]]
then
printf "${progname}: \033[0;32mSUCCESS\033[0m\n"
else
printf "${progname}: \033[0;31mFAILED\033[0m\n"
fi
fi
# if it's a directory
elif [ -d $arg ]
then
for f in $(ls $arg)
do
# remove .tree extension
progname="${f%.*}"
# Make sure an expected output file is present
if ! [ -a ${expdict}${progname}${exp} ]
then
echo "Place ${progname}${exp} file in ${expdict} directory."
exit 2;
else
# compile given file; save output
$options $arg/$f "${outdict}${progname}.c"
gcc -Wall "${outdict}${progname}.c" -o "${outdict}${progname}"
rm -rf $arg/*.tmp
touch "${rundict}${progname}${out}"
"./${outdict}${progname}" > "${rundict}${progname}${out}"
# check if there are diffs
if ! [[ $(diff -bw ${rundict}${progname}${out} ${expdict}${progname}${exp}) ]]
then
printf "${arg}${progname}: \033[0;32mSUCCESS\033[0m\n"
else
printf "${arg}${progname}: \033[0;31mFAILED\033[0m\n"
fi
fi
done
fi
done
exit 2;
;;
\?)
# exit on invalid flag
echo "Invalid option: -$OPTARG"
exit 2;
;;
esac
done
make_calc
for arg
do
# if it's a regular file
if [ -f $arg ]
then
# remove .tree extension
progname="${arg%.*}"
# Make sure an expected output file is present
if ! [ -a ${expdict}${progname}${exp} ]
then
echo "Place ${progname}${exp} file in ${expdict} directory."
exit 2;
else
# run parser on input file; save output
cat $arg | $options > "${outdict}${progname}${out}"
# check if there are diffs
if ! [[ $(diff -bw ${outdict}${progname}${out} ${expdict}${progname}${exp}) ]]
then
printf "${progname}: \033[0;32mSUCCESS\033[0m\n"
else
printf "${progname}: \033[0;31mFAILED\033[0m\n"
fi
fi
# if it's a directory
elif [ -d $arg ]
then
for f in $(ls $arg)
do
# remove .tree extension
progname="${f%.*}"
# Make sure an expected output file is present
if ! [ -a ${expdict}${progname}${exp} ]
then
echo "Place ${progname}${exp} file in ${expdict} directory."
exit 2;
else
# run parser on input file; save output
cat $arg/$f | $options > "${outdict}${progname}${out}"
# check if there are diffs
if ! [[ $(diff -bw ${outdict}${progname}${out} ${expdict}${progname}${exp}) ]]
then
printf "${arg}/${progname}: \033[0;32mSUCCESS\033[0m\n"
else
printf "${arg}/${progname}: \033[0;31mFAILED\033[0m\n"
fi
fi
done
fi
done