source: zzuf/trunk/test/testsuite.sh @ 1725

Last change on this file since 1725 was 1725, checked in by Sam Hocevar, 16 years ago
  • Merged fdcat and streamcat into zzcat.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#!/bin/sh
2
3set -e
4
5check()
6{
7    ZZOPTS="$1"
8    CMD="$2"
9    ALIAS="$3"
10    CHECK="$4"
11    echo -n " $(echo "$ALIAS .............." | cut -b1-18) "
12    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
13    if [ -n "$CHECK" ]; then
14        REFMD5="$CHECK"
15    fi
16    if [ -z "$REFMD5" ]; then
17        REFMD5="$MD5"
18        echo "$MD5"
19    else
20        TESTED=$(($TESTED + 1))
21        if [ "$MD5" != "$REFMD5" ]; then
22            FAILED=$(($FAILED + 1))
23            echo "$MD5 FAILED"
24        else
25            echo 'ok'
26        fi
27    fi
28}
29
30seed=$((0+0$1))
31DIR="$(dirname "$0")"
32ZZUF="$DIR/../src/zzuf"
33ZZCAT="$DIR/zzcat"
34if [ ! -f "$ZZCAT" ]; then
35  echo "error: test/zzcat is missing"
36  exit 1
37fi
38if file /bin/cat | grep -q 'statically linked'; then
39  STATIC_CAT=1
40fi
41if file /bin/dd | grep -q 'statically linked'; then
42  STATIC_DD=1
43fi
44FAILED=0
45TESTED=0
46
47echo "*** running zzuf test suite ***"
48echo "*** using seed $seed ***"
49
50for r in 0.0 0.00001 0.001 0.1 10.0; do
51    for type in 00 ff text random; do
52        file="$DIR/file-$type"
53        ZZOPTS="-s $seed -r $r"
54        case $file in
55          *text*) ZZOPTS="$ZZOPTS -P '\n'" ;;
56        esac
57        echo "*** file $file, ratio $r ***"
58        REFMD5=""
59        if [ $r = 0.0 -a $type = 00 ]; then
60            check="bb7df04e1b0a2570657527a7e108ae23"
61            echo "*** should be $check ***"
62            check "$ZZOPTS" "< $file" "zzuf" "$check"
63        else
64            check "$ZZOPTS" "< $file" "zzuf"
65        fi
66        check "$ZZOPTS" "$ZZCAT 1 $file" "zzcat 1"
67        check "$ZZOPTS" "$ZZCAT 2 $file" "zzcat 2"
68        if [ "$STATIC_CAT" = "" ]; then
69            check "$ZZOPTS" "cat $file" "cat"
70            check "$ZZOPTS" "-i cat < $file" "|cat"
71        fi
72        if [ "$STATIC_DD" = "" ]; then
73            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
74            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
75            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
76            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
77        fi
78        case $file in
79          *text*)
80            # We don't include grep or sed when the input is not text, because
81            # they put a newline at the end of their input if it was not there
82            # initially. (Linux sed doesn't, but OS X sed does.)
83            check "$ZZOPTS" "head -- -n 9999 $file" "head -n 9999"
84            check "$ZZOPTS" "tail -- -n 9999 $file" "tail -n 9999"
85            check "$ZZOPTS" "tail -- -n +1 $file" "tail -n +1"
86            check "$ZZOPTS" "grep -- -a '' $file" "grep -a ''"
87            check "$ZZOPTS" "sed -- -e n $file" "sed -e n"
88            #check "$ZZOPTS" "cut -- -b1- $file" "cut -b1-"
89            check "$ZZOPTS" "-i head -- -n 9999 < $file" "|head -n 9999"
90            check "$ZZOPTS" "-i tail -- -n 9999 < $file" "|tail -n 9999"
91            check "$ZZOPTS" "-i tail -- -n +1 < $file" "|tail -n +1"
92            check "$ZZOPTS" "-i grep -- -a '' < $file" "|grep -a ''"
93            check "$ZZOPTS" "-i sed -- -e n < $file" "|sed -e n"
94            #check "$ZZOPTS" "-i cut -- -b1- < $file" "|cut -b1-"
95            ;;
96        esac
97    done
98done
99
100if [ "$FAILED" != 0 ]; then
101    echo "*** $FAILED tests failed out of $TESTED ***"
102    exit 1
103fi
104echo "*** all $TESTED tests OK ***"
105
106exit 0
107
Note: See TracBrowser for help on using the repository browser.