#!/bin/bash

# Check that we don't get an increase in number of debug symbols [#*@]
# on some test texts.

set -e -u

cd "$(dirname "$0")"

lastout=../t/ntb/articles.nob-nno.mt-latest

out=$(mktemp -t hash-count-nno-nob.XXXXXXXXXX)
trap 'rm -f "${out}"' EXIT

if ! apertium -f html-noent -d .. nob-nno_e-genprefs < ../t/ntb/articles.orig.nob > "${out}"; then
    code=$?
    echo "apertium exited with ${code}, output was:"
    cat "${out}"
    exit "${code}"
fi

last=$(grep -c '[#*@]' "${lastout}" || true)
current=$(grep -c '[#*@]' "${out}" || true)

if [[ "${current}" -gt "${last}" ]]; then
    echo "ERROR: Number of debug symbols [#*@] increased between ${lastout} and now"
    grep '[#@]' "${out}"
    exit 1
fi
