#!/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 if [ -n "${MIHOMO:-}" ]; then # rule-sets are fetched over http: put a local copy in place for an offline check mkdir -p "$out/home/ruleset" echo '+.example.ru' > "$out/ru-inside.txt" "$MIHOMO" convert-ruleset domain text "$out/ru-inside.txt" "$out/home/ruleset/ru-inside.mrs" >/dev/null fi 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 cp "$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