freebsd-dev/sbin/md5/tests/bsd-s-test.SH
Stefan Eßer 884fc5527a sbin/md5: add tests
While the correctness of the supported hash algorithms can be tested
with the built-in self-test feature, these test cases are meant to
detect changes in the output format.

A follow-up commit will	improve	the compatibility with the coreutils
versions of the hash programs, and these tests should detect any
unintended side-effects	of such	a change on existing functionality.
2021-06-25 08:51:40 +02:00

31 lines
578 B
Bash

#!/bin/sh
exitcode=0
testloop () {
opt=$1
sum=$2
field=$3
while read algorithm; do
n=0
for f in %%TESTSBASE%%/sbin/md5/*.inp; do
n=$((n + 1))
read text < $f
hash=$($algorithm$sum $opt -s "$text" | cut -d= -f$field)
hash=$(echo $hash | cut -w -f1)
expected=$(head -$n %%TESTSBASE%%/sbin/md5/$algorithm.digest | tail -1 | cut -w -f4)
[ "$hash" = "$expected" ] || exitcode=1
done
done < %%TESTSBASE%%/sbin/md5/algorithms.txt
}
testloop "" "" 2
testloop -q "" 1
testloop -r "" 1
testloop -qr "" 1
testloop "" sum 1
testloop -q sum 1
exit $exitcode