#!/bin/sh
# Qualification tests must fail to build if their checks would compile away.
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
CC=${CC:-cc}
if ! command -v "$CC" >/dev/null 2>&1; then
    printf 'GATED: compiler not found: %s\n' "$CC" >&2
    exit 2
fi
mkdir -p "$ROOT/build/qualification"
LOG="$ROOT/build/qualification/assertion-guard.log"
if printf '#include "qual.h"\nint main(void) { return 0; }\n' |
    "$CC" -std=c11 -I"$ROOT/test/qualification" -DNDEBUG -x c -fsyntax-only - >"$LOG" 2>&1; then
    printf '%s\n' 'FAIL: -DNDEBUG would silently disable qualification assertions.' >&2
    exit 1
fi
if ! grep -q 'S0 qualification requires assertions' "$LOG"; then
    printf '%s\n' 'FAIL: compilation failed for an unrelated reason; inspect assertion-guard.log.' >&2
    exit 1
fi
printf '%s\n' 'PASS: assertion-disabled qualification builds are explicitly rejected.'
