diff --git a/test-wheel.bash b/test-wheel.bash index 03dd98e..cba84a0 100755 --- a/test-wheel.bash +++ b/test-wheel.bash @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" . "$my_dir/python.bash" @@ -13,13 +15,30 @@ pip install pytest cleanup=true trap ' - if [[ -n $(jobs -p) ]]; then - echo "→ Killing $(jobs -p)" - kill $(jobs -p) - fi + failed_pids=() + for pid in $(jobs -p); do + if kill -0 $pid >/dev/null 2>&1; then + # Background process is still running - good. + kill $pid + else + exit_status=$? + if [[ $exit_status -eq 0 ]]; then + echo "Background task $pid already exited with zero status." + else + echo "Background task $pid exited with nonzero status ($exit_status)." + failed_pids+=("$pid") + fi + fi + done + if [[ "$cleanup" == "true" ]]; then echo "→ Removing $venv"; rm -rf "$venv" fi + + if [[ ${#failed_pids[@]} -gt 0 ]]; then + echo "The following background processes exited with nonzero status: ${failed_pids[@]}" + exit 1 + fi ' EXIT while [[ $# -gt 0 ]]; do @@ -31,14 +50,15 @@ while [[ $# -gt 0 ]]; do shift ;; -b|--background) - echo "→ Launching Background Task $2 ..." + echo "→ Launching background task: $2" $2 & + echo "... started with PID: $!" sleep 5 shift shift ;; -f|--foreground) - echo "→ Starting $2 ..." + echo "→ Starting foreground task: $2" $2 shift shift @@ -51,5 +71,3 @@ while [[ $# -gt 0 ]]; do ;; esac done - -exit 0