Skip to content

Commit 098b04f

Browse files
committed
test(e2e/47): drop bash-4 mapfile for macOS bash 3.2 compat
Apple ships GPLv2-era bash 3.2 on macOS, which has no `mapfile` / `readarray`. The previous round failed on ci-macos with: line 31: mapfile: command not found FAIL: 47_cdb_prebuilt_module_path_abs.sh (exit 127) Replace `mapfile -t vals < <(jq …)` with `jq … > tmp.txt` followed by a `while … read … done < tmp.txt`. Using input redirection (not a `|` pipeline) keeps the loop in the current shell so `fail=1` propagates; the temp file lives under $TMP and is cleaned up by the script's trap. Empty-list signal now uses `[[ ! -s "$TMP/vals.txt" ]]` instead of array length — same semantics, no bashism.
1 parent 43af760 commit 098b04f

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

tests/e2e/47_cdb_prebuilt_module_path_abs.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ command -v jq >/dev/null 2>&1 || {
2727
exit 0
2828
}
2929

30-
# jq returns each value JSON-unescaped (\\ → \, etc.).
31-
mapfile -t vals < <(
32-
jq -r '
33-
.[] | .arguments[]?
34-
| select(type == "string" and startswith("-fprebuilt-module-path="))
35-
| sub("^-fprebuilt-module-path="; "")
36-
' "$cdb"
37-
)
30+
# jq returns each value JSON-unescaped (\\ → \, etc.). Stage to a temp
31+
# file then read with a redirected while loop — bash 3.2 on macOS lacks
32+
# `mapfile`/`readarray`, and a `| while` pipeline puts the loop in a
33+
# subshell so `fail=1` would not propagate. Input redirection runs the
34+
# loop in the current shell, preserving the flag.
35+
jq -r '
36+
.[] | .arguments[]?
37+
| select(type == "string" and startswith("-fprebuilt-module-path="))
38+
| sub("^-fprebuilt-module-path="; "")
39+
' "$cdb" > "$TMP/vals.txt"
3840

39-
if [[ ${#vals[@]} -eq 0 ]]; then
41+
if [[ ! -s "$TMP/vals.txt" ]]; then
4042
# GCC's libstdc++ flow uses -fmodules / gcm.cache without the explicit
4143
# -fprebuilt-module-path flag (see bmi_traits.needsPrebuiltModulePath).
4244
# Nothing to assert in that mode.
@@ -45,11 +47,11 @@ if [[ ${#vals[@]} -eq 0 ]]; then
4547
fi
4648

4749
fail=0
48-
for v in "${vals[@]}"; do
49-
# `jq` on git-bash/Windows emits CRLF line endings; mapfile strips the LF
50-
# but leaves a trailing CR which then poisons every downstream string
51-
# comparison (basename ends with `\r`, regex matches go sideways).
50+
while IFS= read -r v; do
51+
# `jq` on git-bash/Windows emits CRLF; strip the trailing CR so basename
52+
# / regex comparisons don't trip over an invisible `\r`.
5253
v="${v%$'\r'}"
54+
[[ -z "$v" ]] && continue
5355
echo " checking: $v"
5456

5557
# Must NOT carry ninja-escape artefacts. The key signal is `$:` (drive
@@ -80,7 +82,7 @@ for v in "${vals[@]}"; do
8082
*) echo "FAIL: basename is not pcm.cache/gcm.cache: '${normalised##*/}'"
8183
fail=1 ;;
8284
esac
83-
done
85+
done < "$TMP/vals.txt"
8486

8587
[[ $fail -eq 0 ]] || exit 1
8688
echo "OK"

0 commit comments

Comments
 (0)