#!/usr/bin/env bash
set -euo pipefail

yaml_root=/usr/share/rtc-testbench/tests
fallback_root=/usr/share/testbench/tests

if [[ ! -d "${yaml_root}" ]]; then
	if [[ -d "${fallback_root}" ]]; then
		yaml_root="${fallback_root}"
	else
		echo "YAML test directory not found: ${yaml_root} or ${fallback_root}" >&2
		exit 1
	fi
fi

found=0
while IFS= read -r -d '' yaml; do
	found=1
	python3 - <<'PY' "${yaml}"
import pathlib
import sys
import yaml

path = pathlib.Path(sys.argv[1])
yaml.safe_load(path.read_text())
PY
done < <(find "${yaml_root}" -name '*.yaml' -print0)

if [[ "${found}" -eq 0 ]]; then
	echo "No YAML files found under ${yaml_root}." >&2
	exit 1
fi
