Skip to content

Commit

Permalink
cmdlineTests.sh: Rewrite test selection to use find
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Jun 19, 2023
1 parent 381b610 commit 4752b31
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ source "${REPO_ROOT}/scripts/common_cmdline.sh"
pushd "${REPO_ROOT}/test/cmdlineTests" > /dev/null
autoupdate=false
no_smt=false
declare -a selected_tests
declare -a patterns_with_no_matches
declare -a included_test_patterns
while [[ $# -gt 0 ]]
do
case "$1" in
Expand All @@ -56,30 +55,35 @@ do
shift
;;
*)
matching_tests=$(find . -mindepth 1 -maxdepth 1 -type d -name "$1" | cut -c 3- | LC_COLLATE=C sort)

if [[ $matching_tests == "" ]]
then
patterns_with_no_matches+=("$1")
printWarning "No tests matching pattern '$1' found."
else
# shellcheck disable=SC2206 # We do not support test names containing spaces.
selected_tests+=($matching_tests)
fi

included_test_patterns+=("$1")
shift
;;
esac
done

if (( ${#selected_tests[@]} == 0 && ${#patterns_with_no_matches[@]} == 0 ))
(( ${#included_test_patterns[@]} > 0 )) || included_test_patterns+=('*')

test_name_filter=('(' -name "${included_test_patterns[0]}")
for pattern in "${included_test_patterns[@]:1}"
do
test_name_filter+=(-or -name "$pattern")
done
test_name_filter+=(')')

# NOTE: We want leading symbols in names to affect the sort order but without
# LC_COLLATE=C sort seems to ignore them.
# shellcheck disable=SC2207 # We do not support test names containing spaces.
selected_tests=($(find . -mindepth 1 -maxdepth 1 -type d "${test_name_filter[@]}" | cut -c 3- | LC_COLLATE=C sort))

if (( ${#selected_tests[@]} == 0 ))
then
# NOTE: We want leading symbols in names to affect the sort order but without
# LC_COLLATE=C sort seems to ignore them.
all_tests=$(echo * | tr '[:space:]' '\n' | LC_COLLATE=C sort)
# shellcheck disable=SC2206 # We do not support test names containing spaces.
selected_tests=($all_tests)
printWarning "The pattern '${test_name_filter[*]}' did not match any tests."
exit 0;
else
test_count=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)
printLog "Selected ${#selected_tests[@]} out of ${test_count} tests."
fi

popd > /dev/null

case "$OSTYPE" in
Expand Down

0 comments on commit 4752b31

Please sign in to comment.