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] [parser] [lint] [performance] [memory] [clean]" |
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 | mkdir -p bin |
46 | handle "gcc -std=c11 -pedantic -Wall -Wextra -Werror -o bin/c -I src tests/header_unit.c tests/header_unit_2.c" |
47 | echo |
48 |
|
49 | warn_lite "Running C header unit test" |
50 | handle bin/c |
51 | echo |
52 |
|
53 | success "Finished" |
54 | } |
55 |
|
56 | parser() { |
57 | warn "Compiling parser" |
58 | echo |
59 |
|
60 | warn_lite "Running compiler" |
61 | mkdir -p bin |
62 | FILES=$(find src/lnm/*.c) |
63 | handle "gcc -std=c11 -pedantic -Wall -Wextra -Werror -o bin/parser -I src $FILES -lncurses" |
64 | echo |
65 |
|
66 | success "Finished" |
67 | } |
68 |
|
69 | lint() { |
70 | warn "Running lint test" |
71 | echo |
72 |
|
73 | find . -name "*.c" -print0 | while read -d $'\0' file |
74 | do |
75 | warn_lite "Executing gcc --syntax-only $file" |
76 | handle "gcc -std=c11 --syntax-only -pedantic -Wall -Wextra -Werror -I src $file" |
77 | echo |
78 | done |
79 |
|
80 | success "Finished" |
81 | } |
82 |
|
83 | performance() { |
84 | warn "Running performance test" |
85 | echo |
86 |
|
87 | warn_lite "Compiling and running performance tests" |
88 | handle tests/performance.py |
89 | echo |
90 |
|
91 | success "Finished" |
92 | } |
93 |
|
94 | memory() { |
95 | warn "Running memory leak test" |
96 | echo |
97 |
|
98 | warn_lite "Compiling" |
99 | handle "gcc -std=c11 -pedantic -Wall -Wextra -Werror -o bin/c-memory -I src tests/header_memory.c" |
100 | echo |
101 |
|
102 | warn_lite "Running" |
103 | handle bin/c-memory |
104 | echo |
105 |
|
106 | success "Finished" |
107 | } |
108 |
|
109 | clean() { |
110 | warn "Cleaning" |
111 | echo |
112 | rm -r bin/ |
113 | } |
114 |
|
115 | for test in "$@" |
116 | do |
117 | $test |
118 | done |
119 |
|
120 | echo -e "finished: ${SECONDS} seconds" |
121 |
|