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 | exit_on_error() { |
24 | if [ $1 -ne 0 ] |
25 | then |
26 | error "Error in test. Exiting..." |
27 | exit $1 |
28 | else |
29 | success_lite "Success in test." |
30 | fi |
31 | } |
32 |
|
33 | handle() { |
34 | $1 |
35 | exit_on_error $? |
36 | } |
37 |
|
38 | help() { |
39 | echo "Usage: ./test [help] [c_unit] [size] [lint]" |
40 | } |
41 |
|
42 | c_unit() { |
43 | warn "Running C unit test chain" |
44 | echo |
45 |
|
46 | # Compile C unit tests |
47 | warn_lite "Making C header unit test" |
48 | handle make c_unit |
49 | echo |
50 |
|
51 | warn_lite "Running C header unit test" |
52 | handle bin/c |
53 | echo |
54 |
|
55 | success "Finished" |
56 | } |
57 |
|
58 | lint() { |
59 | warn "Running lint test" |
60 | echo |
61 |
|
62 | find . -name "*.c" -print0 | while read -d $'\0' file |
63 | do |
64 | warn_lite "Executing gcc --syntax-only $file" |
65 | handle "gcc --syntax-only -pedantic -Wall -Wextra -I src/c $file" |
66 | echo |
67 | done |
68 |
|
69 | success "Finished" |
70 | } |
71 |
|
72 | size() { |
73 | warn "Running size test on optimization levels" |
74 | echo |
75 |
|
76 | warn_lite "Compiling and getting file sizes" |
77 | handle tests/size.py |
78 | echo |
79 |
|
80 | success "Finished" |
81 | } |
82 |
|
83 | for test in "$@" |
84 | do |
85 | $test |
86 | done |
87 |
|
88 | echo -e "finished: ${SECONDS} seconds" |
89 |
|