#!/usr/bin/env bash
# Run harness=false Gherkin integration tests (not compatible with cargo-nextest),
# then emit a one-case JUnit file for Allure merge (`scripts/sdk_merge_allure_results.py`).
set -euo pipefail
rep="${1:-.tmp/sdk-reports}"
mkdir -p "$rep"
out="${rep}/junit-sdk-rust-gherkin-tier1.xml"
if cargo test --test gherkin_tier1 -q; then
  failures=0
  fxml=""
else
  failures=1
  fxml='<failure message="cargo test --test gherkin_tier1 failed"/>'
fi
cat >"$out" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="gherkin_tier1" tests="1" failures="${failures}" errors="0" skipped="0">
    <testcase classname="openapp-sdk" name="gherkin_tier1" time="0">${fxml}</testcase>
  </testsuite>
</testsuites>
EOF
if [[ "$failures" -ne 0 ]]; then
  exit 1
fi
