#!/bin/bash CC_COMMAND='g++ -Wall -Wextra -Werror -pedantic -D__PROGTEST__' RED="\e[31m" GREEN="\e[32m" YELLOW="\e[33m" RESET="\e[0m" EXIT_STATUS=0 _log() { # 0 => Okay / Green # 1 => Warn / Yellow # 2 => Fail / Red local log_level="$1" local log_message="$2" local log_color="" local log_level_name="" case "$log_level" in 0) log_color="$GREEN" log_level_name="OKAY" ;; 1) log_color="$YELLOW" log_level_name="WARN" ;; 2) log_color="$RED" log_level_name="FAIL" ;; esac printf "[${log_color}${log_level_name}${RESET}] %s\n" "$log_message" } for dir in homework-* exercise-*; do if ! cd "$dir" > /dev/null; then _log 2 "Couldn't cd into $dir" cd .. continue fi if [[ ! -f ./main.c ]]; then _log 1 "No main.c file in $dir" cd .. continue fi if ! eval "$CC_COMMAND main.c"; then _log 2 "Failed to compile code in $dir" cd .. continue fi failed_inputs=0 for input in test_data/*_in.txt; do input_file=${input//*\/} test_case_number=${input_file%%_in.txt} command_output="$(diff <(./a.out < "test_data/${test_case_number}_in.txt") "test_data/${test_case_number}_out.txt")" if [[ ! "$?" ]]; then EXIT_STATUS=1 ((failed_inputs++)) _log 2 "$dir (#$test_case_number)" echo "$command_output" fi done if ((failed_inputs == 0)); then _log 0 "$dir" fi cd .. > /dev/null done exit $EXIT_STATUS