#!/bin/sh
#
# This takes in an output log and a program to run.
#
# This runs the program and compares the output to the log.

if [ $# -lt 2 ]; then
  echo "Error: Usage: testit <log> cmd arg arg..." 1>&2
  exit 1
fi

GOAL="$1"
shift

# Temp file, with automatic cleanup
LOG="/tmp/testit.$$.log"
trap 'rm -f "$LOG"' EXIT

# Run
"$@" > "$LOG" 2>&1
RC=$?

# Compare
diff "$GOAL" "$LOG"

# Cleanup happens automatically
exit $RC
