#!/usr/bin/env bash
# misc_panic_lts-entry — `NUC_PANIC_AT=lts-entry` fires inside
# `cli::lts::run`. Same assertions as misc_panic_parse-entry:
# panicked at, src/ location, diagnostic context, argv line.
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=lts-entry "$NUCLEOS" -d lts -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
