diff options
author | Mattias Andrée <maandree@kth.se> | 2016-03-24 10:00:16 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-03-24 10:00:16 +0100 |
commit | e6f83b3a5b2d1ace5a21a1a16aaf9e363249f109 (patch) | |
tree | f33f3fa9200ecd583750b0b23a73a1c27bf57790 | |
parent | add tests for true and false, and suppress warnings with the tools cannot be found in PATH (diff) | |
download | base-util-tests-e6f83b3a5b2d1ace5a21a1a16aaf9e363249f109.tar.gz base-util-tests-e6f83b3a5b2d1ace5a21a1a16aaf9e363249f109.tar.bz2 base-util-tests-e6f83b3a5b2d1ace5a21a1a16aaf9e363249f109.tar.xz |
Add cksum-test
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | __sum/ck | 14 | ||||
-rwxr-xr-x | cksum-test/test | 87 |
2 files changed, 101 insertions, 0 deletions
diff --git a/__sum/ck b/__sum/ck new file mode 100644 index 0000000..51f3f0f --- /dev/null +++ b/__sum/ck @@ -0,0 +1,14 @@ +4294967295 0 1 +2418082923 2 2 +1220704766 1 3 +3515105045 1 4 +3518178554 2 5 +3263187401 5 6 +1220704766 1 7 +1219131554 3 8 +2074844392 43 9 +3951473468 44 10 +1219157968 10 11 +81918263 62 12 +1939911592 80 13 +2713270184 26 14 diff --git a/cksum-test/test b/cksum-test/test new file mode 100755 index 0000000..8a0cdab --- /dev/null +++ b/cksum-test/test @@ -0,0 +1,87 @@ +#!/bin/bash + +cd -- "$(dirname "$0")/../__sum" +N=14 +algo=ck +if test -z "$CKSUM"; then + CKSUM=../${algo}sum +fi +s="$PREFIX $CKSUM" + +report () +{ + if test $1 = 0; then + printf "\033[1;32mTest %s OK\033[m\n" "$2" + else + printf "\033[1;31mTest %s FAILED\033[m\n" "$2" + fi +} + +multiple_files_order () +{ + $s $(seq 1 $N) | sed -e 's/[\t ]\+/ /g' | cut -d ' ' -f 3 > tmp1 + < $algo cut -d ' ' -f 3 > tmp2 + diff tmp1 tmp2 > /dev/null + report $? "multiple_files_order" + rm tmp1 tmp2 +} + +multiple_files_sum () +{ + $s $(seq 1 $N) | sed -e 's/[\t ]\+/ /g' | cut -d ' ' -f 1,2 | sort > tmp1 + < $algo cut -d ' ' -f 1,2 | sort > tmp2 + diff tmp1 tmp2 > /dev/null + report $? "multiple_files_sum" + rm tmp1 tmp2 +} + +multiple_files () +{ + $s $(seq 1 $N) > tmp1 + diff tmp1 $algo > /dev/null + report $? "multiple_files" + rm tmp1 +} + +one_file () +{ + $s 1 > tmp1 + < $algo head -n 1 > tmp2 + diff tmp1 tmp2 > /dev/null + report $? "one_file" + rm tmp1 tmp2 +} + +stdin () +{ + $s < 1 | sed 's/[\t ]\+/ /' > tmp1 + < $algo head -n 1 | cut -d ' ' -f 1,2 > tmp2 + diff tmp1 tmp2 > /dev/null + report $? "stdin" + rm tmp1 tmp2 +} + +dash () +{ + $s - < 1 | sed 's/[\t ]\+/ /g' | tee tmp3 | cut -d ' ' -f 1,2 > tmp1 + < $algo head -n 1 | cut -d ' ' -f 1,2 > tmp2 + diff tmp1 tmp2 > /dev/null && + test $(grep -o ' ' < tmp3 | wc -l) = 2 && + test -n "$(cut -d ' ' -f 3 < tmp3)" + report $? "dash" + rm tmp1 tmp2 tmp3 +} + + +if test $# = 0; then + set multiple_files_order multiple_files_sum multiple_files one_file stdin dash +fi +( +for f in $@; do + $f +done +) | tee result +! grep FAILED < result >/dev/null +ret=$? +rm result +exit $ret |