test: Polish test script to work on single project or all at once
This commit is contained in:
parent
9adde41415
commit
9755abd043
52
test/main.sh
52
test/main.sh
@ -1,12 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/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"
|
RED="\e[31m"
|
||||||
GREEN="\e[32m"
|
GREEN="\e[32m"
|
||||||
YELLOW="\e[33m"
|
YELLOW="\e[33m"
|
||||||
RESET="\e[0m"
|
RESET="\e[0m"
|
||||||
|
|
||||||
|
if [[ "$1" =~ --all|-a ]]; then
|
||||||
|
check_all=true
|
||||||
|
else
|
||||||
|
check_all=false
|
||||||
|
fi
|
||||||
|
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
_log() {
|
_log() {
|
||||||
@ -36,23 +42,30 @@ _log() {
|
|||||||
printf "[${log_color}${log_level_name}${RESET}] %s\n" "$log_message"
|
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
|
if ! cd "$dir" > /dev/null; then
|
||||||
_log 2 "Couldn't cd into $dir"
|
_log 2 "Couldn't cd into $dir"
|
||||||
cd ..
|
return 1
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local dir_name="${PWD##*/}"
|
||||||
|
|
||||||
if [[ ! -f ./main.c ]]; then
|
if [[ ! -f ./main.c ]]; then
|
||||||
_log 1 "No main.c file in $dir"
|
_log 1 "No main.c file in $dir_name"
|
||||||
cd ..
|
return 1
|
||||||
continue
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d ./test_data ]]; then
|
||||||
|
_log 1 "No test_data directory in $dir_name"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! eval "$CC_COMMAND main.c"; then
|
if ! eval "$CC_COMMAND main.c"; then
|
||||||
_log 2 "Failed to compile code in $dir"
|
_log 2 "Failed to compile code in $dir_name"
|
||||||
cd ..
|
EXIT_STATUS=1
|
||||||
continue
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
failed_inputs=0
|
failed_inputs=0
|
||||||
@ -61,22 +74,25 @@ for dir in homework-* exercise-*; do
|
|||||||
input_file=${input//*\/}
|
input_file=${input//*\/}
|
||||||
test_case_number=${input_file%%_in.txt}
|
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 ! diff --color <(./a.out < "test_data/${test_case_number}_in.txt") "test_data/${test_case_number}_out.txt"; then
|
||||||
|
|
||||||
if [[ ! "$?" ]]; then
|
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
((failed_inputs++))
|
((failed_inputs++))
|
||||||
_log 2 "$dir (#$test_case_number)"
|
_log 2 "$dir (#$test_case_number)"
|
||||||
echo "$command_output"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if ((failed_inputs == 0)); then
|
if ((failed_inputs == 0)); then
|
||||||
_log 0 "$dir"
|
_log 0 "$dir_name"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cd .. > /dev/null
|
if ! $check_all; then
|
||||||
done
|
_test_dir .
|
||||||
|
else
|
||||||
|
for dir in homework-* exercise-*; do
|
||||||
|
_test_dir "$dir"
|
||||||
|
cd .. > /dev/null
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
exit $EXIT_STATUS
|
exit $EXIT_STATUS
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user