#!/bin/bash exe_path=$1 tests_path=$2 if [[ -z "$exe_path" || -z "$tests_path" ]]; then echo "Usage: test.sh " exit 1 fi tests=0 passed=0 abort_testing() { echo -ne "\nšŸ›‘ Received SIGINT, testing aborted" finish_testing } finish_testing() { percentage=$(echo "($passed)*100/$tests" | bc) if [ $tests = $passed ]; then echo -ne "\nāœ…" else echo -ne "\nāŒ" fi echo -e " $passed of $tests ($percentage%) tests passed" if [ $tests = $passed ]; then exit 0 else exit 1 fi } trap abort_testing SIGINT for test_in in "$tests_path"/*.in; do output=$($exe_path < $test_in) test_out=$(basename -- "$test_in") testname="${test_out%.*}" test_out="$(dirname "$test_in")/$testname.out" echo -n "$testname: " ((tests++)) if [ "$(cat $test_out)" = "$output" ]; then echo "āœ… PASSED" ((passed++)) else echo "āŒ FAILED" fi done finish_testing