-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·160 lines (137 loc) · 3.29 KB
/
run.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
#!/bin/sh
##############
### config ###
##############
CFLAGS="-Wall -Wextra -Werror" -g #-fsanitize=address" #compiler flags
#CFLAGS="-g"
INCLUDES="-I . -I includes" #ft_printf.h location
LDFLAGS="-L . -l ftprintf" #-fsanitize=address" #static library and its location
#######################
### test norminette ###
#######################
#printf "\nTest norme... "
#norminette . > norm_output
#grep -B 1 "Error" norm_output > norm_errors
#if [ -s norm_errors ]
#then
# printf "Norme errors:\n"
# cat norm_errors
# exit 1
#else
# printf "Norme OK\n"
#fi
#rm -f norm_output norm_errors
#################
### test make ###
#################
make fclean && make && make clean
if [ $? != 0 ]
then
exit 1
fi
#make all && make re && make fclean && make && make clean
#if [ $? != 0 ]
#then
# printf "make error\n"
# exit 1
#fi
###################
### basic tests ###
###################
for f in printf_test/src/*.test
do
mv "$f" "${f%.test}"
done
rm -f test_exe
printf "\nBasic tests...\n\n"
test_srcs="printf_test/src/test*.c"
gcc -o test_exe $CFLAGS printf_test/src/main.c $test_srcs $INCLUDES $LDFLAGS
if [ $? != 0 ]
then
printf "compilation error"
exit 1
fi
run_test () {
local test_name=$1
local user_output="user_output_$test_name"
local test_output="test_output_$test_name"
local diff="diff_$test_name"
printf "Run %-30s" "$test_name..."
{ ./test_exe ft_printf $test_name > $user_output; } 2> err_output
if [ $? != 0 ]
then
printf "seg fault: run './test_exe ft_printf $test_name' for more info"
cat err_output
exit 1
fi
./test_exe printf $test_name > $test_output
diff --text --suppress-common-lines -p $user_output $test_output > $diff
if [ -s $diff ]
then
printf "error, see $diff\n"
# exit 1
else
printf "diff OK\n"
rm $diff $user_output $test_output
fi
}
run_pointer_test () {
local test_name=$1
local output="ptr_output"
local user_output="user_output_$test_name"
local test_output="test_output_$test_name"
local diff="diff_$test_name"
printf "Run %-30s" "$test_name..."
{ ./test_exe ft_printf $test_name > $output; } 2> err_output
if [ $? != 0 ]
then
printf "seg fault: run './test_exe ft_printf $test_name' for more info"
cat err_output./
exit 1
fi
line_count=$(cat $output | wc -l | sed "s/ //g")
head -n $(( $line_count / 2 )) $output > $user_output
tail -n $(( $line_count / 2 )) $output > $test_output
diff --text --suppress-common-lines -p $user_output $test_output > $diff
if [ -s $diff ]
then
printf "error, see $diff\n"
# exit 1
else
printf "diff OK\n"
rm $output $user_output $test_output $diff
fi
}
for test in $test_srcs
do
test_name="${test#printf_test/src/}"
test_name="${test_name%.c}"
if [ $test_name == "test_pointer" ]
then
run_pointer_test $test_name
else
run_test $test_name
fi
done
for f in printf_test/src/*.[ch]
do
mv "$f" "${f}.test"
done
###################
### test leaks ###
###################
echo ""
read -n 1 -p "Test leaks with valgrind [v] or leaks [l]? " leaks
if [ $leaks == "v" ]
then
printf "\n\nTesting leaks with valgrind...\n\n"
./test_exe ft_printf all valgrind > valgrind_output
elif [ $leaks == "l" ]
then
printf "\n\nTesting leaks with leaks...\n\n"
./test_exe ft_printf test_all leaks > leaks_output
grep -a -e "nodes malloced" -A 1 leaks_output
else
echo ""
fi
rm -f valgrind_output leaks_output err_output