#!/bin/sh
set -eu
cd "$(dirname "$0")"
PYK=${KICAD_PYTHON:-/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python3}
CLI=${KICAD_CLI:-/Applications/KiCad/KiCad.app/Contents/MacOS/kicad-cli}
"$PYK" check_adapter.py
"$CLI" sch erc --severity-all --format json --output erc.json cad/vacuum_pressure_a114.kicad_sch
"$CLI" pcb drc --severity-all --all-track-errors --schematic-parity --format json --output drc.json cad/vacuum_pressure_a114.kicad_pcb
python3 -c 'import json; e=json.load(open("erc.json")); d=json.load(open("drc.json")); assert not [v for s in e["sheets"] for v in s["violations"]]; assert not d["violations"] and not d["unconnected_items"] and not d["schematic_parity"]; print("PASS: native ERC/DRC/unconnected/parity all zero")'
