Make e2e treat args as tests-name regexes

This commit is contained in:
Tim Hockin 2022-02-24 09:04:24 -08:00
parent ad3955c0fa
commit 5707870ecc
1 changed files with 32 additions and 14 deletions

View File

@ -1827,35 +1827,53 @@ function list_tests() {
}
# Figure out which, if any, tests to run.
tests=($(list_tests))
all_tests=($(list_tests))
tests_to_run=()
function print_tests() {
echo "available tests:"
for t in "${tests[@]}"; do
for t in "${all_tests[@]}"; do
echo " $t"
done
}
for t; do
# Validate and accumulate tests to run if args are specified.
for arg; do
# Use -? to list known tests.
if [[ "${t}" == "-?" ]]; then
if [[ "${arg}" == "-?" ]]; then
print_tests
exit 0
fi
# Make sure we know this test.
if [[ " ${tests[*]} " =~ " ${t} " ]]; then
continue
if [[ "${arg}" =~ ^- ]]; then
echo "ERROR: unknown flag '${arg}'"
exit 1
fi
# Not a known test or flag.
echo "ERROR: unknown test or flag: '${t}'"
echo
print_tests
exit 1
# Make sure each non-flag arg matches at least one test.
nmatches=0
for t in "${all_tests[@]}"; do
if [[ "${t}" =~ ${arg} ]]; then
nmatches=$((nmatches+1))
# Don't run tests twice, just keep the first match.
if [[ " ${tests_to_run[*]} " =~ " ${t} " ]]; then
continue
fi
tests_to_run+=("${t}")
continue
fi
done
if [[ ${nmatches} == 0 ]]; then
echo "ERROR: no tests match pattern '${arg}'"
echo
print_tests
exit 1
fi
tests_to_run+=("${matches[@]}")
done
set -- "${tests_to_run[@]}"
# If no tests specified, run them all.
# If no tests were specified, run them all.
if [[ "$#" == 0 ]]; then
set -- "${tests[@]}"
set -- "${all_tests[@]}"
fi
# Build it