e2e.sh (1161B)
1 #!/usr/bin/env bash 2 # End-to-end test: for every testdata case with a check.odin, generate Odin 3 # types from its schema, compile them together with the hand-written checks, 4 # and run the checks against sample.json. 5 set -euo pipefail 6 7 ODIN=${ODIN:-odin} 8 root=$(cd "$(dirname "$0")/.." && pwd) 9 build="$root/build/e2e" 10 11 "$ODIN" build "$root/src/cmd/jschema" -debug -out:"$build/jschema" 2>/dev/null || 12 { mkdir -p "$build" && "$ODIN" build "$root/src/cmd/jschema" -debug -out:"$build/jschema"; } 13 14 failures=0 15 for case_dir in "$root"/testdata/cases/*/; do 16 name=$(basename "$case_dir") 17 [ -f "$case_dir/check.odin" ] || continue 18 19 dir="$build/$name" 20 mkdir -p "$dir" 21 rm -f "$dir"/*.odin "$dir"/*.json 22 23 "$build/jschema" "$case_dir/schema.json" -pkg:check -o:"$dir/generated.odin" 24 cp "$case_dir/check.odin" "$dir/" 25 cp "$case_dir/sample.json" "$dir/" 26 27 if "$ODIN" test "$dir" -out:"$dir/check_test" >"$dir/test.log" 2>&1; then 28 echo "ok $name" 29 else 30 echo "FAIL $name" 31 cat "$dir/test.log" 32 failures=$((failures + 1)) 33 fi 34 done 35 36 if [ "$failures" -gt 0 ]; then 37 echo "e2e: $failures case(s) failed" 38 exit 1 39 fi 40 echo "e2e: all cases passed"