#!/bin/sh # Render every fixture with router/mihomo-kit.sh and web/engine.js, diff them, # and (if MIHOMO points to a mihomo binary) validate with `mihomo -t`. # tools/test.sh parity only # MIHOMO=/path/to/mihomo tools/test.sh set -u cd "$(dirname "$0")/.." out=$(mktemp -d) fail=0 for f in tests/fixtures/*.env; do n=$(basename "$f" .env) [ "$n" = common ] && continue sh router/mihomo-kit.sh render tests/fixtures/common.env "$f" > "$out/$n.sh.yaml" || { echo "FAIL $n: sh render"; fail=1; continue; } sh -c 'set -a; . tests/fixtures/common.env; . "$1"; node tools/render.js' _ "$f" > "$out/$n.js.yaml" || { echo "FAIL $n: js render"; fail=1; continue; } if ! diff -u "$out/$n.sh.yaml" "$out/$n.js.yaml"; then echo "FAIL $n: sh and js differ" fail=1 continue fi if [ -n "${MIHOMO:-}" ]; then mkdir -p "$out/home" # geosite needs a download: drop those rules for the syntax check sed '/GEOSITE/d; /rule-set:ru-inside/d' "$out/$n.sh.yaml" > "$out/home/$n.yaml" if ! "$MIHOMO" -t -d "$out/home" -f "$out/home/$n.yaml" >"$out/$n.log" 2>&1; then echo "FAIL $n: mihomo -t"; tail -3 "$out/$n.log"; fail=1; continue fi fi echo "ok $n" done rm -rf "$out" exit $fail