#!/bin/sh # Offline self-test for yaml-citations.sh: each case is a small fixture tree # that must FAIL (or, for happy-path, PASS). Run: sh scripts/ci/test-yaml-citations.sh set -eu HERE="$(cd "$(dirname "$0")" && pwd)" SUT="$HERE/yaml-citations.sh" [ -f "$SUT" ] || { echo "FAIL: $SUT not found"; exit 1; } TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT INT TERM fails=0 # new_tree NAME — a fixture with one anchored target the cases can cite. new_tree() { d="$TMP/$1"; mkdir -p "$d/k/a" "$d/k/b" printf 'kind: X\n# anchor: target-block\nspec: {}\n' > "$d/k/a/target.yaml" echo "$d" } # expect CASE want(pass|fail) DIR expect() { if YAML_CITATIONS_FLOOR=1 sh "$SUT" "$3" > "$TMP/$1.out" 2>&1; then got=pass; else got=fail; fi if [ "$got" = "$2" ]; then echo "ok $1 ($got)" else echo "FAIL $1: wanted $2, got $got"; sed 's/^/ /' "$TMP/$1.out"; fails=1; fi } d=$(new_tree happy-path) printf '# see target.yaml#target-block and ../a/target.yaml#target-block\nx: 1\n' > "$d/k/a/same-dir.yaml" printf '# root-relative: k/a/target.yaml#target-block\nx: 1\n' > "$d/k/b/root.yaml" printf 'url: "http://h/p.yaml#frag" # a # inside a value is not a comment\n' > "$d/k/b/url.yaml" expect happy-path pass "$d" d=$(new_tree line-number) printf '# see ../a/target.yaml:2\nx: 1\n' > "$d/k/b/c.yaml" expect line-number fail "$d" d=$(new_tree line-range-yml) printf '# see ../a/target.yml:2-3\nx: 1\n' > "$d/k/b/c.yml" expect line-range-yml fail "$d" d=$(new_tree missing-file) printf '# see ../a/gone.yaml#target-block\nx: 1\n' > "$d/k/b/c.yaml" expect missing-file fail "$d" d=$(new_tree missing-anchor) printf '# see ../a/target.yaml#no-such-block\nx: 1\n' > "$d/k/b/c.yaml" expect missing-anchor fail "$d" d=$(new_tree duplicate-anchor) printf '# anchor: target-block\n' >> "$d/k/a/target.yaml" expect duplicate-anchor fail "$d" d=$(new_tree malformed-anchor) printf '# anchor: Not_Kebab\nx: 1\n' > "$d/k/b/c.yaml" expect malformed-anchor fail "$d" d="$TMP/empty-discovery"; mkdir -p "$d" if sh "$SUT" "$d" > "$TMP/empty.out" 2>&1; then echo "FAIL empty-discovery: passed with no files"; fails=1 else echo "ok empty-discovery (fail)"; fi exit $fails