-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·100 lines (76 loc) · 2.06 KB
/
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
#!/bin/bash
if [[ $# != 2 ]]; then
echo "Sposób uzytkowania: $0 <ścieżka/do/folderu/z/testami> <ścieżka/do/fodleru/z/projektem> " >&2
exit 1
fi
tests=$(realpath "$1")
project=$(realpath "$2")
if ! [[ -d "$tests" ]]; then
echo "Podany folder z testami nie istnieje"
exit 1
fi
if ! [[ -d "$project" ]]; then
echo "Podany folder z projektem nie istnieje"
exit 1
fi
total=0
correct=0
leaked=0
function traverse_folder() {
folder="$1"
shopt -s nullglob
for f in "$folder"/*.c; do
run_test "$f"
done
shopt -s nullglob
for f in "$folder"/*.cc; do
run_test "$f"
done
shopt -s nullglob
for d in "$folder"/*/; do
echo "$d"
traverse_folder "$(realpath "$d")"
done
}
RED='\033[0;31m'
GREEN='\033[0;32m'
NOCOLOR='\033[0m'
function run_test() {
input_file="$1"
extension="${input_file##*.}"
error_file=${input_file//.$extension/.err}
((total++))
echo -e "\e[1mTest $f \e[0m"
if [[ "$extension" == "c" ]]; then
gcc -Wall -Wextra -O2 -std=c11 -c "$input_file" -o test_obj.o
else
g++ -Wall -Wextra -O2 -std=c++17 -c "$input_file" -o test_obj.o
fi
g++ test_obj.o encstrset.o -o compiled_test
./compiled_test 1>"$temp_out" 2>"$temp_err"
rm compiled_test 2> /dev/null
if [[ ! -s "$temp_out" ]]; then
echo -ne "${GREEN}stdout ok (empty)${NOCOLOR}, "
if cmp -s "$error_file" "$temp_err" ; then
echo -ne "${GREEN}stderr ok${NOCOLOR}\n"
((correct++))
else
echo -ne "${RED}stderr nieprawidlowe${NOCOLOR}\n"
diff -d "$error_file" "$temp_err"
# cat "$temp_err"
fi
else
echo -ne "${RED}stdout nieprawidlowe (niepuste)${NOCOLOR}\n"
diff -d "$output_file" "$temp_out"
fi
}
temp_out=$(mktemp)
temp_err=$(mktemp)
trap 'rm -f "$temp_out"' INT TERM HUP EXIT
trap 'rm -f "$temp_err"' INT TERM HUP EXIT
cd $2
echo "Compilation of encstrset.cc..."
g++ -Wall -Wextra -O2 -std=c++17 -c encstrset.cc -o encstrset.o
traverse_folder "$tests"
rm test_obj.o encstrset.o 2> /dev/null
echo "total: ${total}, correct ${correct}"