-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.sh
executable file
·91 lines (74 loc) · 2.47 KB
/
test1.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
#!/bin/bash
if [ ! -d "./provided_tests" ]; then
echo "Error: tests directory not found!"
exit 1
fi
if [ ! -e "./a.out" ]; then
echo "Error: a.out not found!"
exit 1
fi
if [ ! -x "./a.out" ]; then
echo "Error: a.out not executable!"
exit 1
fi
let count=0
let all=0
mkdir -p ./output
for test_file in $(find ./provided_tests -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Error_Code_1 -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Error_Code_2 -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Error_Code_3 -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Error_Code_4 -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Error_Code_5 -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/No_Error -type f -name "*.txt" | sort); do
#for test_file in $(find ./provided_tests/Syntax_Error -type f -name "*.txt" | sort); do
all=$((all+1))
name=`basename ${test_file} .txt`
expected_file=${test_file}.expected
output_file=./output/${name}.output
diff_file=./output/${name}.diff
./a.out < ${test_file} > ${output_file}
folder_name="$(cut -d'/' -f3 <<<"${test_file}")"
if [ ${folder_name} = "Syntax_Error" ]; then
diff -Bw ${expected_file} ${output_file} > ${diff_file}
out=$(<${output_file})
exp=$(<${expected_file})
if [[ ${exp} == "SYNTAX ERROR !&%!" ]]; then
if [[ ${out} == "SYNTAX ERROR !&%!" ]]; then
count=$((count+1))
echo "${name}: OK"
else
echo "${name}: Output does not match expected:"
echo "--------------------------------------------------------"
cat ${diff_file}
fi
else
if [[ ${out} == "SYNTAX ERROR !&%!" ]]; then
echo "${name}: Output does not match expected:"
echo "--------------------------------------------------------"
cat ${diff_file}
else
count=$((count+1))
echo "${name}: OK"
fi
fi
else
diff -Bw ${expected_file} ${output_file} > ${diff_file}
echo
if [ -s ${diff_file} ]; then
echo "${name}: Output does not match expected:"
echo "--------------------------------------------------------"
cat ${diff_file}
else
count=$((count+1))
echo "${name}: OK"
fi
fi
echo "========================================================"
rm -f ${output_file}
rm -f ${diff_file}
done
echo
echo "Passed $count tests out of $all"
echo
rmdir ./output