From 9755abd043fc605c42e44d77f6aa30bf13824a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kl=C3=A9ger?= Date: Mon, 13 Oct 2025 19:02:29 +0200 Subject: [PATCH] test: Polish test script to work on single project or all at once --- test/main.sh | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/test/main.sh b/test/main.sh index 150d6bb..1088439 100755 --- a/test/main.sh +++ b/test/main.sh @@ -1,12 +1,18 @@ #!/bin/bash -CC_COMMAND='g++ -Wall -Wextra -Werror -pedantic -D__PROGTEST__' +CC_COMMAND='g++ -Wall -Wextra -Werror -pedantic -D__PROGTEST__ -Wdouble-promotion -Wfloat-conversion' RED="\e[31m" GREEN="\e[32m" YELLOW="\e[33m" RESET="\e[0m" +if [[ "$1" =~ --all|-a ]]; then + check_all=true +else + check_all=false +fi + EXIT_STATUS=0 _log() { @@ -36,23 +42,30 @@ _log() { printf "[${log_color}${log_level_name}${RESET}] %s\n" "$log_message" } -for dir in homework-* exercise-*; do +_test_dir() { + local dir="$1" + if ! cd "$dir" > /dev/null; then _log 2 "Couldn't cd into $dir" - cd .. - continue + return 1 fi + local dir_name="${PWD##*/}" + if [[ ! -f ./main.c ]]; then - _log 1 "No main.c file in $dir" - cd .. - continue + _log 1 "No main.c file in $dir_name" + return 1 + fi + + if [[ ! -d ./test_data ]]; then + _log 1 "No test_data directory in $dir_name" + return 1 fi if ! eval "$CC_COMMAND main.c"; then - _log 2 "Failed to compile code in $dir" - cd .. - continue + _log 2 "Failed to compile code in $dir_name" + EXIT_STATUS=1 + return 1 fi failed_inputs=0 @@ -61,22 +74,25 @@ for dir in homework-* exercise-*; 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 + if ! diff --color <(./a.out < "test_data/${test_case_number}_in.txt") "test_data/${test_case_number}_out.txt"; 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" + _log 0 "$dir_name" fi +} - cd .. > /dev/null -done +if ! $check_all; then + _test_dir . +else + for dir in homework-* exercise-*; do + _test_dir "$dir" + cd .. > /dev/null + done +fi exit $EXIT_STATUS