#!/bin/sh set -eu ziran=$1 repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) work=$(mktemp -d) trap 'rm -rf "$work"' EXIT HUP INT TERM "$ziran" run --target=c --root "$repo/tests" "$repo/tests/numeric_width_matrix_gen.zi" -- "$work/width_matrix.zi" "$ziran" ir --root "$work" -o "$work/ir" "$work/width_matrix.zi" for form in source saved; do root=$work input=$work/width_matrix.zi if [ "$form" = saved ]; then root=$work/ir; input=$work/ir/width_matrix.zir; fi "$ziran" bundle --root "$root" --entry width_matrix:Answer -o "$work/$form.zx" "$input" test "$("$ziran" run "$work/$form.zx")" = 42 for target in c go; do output=$work/$form-$target set -- if [ "$target" = go ]; then set -- --pkg main; fi "$ziran" build "--target=$target" --exe --entry width_matrix:Run \ "$@" --root "$root" -o "$output" "$input" case "$target" in c) result=$("$output/width_matrix") ;; go) result=$(GO111MODULE=off go run "$output/"*.go) ;; esac if [ "$result" != 42 ]; then echo "$form/$target failed conversion $result" >&2 exit 1 fi done done