1010# SHOW_EVERY : print progress/iteration header every N iterations (default: 100, 1 = every run, <=0 = disabled)
1111# LOG_STDERR : set to 1 to enable verbose stderr logging (HLS_TEST_LOG_STDERR & HLS_TEST_HARNESS_STDERR) (default: 1)
1212# NO_BUILD_ONCE : set to non-empty to skip the initial cabal build step
13+ # RUN_MODE : choose 'build' (build once and exit), 'run' (skip upfront build and just run), or 'both' (default)
1314#
1415# Test selection:
1516# TEST_PATTERNS : comma-separated list of entries to run each iteration.
@@ -37,6 +38,7 @@ MAX_ITER="${MAX_ITER:-}"
3738SLEEP_SECS=" ${SLEEP_SECS:- 0} "
3839SHOW_EVERY=" ${SHOW_EVERY:- 1} "
3940LOG_STDERR=" ${LOG_STDERR:- 1} "
41+ RUN_MODE=" ${RUN_MODE:- both} " # build | run | both
4042
4143# Allow providing a positional max iteration: ./open-close-loop.sh 50
4244if [[ $# -ge 1 && -z " ${MAX_ITER} " ]]; then
@@ -96,10 +98,11 @@ if [[ ${#items[@]} -eq 0 ]]; then
9698 exit 2
9799fi
98100
99- # Build required test binaries once upfront (unless NO_BUILD_ONCE is set)
100- if [[ -z " ${NO_BUILD_ONCE :- } " ]] ; then
101- # collect unique BIN names
101+ # Helper to build required test binaries once
102+ build_required_bins_once () {
103+ # collect unique BIN names from global 'items'
102104 declare -a bins_to_build=()
105+ local it bin seen b
103106 for it in " ${items[@]} " ; do
104107 bin=" ${it%%::* } " ; seen=0
105108 if (( ${# bins_to_build[@]} > 0 )) ; then
@@ -110,11 +113,40 @@ if [[ -z "${NO_BUILD_ONCE:-}" ]]; then
110113 if (( ${# bins_to_build[@]} > 0 )) ; then
111114 echo " [loop] Building test targets once upfront: ${bins_to_build[*]} " >&2
112115 if ! cabal build " ${bins_to_build[@]} " >&2 ; then
113- echo " [loop][error] Build failed. Cannot proceed with tests. " >&2
114- exit 2
116+ echo " [loop][error] Build failed." >&2
117+ return 2
115118 fi
116- echo " [loop] Build succeeded. Proceeding with tests. " >&2
119+ echo " [loop] Build succeeded." >&2
117120 fi
121+ return 0
122+ }
123+
124+ # Honor RUN_MODE before any build/run
125+ case " ${RUN_MODE} " in
126+ build)
127+ if ! build_required_bins_once; then exit 2; fi
128+ echo " [loop] RUN_MODE=build completed. Exiting without running tests." >&2
129+ exit 0
130+ ;;
131+ run)
132+ echo " [loop] RUN_MODE=run: skipping upfront build, proceeding to run loop." >&2
133+ ;;
134+ both)
135+ : # default behavior below
136+ ;;
137+ * )
138+ echo " [loop][error] Invalid RUN_MODE='${RUN_MODE} '. Use one of: build | run | both." >&2
139+ exit 2
140+ ;;
141+ esac
142+
143+ # Build required test binaries once upfront (unless NO_BUILD_ONCE is set or RUN_MODE=run)
144+ if [[ -z " ${NO_BUILD_ONCE:- } " && " ${RUN_MODE} " != " run" ]]; then
145+ if ! build_required_bins_once; then
146+ echo " [loop][error] Cannot proceed with tests due to build failure." >&2
147+ exit 2
148+ fi
149+ echo " [loop] Proceeding with tests." >&2
118150fi
119151
120152# Resolve binary path by name (cache results)
0 commit comments