Created
December 11, 2018 19:19
-
-
Save maximaximal/e3c27708d99679971362b0c09f79e301 to your computer and use it in GitHub Desktop.
Test Script with specified Inputs and Outputs. License. GPLv2 or later.
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
#! /usr/bin/env bash | |
# This test script tries all inputs and compares them with | |
# their respective outputs. Supply it with | |
# the name of the executable. | |
name=$1 | |
# Color Constants | |
SUCCESS_COLOR='\033[0;32m' | |
ERROR_COLOR='\033[0;31m' | |
NO_COLOR='\033[0m' | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | |
if [ "$#" -ne 1 ]; then | |
echo "Must supply path to minesweeper executable!" | |
exit | |
fi | |
if [[ ! -x "$name" ]]; then | |
echo "The file must be the executable!" | |
exit | |
fi | |
echo "Running tests for binary in \"$name\"." | |
echo "Path of tests: \"$DIR\"" | |
for file in $DIR/input/*.txt; do | |
testname="${file##*/}" | |
outputname="${testname/input/output}" | |
expected=$(cat $DIR/output/$outputname) | |
result=$($name $file) | |
(diff <(echo "$result") <(echo "$expected") && printf "${SUCCESS_COLOR}Test in $file ran successful! $NO_COLOR \n") || printf "${ERROR_COLOR}Test in $file failed! $NO_COLOR\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment