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.
31 lines
578 B
Bash
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
|