#!/usr/bin/env bash success() { echo -e "\033[92m\033[1m\033[7m${@}\033[0m" } success_lite() { echo -e "\033[92m${@}\033[0m" } error() { echo -e "\033[91m\033[7m\033[1m${@}\033[0m" } warn() { echo -e "\033[93m\033[1m\033[7m${@}\033[0m" } warn_lite() { echo -e "\033[93m${@}\033[0m" } handle() { echo $1 $1 if [ $? -ne 0 ] then error "Error in test. Exiting..." exit 1 else success_lite "Success in test." fi } help() { echo "Usage: ./test [help] [c_unit] [performance] [lint]" } c_unit() { warn "Running C unit test chain" echo # Compile C unit tests warn_lite "Making C header unit test" mkdir -p bin handle "gcc -pedantic -Wall -Wextra -Werror -o bin/c -I src/c tests/header_unit.c tests/header_unit_2.c" echo warn_lite "Running C header unit test" handle bin/c echo success "Finished" } lint() { warn "Running lint test" echo find . -name "*.c" -print0 | while read -d $'\0' file do warn_lite "Executing gcc --syntax-only $file" handle "gcc --syntax-only -pedantic -Wall -Wextra -Werror -I src/c $file" echo done success "Finished" } performance() { warn "Running performance test" echo warn_lite "Compiling and getting file sizes" handle tests/performance.py echo success "Finished" } for test in "$@" do $test done echo -e "finished: ${SECONDS} seconds"