#!/bin/bash

# This test exercises the example described in the README.

# basic-command is the example program from the README.
cmd=debian/tests/basic-command

die () {
    printf '%s\n' "$*" 1>&2
    exit 1
}

chmod +x $cmd || exit 1
log=$AUTOPKGTEST_TMP/error.log

$cmd &>$log

text='error: Failed to divide by zero'
# The output must contain this text.
if ! grep -q "$text" $log; then
    echo "Should have output the error, but did not."
    echo "Log: --"
    cat $log
    echo "--"
    exit 1
fi

# With verbosity critical, the output must not contain the error text.
$cmd --verbosity=critical &>$log
if grep -q "$text" $log; then
    echo "Should have NOT output the error."
    echo "Log: --"
    cat $log
    echo "--"
    exit 1
fi
