Last active
October 15, 2020 10:27
-
-
Save swimmwatch/c5ac95d757e9135c86e1948a6e9a0461 to your computer and use it in GitHub Desktop.
Simple lab checker for C/C++ programs that is being compiled from Make. Script reads test cases from `tests` directory and compares output from program with text after `out:` separator in test case file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- exit codes --- | |
TESTS_SUCCESS=0 | |
TESTS_FAILURE=1 | |
# --- END exit codes --- | |
# --- constants --- | |
FONT_COLOR_RED_START="\033[1;31m" | |
FONT_COLOR_RED_END="\033[0m" | |
FONT_COLOR_GREEN_START="\033[0;32m" | |
FONT_COLOR_GREEN_END="\033[0m" | |
FAILURE_CHAR="\u2717" | |
SUCCESS_CHAR="\u2713" | |
TESTCASES_DIR="./tests" | |
# --- END constants --- | |
printf "Run tests...\n" | |
for testcase_path in $(find $TESTCASES_DIR -name '*' -type f) | |
do | |
if ! diff <(make 1> /dev/null && ./program < $testcase_path) <(sed '1,/out:/d' $testcase_path); then | |
printf "${FONT_COLOR_RED_START}--> $testcase_path ${FAILURE_CHAR}${FONT_COLOR_RED_END}\n" 1>&2 | |
exit $TESTS_FAILURE | |
else | |
printf "${FONT_COLOR_GREEN_START} $testcase_path ${SUCCESS_CHAR}${FONT_COLOR_GREEN_END}\n" | |
fi | |
done | |
printf "${FONT_COLOR_GREEN_START}Tests passed!${FONT_COLOR_GREEN_END}\n" | |
exit $TESTS_SUCCESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment