-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·61 lines (52 loc) · 1.8 KB
/
test
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
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
pattern=".*\\.h"
fi
if [ $# -eq 1 ]; then
pattern=".*$1.*\\.h"
fi
rm -f ./tests/.test.c
# compile and all tests individually
find ./tests -regex "$pattern" -print0 | while read -d $'\0' file; do
name=$(basename "$file" .h)
printf "#include \".$file\"\\nint main(void) { $name(); alloc_list_dump(); assert_msg(alloc_list_is_empty(),\"$file\"); return 0; }" > ./tests/.test.c
gcc ./tests/.test.c -o bin/test -Wall -Wextra -lm -DALLOC_TRACE -DFILE_TRACE
./bin/test
echo -n "."
done
if [ $# -eq 0 ]; then
# check if all source files have a corresponding test
find ./src -type f -not -name "all.h" -print0 | while read -d $'\0' file; do
test="${file%/*}/test_${file##*/}"
test="${test/src/tests}"
if [ ! -f "$test" ]; then
printf "\r\e[KTest missing: ${test} (because ${file})\n" >&2
exit 1
fi
done
# check if all functions are included in all.h
find ./src/func -type f -print0 | while read -d $'\0' file; do
func="${file/\/src\/func/}"
if ! grep -q "$func" "./src/func/all.h" && [ "$func" != "./all.h" ]; then
printf "\r\e[KInclude missing in all.h: #include \"${func}\"\n" >&2
exit 1
fi
done
# check if all funcs have a corresponding example
find ./src/func -type f -not -name "all.h" -print0 | while read -d $'\0' file; do
example="${file/src/examples}"
example="${example%.h}.c"
if [ ! -f "$example" ]; then
printf "\r\e[KExample missing: ${example} (because ${file})\n" >&2
exit 1
fi
done
fi
if [ -f ./tests/.test.c ]; then
rm ./tests/.test.c
printf "\r\e[KAll tests passed\n"
else
printf "\r\e[KNo tests found for pattern: $1\n" >&2
exit 1
fi