#!/usr/bin/env bash

echo "Building executable..."

cd "${FLAKE:-$(dirname $0)}"
if command -v nix; then
    bidirectional="$(nix build --no-link --print-out-paths .#a2-p2-bidirectional)/bin/bidirectional"
else
    gcc bidirectional.c -o bidirectional
    bidirectional="./bidirectional"
fi

out="$("$bidirectional")"
read -r -d '' expected <<EOF
Sending message from parent to child
Response from child to parent
EOF
if test "$out" = "$expected"; then
    echo "SUCCESS"
fi
