improve tests flags

This commit is contained in:
hugogogo
2026-05-14 21:33:44 +02:00
parent 31469af23f
commit 840f5bcfdf
3 changed files with 47 additions and 19 deletions

View File

@@ -30,16 +30,31 @@ RESET="\e[0m"
NAME="computor"
BINARY="./$NAME"
SKIP_REDUCED=true
SKIP_SOLUTION=true
if [[ ! -x "$BINARY" ]]; then
echo -e >&2 $B_RED"Error:$RESET binary $B_PURPLE'$BINARY'$RESET not found or not executable."
echo >&2 "Did you compile your C program?"
exit 1
fi
# flags
SKIP_REDUCED=false
SKIP_SOLUTION=false
RUN_ONLY=false
FLAGS="" # default empty
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--skip-reduced) SKIP_REDUCED=true ;;
--skip-solution) SKIP_SOLUTION=true ;;
--run-only) RUN_ONLY=true ;;
-b) FLAGS="$FLAGS -b" ;; # append -b to FLAGS
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# ----------------------------------------------------------------------
# TEST LOGIC
# ----------------------------------------------------------------------
@@ -50,10 +65,20 @@ run_test() {
local expected="$3"
local check_error="${4:-no_error}" # Default: false (compare output)
# If RUN_ONLY is true, skip all test logic and just run the binary
if [[ "$RUN_ONLY" == "true" ]]; then
printf $B_PURPLE"Running: '%s'$RESET\n" "$test_name"
printf "Input: '%s'\n" "$input"
printf "Output:\n"
printf "%s" "$input" | "$BINARY" $FLAGS 2>&1
printf "\n"
return
fi
printf $B_PURPLE"Test : '%s'$RESET - " "$test_name"
# Run the program and capture the output
out=$(printf "%s" "$input" | "$BINARY" 2>&1)
out=$(printf "%s" "$input" | "$BINARY" $FLAGS 2>&1)
exit_code=$?
# If SKIP_REDUCED is true, remove the "Reduced form" line from both output and expected