#!/bin/bash

set -euo pipefail

cd "$(dirname "$0")"/..

function eprintln() {
  >&2 echo "$1"
}

eprintln "Building mdbook"
mdbook build

eprintln "Verifying generated html"
set +e
diff -u \
  "expected/chapter_1_main.html" \
  <(./scripts/get-snapshot)
DIFF_RESULT=$?
set -e

if [ "$DIFF_RESULT" != 0 ]; then
  eprintln ""
  eprintln "error: generated html was different than expected"
  eprintln ""
  eprintln "error: If you expected the output to change, run:"
  eprintln "./integration/update-snapshot"
  eprintln "and commit the result"
  exit 1
fi
