test: improve test script to run from anywhere + stricter exit on error

This commit is contained in:
kevinnls
2021-04-03 16:29:00 +05:30
parent 774b2a39b2
commit 7007d59718

View File

@@ -13,7 +13,8 @@ project_name='stdouterr'
project_version='v0.1.0-beta' project_version='v0.1.0-beta'
project_lang='C' project_lang='C'
project_root="$( cd .. ; pwd )" script_dir="$(realpath -e $(dirname "${0}") 2>/dev/null)"
project_root=${script_dir%/*} # remove everything after the final `/`
test_dir="${project_root}/dev/tests.d" test_dir="${project_root}/dev/tests.d"
[[ ! -d "${test_dir}" ]] && mkdir -p "${test_dir}" [[ ! -d "${test_dir}" ]] && mkdir -p "${test_dir}"
@@ -104,9 +105,15 @@ test(){
echo "=== end of test ===" echo "=== end of test ==="
} }
check_compilers \ if check_compilers; then
&& compile \ if compile; then
&& echo $? \ if test "$@"; then
&& test "$@" \ echo "completed with exit code $?"
|| exit 1 fi
fi
else
exit_code=$?
>>2 echo "some error occurred"
exit "${exit_code}"
fi