diff --git a/tests/shared_test_functions.sh b/tests/shared_test_functions.sh index ff4fa310..db06204a 100644 --- a/tests/shared_test_functions.sh +++ b/tests/shared_test_functions.sh @@ -26,6 +26,8 @@ # Set up the below variables. # - expected_exitcode(expected, actual): # Check if ${expected} matches ${actual}. +# - get_filelist (pattern): return a sorted list of files corresponding to +# ${pattern}, separated by newlines. # - run_scenarios(): # Run scenarios in the test directory. # @@ -205,6 +207,29 @@ expected_exitcode() { fi } +## get_filelist (pattern): +# Return a sorted list of files corresponding to ${pattern}, separated by +# newlines. +get_filelist() { + _get_filelist_pattern=$1 + + # Separate the pattern into directory and basename. + _get_filelist_dir=$(dirname "${_get_filelist_pattern}") + _get_filelist_base=$(basename "${_get_filelist_pattern}") + + # Find all files matching the pattern. Don't complain if the + # directory does not exist (i.e. checking for non-existent valgrind + # logfiles). + _get_filelist_unsorted=$(find "${_get_filelist_dir}" \ + -name "${_get_filelist_base}" -prune -print 2>/dev/null) + + # Sort the list. + _get_filelist_filelist=$(printf "%s" "${_get_filelist_unsorted}" | sort) + + # Return the sorted list. + printf "%s" "${_get_filelist_filelist}" +} + ## notify_success_or_fail (log_basename, val_log_basename): # Examine all "exit code" files beginning with ${log_basename} and # print "SUCCESS!", "FAILED!", "SKIP!", or "PARTIAL SUCCESS / SKIP!" @@ -217,7 +242,7 @@ notify_success_or_fail() { val_log_basename=$2 # Bail if there's no exitfiles. - exitfiles=$(ls "${log_basename}"-*.exit) || true + exitfiles=$(set -o noglob; get_filelist "${log_basename}"-*.exit) if [ -z "${exitfiles}" ]; then echo "FAILED" 1>&2 s_retval=1 @@ -229,7 +254,7 @@ notify_success_or_fail() { skip_exitfiles=0 # Check each exitfile. - for exitfile in $(echo "${exitfiles}" | sort); do + for exitfile in ${exitfiles}; do ret=$(cat "${exitfile}") total_exitfiles=$(( total_exitfiles + 1 )) if [ "${ret}" -lt 0 ]; then diff --git a/tests/shared_valgrind_functions.sh b/tests/shared_valgrind_functions.sh index e4e9033b..f73b9d3f 100644 --- a/tests/shared_valgrind_functions.sh +++ b/tests/shared_valgrind_functions.sh @@ -327,7 +327,7 @@ valgrind_check_basenames() { val_basename=$(valgrind_get_basename "${exitfile}") # Get list of files to check. (Yes, the star goes outside the quotes.) - logfiles=$(ls "${val_basename}"* 2>/dev/null) + logfiles=$(set -o noglob; get_filelist "${val_basename}"*) num_logfiles=$(echo "${logfiles}" | wc -w) # Bail if we don't have any valgrind logfiles to check.