| 1 | #!/usr/bin/env bash | 
| 2 |  | 
| 3 | mkdir -p bin | 
| 4 |  | 
| 5 | py() { | 
| 6 | python3 $@ | 
| 7 | } | 
| 8 |  | 
| 9 | success() { | 
| 10 | echo -e "\033[92m\033[1m\033[7m${@}\033[0m" | 
| 11 | } | 
| 12 |  | 
| 13 | success_lite() { | 
| 14 | echo -e "\033[92m${@}\033[0m" | 
| 15 | } | 
| 16 |  | 
| 17 | error() { | 
| 18 | echo -e "\033[91m\033[7m\033[1m${@}\033[0m" | 
| 19 | } | 
| 20 |  | 
| 21 | warn() { | 
| 22 | echo -e "\033[93m\033[1m\033[7m${@}\033[0m" | 
| 23 | } | 
| 24 |  | 
| 25 | warn_lite() { | 
| 26 | echo -e "\033[93m${@}\033[0m" | 
| 27 | } | 
| 28 |  | 
| 29 | run() { | 
| 30 | warn_lite "python3 ${@}" | 
| 31 | py $@ | 
| 32 | code=$? | 
| 33 | if [ ${code} -ne 0 ] | 
| 34 | then | 
| 35 | error "Error in test '${@}'. Exiting..." | 
| 36 | exit ${code} | 
| 37 | else | 
| 38 | success_lite "Success in test '${@}'." | 
| 39 | fi | 
| 40 | echo | 
| 41 | } | 
| 42 |  | 
| 43 | compile_c() { | 
| 44 | warn_lite "gcc ${@}" | 
| 45 | gcc $@ | 
| 46 | code=$? | 
| 47 | if [ ${code} -ne 0 ] | 
| 48 | then | 
| 49 | error "Error in test '${@}'. Exiting..." | 
| 50 | exit ${code} | 
| 51 | else | 
| 52 | success_lite "Success in test '${@}'." | 
| 53 | fi | 
| 54 | echo | 
| 55 | warn_lite "bin/c" | 
| 56 | bin/c | 
| 57 | code=$? | 
| 58 | if [ ${code} -ne 0 ] | 
| 59 | then | 
| 60 | error "Error in test 'bin/c'. Exiting..." | 
| 61 | exit ${code} | 
| 62 | else | 
| 63 | success_lite "Success in test 'bin/c'." | 
| 64 | fi | 
| 65 | echo | 
| 66 | } | 
| 67 |  | 
| 68 | run_tests() { | 
| 69 | # Test prep (generate log files) | 
| 70 | warn "Undergoing test preparations" | 
| 71 | run ./tests/write.py ./bin/w1.lnm | 
| 72 | run ./tests/write_many.py ./bin/w2.lnm 1000 | 
| 73 | echo | 
| 74 |  | 
| 75 | # Unit tests | 
| 76 | warn "Beginning unit tests" | 
| 77 | compile_c ./tests/main.c -o ./bin/c -Wall -Wextra -Werror -pedantic -I"./src/c" | 
| 78 | run ./tests/unit_parserargs.py | 
| 79 | echo | 
| 80 |  | 
| 81 | success "Finished! Exiting with code 0" | 
| 82 | } | 
| 83 |  | 
| 84 | run_tests | 
| 85 |  | 
| 86 | echo -e "Time elapsed: ${SECONDS} second(s)" | 
| 87 |  |