slight improvements to tester, but arg parsing needs work
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
# run_test test_number
|
||||
# run_test testnumber
|
||||
run_test () {
|
||||
testfile=tests/$1.run
|
||||
# cat $testfile
|
||||
@@ -8,7 +8,7 @@ run_test () {
|
||||
return 0
|
||||
}
|
||||
|
||||
# check_test test_number out/err
|
||||
# check_test testnumber out/err
|
||||
check_test () {
|
||||
outdiff=$(diff tests/$1.$2 tests-out/$1.$2)
|
||||
outerr=$?
|
||||
@@ -23,20 +23,78 @@ check_test () {
|
||||
return 0
|
||||
}
|
||||
|
||||
# run_and_check testnumber printerror
|
||||
# testnumber: the test to run and check
|
||||
# printerrer: if 1, print an error if test does not exist
|
||||
run_and_check () {
|
||||
if [[ ! -f tests/$1.run ]]; then
|
||||
if (( $2 == 1 )); then
|
||||
echo "test $1 does not exist" >&2; exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
run_test $1
|
||||
check_test $1 out
|
||||
check_test $1 err
|
||||
builtin echo -e "\e[32mtest $1: passed\e[0m"
|
||||
return 0
|
||||
}
|
||||
|
||||
# usage: call when args not parsed, or when help needed
|
||||
usage () {
|
||||
echo "usage: run-tests.sh [-h] [-v] [-t test]"
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# main program
|
||||
#
|
||||
verbose=0
|
||||
specific=""
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-v)
|
||||
verbose=1
|
||||
;;
|
||||
-t)
|
||||
shift;
|
||||
if (( $# == 0 )); then
|
||||
usage
|
||||
echo "-t needs a specific test number" >&2; exit 1
|
||||
fi
|
||||
specific=$1
|
||||
number='^[0-9]+$'
|
||||
if ! [[ $specific =~ $number ]]; then
|
||||
usage
|
||||
echo "-t must be followed by a number" >&2; exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
if (( $# == 0 )); then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ! -d tests-out ]]; then
|
||||
mkdir tests-out
|
||||
fi
|
||||
|
||||
(( testnum = 1 ))
|
||||
# run just one test
|
||||
if [[ $specific != "" ]]; then
|
||||
run_and_check $specific 1
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# run all tests
|
||||
(( testnum = 1 ))
|
||||
while true; do
|
||||
if [[ ! -f tests/$testnum.run ]]; then
|
||||
exit 0
|
||||
fi
|
||||
run_test $testnum
|
||||
check_test $testnum out
|
||||
check_test $testnum err
|
||||
builtin echo -e "\e[32mtest $testnum: passed\e[0m"
|
||||
run_and_check $testnum 0
|
||||
(( testnum = $testnum + 1 ))
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user