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

bin=${1:?usage: run_benchmark_smoke.sh /path/to/benchmark_phpef}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

"$bin" >"$work/out" 2>"$work/err"

printf '%s\n' '--- benchmark_phpef stdout ---'
cat "$work/out"
printf '%s\n' '--- benchmark_phpef stderr ---'
cat "$work/err"

for required in \
    'This Application is copyright' \
    'Tests - Success.' \
    'Benchmark 10 run:' \
    'Benchmark 20 run:' \
    'Benchmark 10 tuned run:' \
    'Benchmark 20 tuned run:' \
    'Total Benchmark:'; do
    if ! grep -Fq "$required" "$work/out"; then
        echo "missing expected benchmark output: $required" >&2
        exit 1
    fi
done

if [ -s "$work/err" ]; then
    echo 'did not expect stderr output from benchmark_phpef' >&2
    exit 1
fi

printf '%s\n' 'ok 1 - benchmark_phpef runs successfully'
