#!/bin/sh

set -e

: ${UTRANS:=../utrans}

for backend in openrc cron xinetd inetd lsb ; do

    echo "Testing $backend backend" >&2

    output=$(mktemp -d)
    trap 'rm -rf ${output}' EXIT

    find ./input -maxdepth 2 ! -type d -print -exec "$UTRANS" -f overwrite -b ="${backend}" '{}' "${output}" ';' 2>&1 |
	# Filter expected missing backend errors.
	grep -vx "ERROR: backend for [a-z]\+ unit not available\."

    diff -u -r  -x '.*' expected/"${backend}" "${output}"

    rm -rf "${output}"

done
