#!/bin/bash

shells=(bash zsh)

cd "${0%/*}/tests"

if [ ! -r shunit2 ]; then
  curl https://raw.githubusercontent.com/kward/shunit2/v2.1.8/shunit2 -O
fi

typeset -a testing_shells

for shell in "${shells[@]}"; do
  if command -v "$shell" >/dev/null; then
    testing_shells+=("$shell")
  else
    printf "Cannot find shell '%s', skipping tests\n" "$shell" >&2
  fi
done

fail=0

for test_file in ./test_*.sh; do
  for shell in "${testing_shells[@]}"; do
    printf "\nRunning shell '%s' with test '%s'\n" "$shell" "$test_file"
    "$shell" "$test_file" || fail=$?
  done
done

exit "$fail"

#!/bin/bash

if [[ -n ${1+x} ]]; then
  shells=("$@")
else
  shells=(bash zsh)
fi

cd "${0%/*}/tests"

if [ ! -r shunit2 ]; then
  curl https://raw.githubusercontent.com/kward/shunit2/v2.1.8/shunit2 -O
fi

typeset -a testing_shells

for shell in "${shells[@]}"; do
  if command -v "$shell" >/dev/null; then
    testing_shells+=("$shell")
    printf 'shell "%s": version "%s"\n' "$shell" "$("$shell" --version)"
  else
    printf "Cannot find shell '%s', skipping tests\n" "$shell" >&2
  fi
done

typeset -i fail=0

for test_file in ./test_*.sh; do
  for shell in "${testing_shells[@]}"; do
    printf "\nRunning shell '%s' with test '%s'\n" "$shell" "$test_file"
    "$shell" "$test_file" || fail+=1
  done
done

exit "$fail"

Modify test script to accept shells as arguments
Modify test script to accept shells as arguments

While not useful in CI scripts, this lets a developer run the tests
against their own shells if they wish.

I tested this with:
bash 3.2.0(1)-release (x86_64-unknown-linux-gnu)
bash 4.0.28(2)-release (x86_64-unknown-linux-gnu)
bash 4.2.53(1)-release (x86_64-unknown-linux-gnu)
bash 4.4.0(1)-release (x86_64-unknown-linux-gnu)
bash 4.4.19(1)-release (x86_64-unknown-linux-gnu)
bash 5.0.17(1)-release (x86_64-pc-linux-gnu)
bash 5.1.0(1)-release (x86_64-pc-linux-gnu)
zsh 5.0.8 (x86_64-unknown-linux-gnu)
zsh 5.1.1 (x86_64-unknown-linux-gnu)
zsh 5.2 (x86_64-unknown-linux-gnu)
zsh 5.3.1 (x86_64-unknown-linux-gnu)
zsh 5.4.2 (x86_64-unknown-linux-gnu)
zsh 5.5.1 (x86_64-redhat-linux-gnu)
zsh 5.8 (x86_64-pc-linux-gnu)

I found a few bugs, fixed in the following commits.
