Skip to content

Commit

Permalink
fix some problems in testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxieee committed Mar 9, 2024
1 parent af59aee commit 63129a6
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions scripts/RUN_TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ while [[ $# -gt 0 ]]; do
usage
exit 0
;;
-*|--*)
-*)
echo "Error: unknown option $1!!"
usage
exit 1
Expand Down Expand Up @@ -127,7 +127,7 @@ for arg in "${POSITIONAL[@]}"; do
if [ -f "$arg" ]; then
TESTS+=("$arg")
elif [ -d "$arg" ]; then
for file in $(find $arg -regex ".*\.dof" -type f); do
for file in $(find "$arg" -regex ".*\.dof" -type f); do
if [ -f "$file" ]; then
TESTS+=("$file")
fi
Expand All @@ -143,7 +143,12 @@ done

ref-path() {
local TEST=$1
echo $(realpath --relative-to $(pwd) "$(dirname ${TEST})/../ref/$(basename ${TEST%.*}).log")
# use grealpath on macOS because realpath does not have a --relative-to option
if [ "$(uname)" == "Darwin" ]; then
grealpath --relative-to "$(pwd)" "$(dirname "${TEST}")/../ref/$(basename "${TEST%.*}").log"
else
realpath --relative-to "$(pwd)" "$(dirname "${TEST}")/../ref/$(basename "${TEST%.*}").log"
fi
}
export -f ref-path

Expand All @@ -154,16 +159,17 @@ dofile-result-same-with-ref() {
local SILENT=$3
local QSYN=$4
local DIFF=$5
local REF=$(ref-path $TEST)
local REF
REF=$(ref-path "$TEST")

DIFF_OUTPUT=$(OMP_WAIT_POLICY=passive $QSYN --no-version --qsynrc-path /dev/null --file $TEST 2>&1 | $DIFF - $REF 2>&1)
DIFF_OUTPUT=$(OMP_WAIT_POLICY=passive $QSYN --no-version --qsynrc-path /dev/null --file "$TEST" 2>&1 | $DIFF - "$REF" 2>&1)
if [ $? -eq 0 ]; then
if [[ $VERBOSE -eq 1 ]]; then
echo " $(pass-style '') $TEST"
return 0
fi
else
if [ ! -f $REF ]; then
if [ ! -f "$REF" ]; then
echo " $(unknown-style '?') $REF"
else
echo " $(fail-style '') $TEST"
Expand All @@ -183,15 +189,16 @@ update-dofile-ref() {
local VERBOSE=$2
local SILENT=$3
local QSYN=$4
local REF=$(ref-path $TEST)
local REF
REF=$(ref-path "$TEST")

# if the reference file does not exist, create it
if [[ ! -f $REF ]]; then
mkdir -p $(dirname $REF)
touch $REF
mkdir -p "$(dirname "$REF")"
touch "$REF"
fi

DIFF_OUTPUT=$(OMP_WAIT_POLICY=passive $QSYN --no-version --qsynrc-path /dev/null --file $TEST 2>&1 | diff $REF -)
DIFF_OUTPUT=$(OMP_WAIT_POLICY=passive $QSYN --no-version --qsynrc-path /dev/null --file "$TEST" 2>&1 | diff "$REF" -)

# update reference file if the output of qsyn is different from the reference
if [[ $? -eq 0 ]]; then
Expand All @@ -200,7 +207,7 @@ update-dofile-ref() {
return 0
fi
else
printf "%s\n" "$DIFF_OUTPUT" | patch -f $REF
printf "%s\n" "$DIFF_OUTPUT" | patch -f "$REF"
if [[ $? -eq 1 ]]; then
echo " $(fail-style !) $TEST"
return 0
Expand All @@ -223,9 +230,10 @@ if [[ "$ACTION" == 'diff' ]]; then

TESTS_COUNT=${#TESTS[@]}
if [ $FAIL_COUNT -eq 0 ]; then
echo "$(pass-style "Passed all $TESTS_COUNT tests.")"
pass-style "Passed all $TESTS_COUNT tests."
else
echo "$(fail-style "$FAIL_COUNT out of $TESTS_COUNT tests failed.")"

fail-style "$FAIL_COUNT out of $TESTS_COUNT tests failed."
fi
elif [[ "$ACTION" == 'update' ]]; then
echo "> Updating reference files..."
Expand All @@ -237,5 +245,5 @@ elif [[ "$ACTION" == 'update' ]]; then

TESTS_COUNT=${#TESTS[@]}

echo "$(pass-style "Updated $UPDATE_COUNT out of $TESTS_COUNT reference files.")"
fi
pass-style "Updated $UPDATE_COUNT out of $TESTS_COUNT reference files."
fi

0 comments on commit 63129a6

Please sign in to comment.