1 | #!/usr/bin/env bash |
2 |
|
3 | success() { |
4 | echo -e "\033[92m\033[1m\033[7m${@}\033[0m" |
5 | } |
6 |
|
7 | success_lite() { |
8 | echo -e "\033[92m${@}\033[0m" |
9 | } |
10 |
|
11 | error() { |
12 | echo -e "\033[91m\033[7m\033[1m${@}\033[0m" |
13 | } |
14 |
|
15 | warn() { |
16 | echo -e "\033[93m\033[1m\033[7m${@}\033[0m" |
17 | } |
18 |
|
19 | warn_lite() { |
20 | echo -e "\033[93m${@}\033[0m" |
21 | } |
22 |
|
23 | handle() { |
24 | echo $1 |
25 | $1 |
26 | if [ $? -ne 0 ] |
27 | then |
28 | error "Error in test. Exiting..." |
29 | exit $1 |
30 | else |
31 | success_lite "Success in test." |
32 | fi |
33 | } |
34 |
|
35 | help() { |
36 | echo "Usage: ./test [help] [c_unit] [performance] [lint]" |
37 | } |
38 |
|
39 | c_unit() { |
40 | warn "Running C unit test chain" |
41 | echo |
42 |
|
43 | # Compile C unit tests |
44 | warn_lite "Making C header unit test" |
45 | handle "gcc -pedantic -Wall -Wextra -Werror -o bin/c -I src/c tests/header_unit.c tests/header_unit_2.c" |
46 | echo |
47 |
|
48 | warn_lite "Running C header unit test" |
49 | handle bin/c |
50 | echo |
51 |
|
52 | success "Finished" |
53 | } |
54 |
|
55 | lint() { |
56 | warn "Running lint test" |
57 | echo |
58 |
|
59 | find . -name "*.c" -print0 | while read -d $'\0' file |
60 | do |
61 | warn_lite "Executing gcc --syntax-only $file" |
62 | handle "gcc --syntax-only -pedantic -Wall -Wextra -I src/c $file" |
63 | echo |
64 | done |
65 |
|
66 | success "Finished" |
67 | } |
68 |
|
69 | performance() { |
70 | warn "Running performance test" |
71 | echo |
72 |
|
73 | warn_lite "Compiling and getting file sizes" |
74 | handle tests/performance.py |
75 | echo |
76 |
|
77 | success "Finished" |
78 | } |
79 |
|
80 | for test in "$@" |
81 | do |
82 | $test |
83 | done |
84 |
|
85 | echo -e "finished: ${SECONDS} seconds" |
86 |
|