Skip to content

Instantly share code, notes, and snippets.

@maximaximal
Created December 11, 2018 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximaximal/e3c27708d99679971362b0c09f79e301 to your computer and use it in GitHub Desktop.
Save maximaximal/e3c27708d99679971362b0c09f79e301 to your computer and use it in GitHub Desktop.
Test Script with specified Inputs and Outputs. License. GPLv2 or later.
#! /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