From 5707870ecc4e9ba657002d2487c39c3d7be2b60a Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 24 Feb 2022 09:04:24 -0800 Subject: [PATCH] Make e2e treat args as tests-name regexes --- test_e2e.sh | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index ac93739..4c5ea5f 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -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