#!/usr/bin/env bash
#
# Run the `ci/compare-image` script against a list of image references.
#
# Each reference is read from stdin. Empty lines, or lines prefixed with
# the `#` character, are ignored.

set -euo pipefail

SELF=$(realpath "$(dirname "$0")")

failed=()

while read -sr line
do
    if [ -z "$line" ] || [ "${line:0:1}" = '#' ]
    then
        continue
    fi

    printf ' --- %q ---\n' "$line"

    if ! "$SELF/compare-image" "$line"
    then
        printf ' --- Failed: %q\n' "$line"
        failed+=("$line")
    fi

    printf '\n\n'
done

if [ ${#failed[@]} -gt 0 ]
then
    echo "Failed:"
    printf ' - %s\n' "${failed[@]}"
    exit 1
fi
