#!/usr/bin/env bash
# misc_panic_verify-entry — `NUC_PANIC_AT=verify-entry` fires
# inside `cli::verify::run`. Same shape as the other -d panic
# sites.
set -euo pipefail

cat > "$NUCTEST_TMPDIR/x.dzn" <<'EOF'
interface I { in void e(); behavior { on e: {} } }
component C { provides I p; behavior { on p.e(): {} } }
EOF

set +e
NUC_PANIC_AT=verify-entry "$NUCLEOS" -d verify -k -m C "$NUCTEST_TMPDIR/x.dzn" \
    > "$NUCTEST_TMPDIR/out.txt" 2> "$NUCTEST_TMPDIR/err.txt"
exit_code=$?
set -e

[ "$exit_code" != 0 ] || { echo "FAIL: expected panic" >&2; exit 1; }
for needle in "panicked at" "src/" \
    "=== nucleos diagnostic context ===" "argv    :"; do
    if ! grep -qF "$needle" "$NUCTEST_TMPDIR/err.txt"; then
        echo "FAIL: stderr missing '$needle'" >&2
        cat "$NUCTEST_TMPDIR/err.txt" >&2
        exit 1
    fi
done
