#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

make -C "$ROOT" -s >/dev/null

BIN="$ROOT/flowlog"

fail() {
  echo "fail: $1" >&2
  exit 1
}

tmpdir="$(mktemp -d -t flowlog_ctrld_repl.XXXXXX)"
cleanup() {
  rm -rf "$tmpdir" >/dev/null 2>&1 || true
}
trap cleanup EXIT

tester="$tmpdir/ctrld_repl_tty"
cc -O2 -Wall -Wextra "$ROOT/tests/regressions/repl_ctrld_tty.c" -lutil -o "$tester" || fail "ctrld_repl_build"

"$tester" "$BIN" >/dev/null 2>&1 || fail "ctrld_repl_exit"

echo "ok"
