Compare commits

...

3 Commits

Author SHA1 Message Date
Tomáš Kléger
fe80bfc2fe ci: Add CI/CD script 2025-10-07 14:44:05 +02:00
Tomáš Kléger
16b8c78731 test: Add testing script 2025-10-07 14:42:59 +02:00
Tomáš Kléger
73cc39c07f git: Update gitignore as preparation for new Makefiles 2025-10-07 14:34:45 +02:00
3 changed files with 94 additions and 0 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
a.out
main
debug

10
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,10 @@
image: ${CI_REGISTRY}/ict/images/alpine/ci:latest
before_script:
apk add build-base bash
validate_code:
stage: test
script:
- chmod +x ./test/main.sh
- ./test/main.sh

82
test/main.sh Executable file
View File

@ -0,0 +1,82 @@
#!/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