1 | #!/usr/bin/env bash |
2 |
|
3 | CC="gcc" |
4 |
|
5 | success() { |
6 | echo -e "\033[92m\033[1m\033[7m${@}\033[0m" |
7 | } |
8 |
|
9 | success_lite() { |
10 | echo -e "\033[92m${@}\033[0m" |
11 | } |
12 |
|
13 | error() { |
14 | echo -e "\033[91m\033[7m\033[1m${@}\033[0m" |
15 | } |
16 |
|
17 | warn() { |
18 | echo -e "\033[93m\033[1m\033[7m${@}\033[0m" |
19 | } |
20 |
|
21 | warn_lite() { |
22 | echo -e "\033[93m${@}\033[0m" |
23 | } |
24 |
|
25 | handle() { |
26 | echo $1 |
27 | $1 |
28 | if [ $? -ne 0 ] |
29 | then |
30 | error "Error in test. Exiting..." |
31 | exit 1 |
32 | else |
33 | success_lite "Success in test." |
34 | fi |
35 | } |
36 |
|
37 | help() { |
38 | echo "Usage: ./test [help] [c_unit] [parser] [lint] [performance] [memory] [clean]" |
39 | } |
40 |
|
41 | c_unit() { |
42 | warn "Running C unit test chain" |
43 | echo |
44 |
|
45 | # Compile C unit tests |
46 | warn_lite "Making C header unit test" |
47 | mkdir -p bin |
48 | handle "$CC -std=c11 -pedantic -Wall -Wextra -Werror -o bin/c -I src tests/header_unit.c tests/header_unit_2.c" |
49 | echo |
50 |
|
51 | warn_lite "Running C header unit test" |
52 | handle bin/c |
53 | echo |
54 |
|
55 | success "Finished" |
56 | } |
57 |
|
58 | parser() { |
59 | warn "Compiling parser" |
60 | echo |
61 |
|
62 | warn_lite "Running compiler" |
63 | mkdir -p bin |
64 | FILES=$(find src/lnm/*.c) |
65 | handle "$CC -std=c11 -pedantic -Wall -Wextra -Werror -o bin/parser -I src $FILES -lncurses" |
66 | echo |
67 |
|
68 | success "Finished" |
69 | } |
70 |
|
71 | lint() { |
72 | warn "Running lint test" |
73 | echo |
74 |
|
75 | find . -name "*.c" -print0 | while read -d $'\0' file |
76 | do |
77 | warn_lite "Executing gcc --syntax-only $file" |
78 | $CC -std=c11 --syntax-only -pedantic -Wall -Wextra -I src $file |
79 | echo |
80 | done |
81 |
|
82 | success "Finished" |
83 | } |
84 |
|
85 | performance() { |
86 | warn "Running performance test" |
87 | echo |
88 |
|
89 | warn_lite "Compiling and running performance tests" |
90 | handle tests/performance.py |
91 | echo |
92 |
|
93 | success "Finished" |
94 | } |
95 |
|
96 | memory() { |
97 | warn "Running memory leak test" |
98 | echo |
99 |
|
100 | warn_lite "Compiling" |
101 | handle "$CC -std=c11 -pedantic -Wall -Wextra -Werror -o bin/c-memory -I src tests/header_memory.c" |
102 | echo |
103 |
|
104 | warn_lite "Running" |
105 | handle bin/c-memory |
106 | echo |
107 |
|
108 | success "Finished" |
109 | } |
110 |
|
111 | clean() { |
112 | warn "Cleaning" |
113 | echo |
114 | rm -r bin/ |
115 | } |
116 |
|
117 | for test in "$@" |
118 | do |
119 | $test |
120 | done |
121 |
|
122 | echo -e "finished: ${SECONDS} seconds" |
123 |
|