|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Regression test for run-tests.sh silently truncating recursive ** glob |
| 3 | +# buckets on Linux/macOS (quarto-cli-jho3). |
| 4 | +# |
| 5 | +# Runs the real run-tests.sh against a nested qmd fixture, with the deno |
| 6 | +# binary swapped for a recorder stub (via the DENO_DIR override run-tests.sh |
| 7 | +# already supports), and checks that a file nested two directories deep |
| 8 | +# under a `**` bucket still reaches the resolved test-file set. The |
| 9 | +# assertion re-expands any still-glob-shaped token itself (mirroring what |
| 10 | +# smoke-all.test.ts's expandGlobSync does), so it passes regardless of |
| 11 | +# whether the fix quotes the pattern through to deno or expands it in bash. |
| 12 | +set -uo pipefail |
| 13 | + |
| 14 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" |
| 15 | +REPO_ROOT="$(cd "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)" |
| 16 | + |
| 17 | +TMP="$(mktemp -d)" |
| 18 | +trap 'rm -rf "$TMP"' EXIT |
| 19 | + |
| 20 | +fail() { |
| 21 | + echo "FAIL: $1" |
| 22 | + exit 1 |
| 23 | +} |
| 24 | + |
| 25 | +# --- Isolated fake repo skeleton, just enough for run-tests.sh to run --- |
| 26 | +mkdir -p "$TMP/tests" |
| 27 | +mkdir -p "$TMP/package/scripts/common" |
| 28 | +mkdir -p "$TMP/package/dist/bin/tools/stub" |
| 29 | +mkdir -p "$TMP/src/resources" |
| 30 | + |
| 31 | +# Strip CR in case this checkout has core.autocrlf=true (Windows dev boxes); |
| 32 | +# CI checkouts on Linux/macOS never have CRLF here, this is a local-copy |
| 33 | +# normalization only, not part of the fix under test. |
| 34 | +tr -d '\r' < "$REPO_ROOT/tests/run-tests.sh" > "$TMP/tests/run-tests.sh" |
| 35 | +tr -d '\r' < "$REPO_ROOT/package/scripts/common/utils.sh" > "$TMP/package/scripts/common/utils.sh" |
| 36 | +chmod +x "$TMP/tests/run-tests.sh" |
| 37 | + |
| 38 | +RECORD_FILE="$TMP/recorded-argv.txt" |
| 39 | +cat > "$TMP/package/dist/bin/tools/stub/deno" <<'EOF' |
| 40 | +#!/usr/bin/env bash |
| 41 | +printf '%s\n' "$@" > "$RECORD_FILE" |
| 42 | +exit 0 |
| 43 | +EOF |
| 44 | +chmod +x "$TMP/package/dist/bin/tools/stub/deno" |
| 45 | + |
| 46 | +# --- Nested fixture: one .qmd at depth 1, one at depth 2 under qmd-files/ --- |
| 47 | +mkdir -p "$TMP/qmd-files/a/b" |
| 48 | +: > "$TMP/qmd-files/a/one.qmd" |
| 49 | +: > "$TMP/qmd-files/a/b/two.qmd" |
| 50 | + |
| 51 | +# --- Invoke the real script exactly as test-smokes.yml's bucket runner does --- |
| 52 | +( |
| 53 | + cd "$TMP/tests" || exit 1 |
| 54 | + export QUARTO_TESTS_NO_CONFIG=true |
| 55 | + export QUARTO_TESTS_FORCE_NO_VENV=true |
| 56 | + export DENO_DIR=stub |
| 57 | + export RECORD_FILE |
| 58 | + ./run-tests.sh "../qmd-files/**/*.qmd" |
| 59 | +) |
| 60 | + |
| 61 | +[ -f "$RECORD_FILE" ] || fail "deno stub was never invoked - run-tests.sh did not reach the final deno call" |
| 62 | + |
| 63 | +mapfile -t recorded < "$RECORD_FILE" |
| 64 | + |
| 65 | +dashdash_index=-1 |
| 66 | +for i in "${!recorded[@]}"; do |
| 67 | + if [ "${recorded[$i]}" = "--" ]; then |
| 68 | + dashdash_index=$i |
| 69 | + break |
| 70 | + fi |
| 71 | +done |
| 72 | +[ "$dashdash_index" -ge 0 ] || fail "no isolated '--' token in deno argv (got: ${recorded[*]})" |
| 73 | + |
| 74 | +# Resolve the file tokens after '--' into an actual file set, expanding any |
| 75 | +# token that still looks like a glob pattern (mirrors expandGlobSync). |
| 76 | +resolved=() |
| 77 | +( |
| 78 | + cd "$TMP/tests" || exit 1 |
| 79 | + shopt -s globstar nullglob |
| 80 | + for ((i = dashdash_index + 1; i < ${#recorded[@]}; i++)); do |
| 81 | + tok="${recorded[$i]}" |
| 82 | + if [[ "$tok" == *"*"* ]]; then |
| 83 | + for f in $tok; do |
| 84 | + echo "$f" |
| 85 | + done |
| 86 | + else |
| 87 | + echo "$tok" |
| 88 | + fi |
| 89 | + done |
| 90 | +) > "$TMP/resolved-files.txt" |
| 91 | + |
| 92 | +grep -q 'a/one\.qmd$' "$TMP/resolved-files.txt" || fail "depth-1 fixture file (qmd-files/a/one.qmd) missing from resolved test set" |
| 93 | +grep -q 'a/b/two\.qmd$' "$TMP/resolved-files.txt" || fail "depth-2 fixture file (qmd-files/a/b/two.qmd) missing from resolved test set - recursive ** bucket was silently truncated" |
| 94 | + |
| 95 | +echo "PASS: recursive ** bucket resolved both depth-1 and depth-2 fixture files" |
0 commit comments