otpcli/t/lib.sh

52 lines
1.1 KiB
Bash

#!/bin/sh
# otpcli - command-line interface for HOTP and TOTP
# Written in 2021 by Lucas
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication
# along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
# Produces TAP (Test Anything Protocol) output
# plan number_of_tests [directive]
plan()
{
_n=$1
shift
if [ -n "$*" ]; then
printf "1..%u # %s\n" "$_n" "$*"
else
printf "1..%u\n" "$_n"
fi
_counter=1
}
# check description expected command [args...]
check()
{
_description=$1 _expected=$2
shift 2
_got=$("${@:-:}")
_rc=0
if [ "$_got" != "$_expected" ]; then
printf "not ok %u - %s\n" "$_counter" "$_description"
printf " # Failed test at %s.\n" "$0"
printf " # got: '%s'\n" "$_got"
printf " # expected: '%s'\n" "$_expected"
_rc=1
else
printf "ok %u - %s\n" "$_counter" "$_description"
fi
_counter=$(($_counter + 1))
return $_rc
}