This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·118 lines (94 loc) · 3.02 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env sh
set -e
OUTDIR="${OUTDIR:-tests-out}"
log() { "${2:-echo}" " :: $1"; }
test_gcc_like() {
case "$2" in
c)
log "\033[1mTesting C with $3\033[0m\n" printf
for cstd in c90 c89 iso9899:1990 iso9899:199409 \
c99 c9x iso9899:1999 iso9899:199x c11 c1x \
iso9899:2011 c17 c18 iso9899:2017 iso9899:2018 \
c2x iso9899:2018 c2x gnu90 gnu89 gnu99 gnu9x gnu11 \
gnu1x gnu17 gnu18 gnu2x; do
{
log "Testing C standard: \033[1m$cstd\033[0m\n" printf
if ! "$3" -Iinclude -Werror -Wall -Wextra -Wshadow -Wpedantic \
-pedantic -std="$cstd" -o "$OUTDIR/$3-$cstd" "$1"; then
log "\033[1;31mC standard $cstd failed\033[0m\n" printf >&2
exit 2
fi
} &
done
wait
;;
cpp)
log "\033[1mTesting C++ with $4\033[0m\n" printf
for cppstd in c++98 c++03 gnu++98 gnu++03 c++11 c++0x \
gnu++11 gnu++0x c++14 c++1y gnu++14 gnu++1y c++17 \
c++1z gnu++17 gnu++1z c++20 c++2a gnu++20 gnu++2a \
c++2b gnu++2b; do
{
log "Testing C++ standard: \033[1m$cppstd\033[0m\n" printf
if ! "$4" -Iinclude -Werror -Wall -Wextra -Wshadow -Wpedantic \
-pedantic -std="$cppstd" -o "$OUTDIR/$4-$cppstd" "$1"; then
log "\033[1;31mC++ standard $cppstd failed\033[0m\n" printf >&2
exit 2
fi
} &
done
wait
;;
*)
log "Unhandled test case: $1" >&2
exit 1
;;
esac
}
test_gcc() { test_gcc_like "$1" "$2" 'gcc' 'g++'; }
test_clang() { test_gcc_like "$1" "$2" 'clang' 'clang++'; }
test_tcc() {
if [ "$2" = 'c' ]; then
log '\033[1mTesting C with tcc\033[0m\n' printf
for std in c99 c11; do
{
log "Testing C standard: \033[1m$cstd\033[0m\n" printf
if ! tcc -Iinclude -std="$std" -Wall -Werror -o "$OUTDIR/tcc-$std" "$1"; then
log "\033[1;31mC standard $std failed\033[0m\n" printf >&2
exit 2
fi
} &
done
wait
fi
}
run_binaries() {
for bin in "$OUTDIR"/*; do
{
log "Running \033[1m$bin\033[0m\n" printf
if ! ./"$bin" >/dev/null 2>&1; then
log "\033[1;31mBinary '$bin' failed\033[0m\n" printf >&2
exit 3
fi
} &
done
wait
}
main() {
rm -rf -- "$OUTDIR"
mkdir -p -- "$OUTDIR"
for compiler in gcc clang tcc; do
log "Looking for '$compiler'... " printf
if ! command -v "$compiler"; then
echo 'not found'
continue
fi
for testf in tests/*; do
"test_$compiler" "$testf" "$(printf '%s' "$testf" |
awk -F . '{if (NF>1) {print $NF}}')"
done
done
log 'Running binaries'
run_binaries
}
main "$@"