From 7007d59718f8246a2410dd31f2473bab8b7c2b5f Mon Sep 17 00:00:00 2001 From: kevinnls <57634663+kevinnls@users.noreply.github.com> Date: Sat, 3 Apr 2021 16:29:00 +0530 Subject: [PATCH] test: improve test script to run from anywhere + stricter exit on error --- dev/test | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/dev/test b/dev/test index 3819d89..c86ebf2 100755 --- a/dev/test +++ b/dev/test @@ -13,7 +13,8 @@ project_name='stdouterr' project_version='v0.1.0-beta' 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" [[ ! -d "${test_dir}" ]] && mkdir -p "${test_dir}" @@ -104,9 +105,15 @@ test(){ echo "=== end of test ===" } -check_compilers \ - && compile \ - && echo $? \ - && test "$@" \ - || exit 1 +if check_compilers; then + if compile; then + if test "$@"; then + echo "completed with exit code $?" + fi + fi +else + exit_code=$? + >>2 echo "some error occurred" + exit "${exit_code}" +fi