Skip to content

Instantly share code, notes, and snippets.

@aprell
Created August 26, 2019 12:44
Show Gist options
  • Select an option

  • Save aprell/6015d91edf2d97fb76d3f5913e2669f6 to your computer and use it in GitHub Desktop.

Select an option

Save aprell/6015d91edf2d97fb76d3f5913e2669f6 to your computer and use it in GitHub Desktop.
A simple test runner
#!/usr/bin/env bash
# ShellChecked
set -eu
set -o pipefail
usage=$(cat <<EOF
Usage: $(basename "$0") test.input [repetitions]
If not specified, repetitions is set to 10.
EOF
)
if [ "$#" -lt 1 ]; then
echo "$usage"
exit 0
fi
# Optional argument
# Default is ten repetitions for each benchmark
repetitions=${2:-10}
RESET="\e[0m"
BOLD="\e[1m"
FAIL="\e[31m"
PASS="\e[32m"
print_success() {
echo -ne "$BOLD$PASS \u2714$RESET"
}
print_failure() {
echo -ne "$BOLD$FAIL \u2718$RESET"
}
testrun() {
local prog=$1
local success=true
shift
echo -n "$prog $*: "
for _ in $(seq 1 "$repetitions"); do
echo -n "."
if ! "$prog" "$@" > /dev/null #2>&1
then
success=false
break
fi
done
if [ "$success" = true ]; then
print_success
else
print_failure
fi
echo
}
while read -r line; do
# Force word splitting of line
testrun $line
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment