blob: 51678fe894c21de264d70e26413472ccd936a137 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/bin/bash
cd -- "$(dirname "$0")"
N=14
if test -z "$tool"; then
tool=../${algo}sum
fi
s="$PREFIX $tool"
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) | tr '[A-F]' '[a-f]' | sed -e 's/[\t ]*/ /' | cut -d ' ' -f 2 > tmp1
< $algo sed -e 's/ */ /' | cut -d ' ' -f 2 > tmp2
diff tmp1 tmp2 > /dev/null
report $? "multiple_files_order"
rm tmp1 tmp2
}
multiple_files_delim ()
{
$s $(seq 1 $N) | tr '[A-F]' '[a-f]' | sed -e 's/^[0-9a-f]*//' | sort > tmp1
seq 1 $N | sed -e 's/^/ /' | sort > tmp2
diff tmp1 tmp2 > /dev/null
report $? "multiple_files_delim"
rm tmp1 tmp2
}
multiple_files_sum ()
{
$s $(seq 1 $N) | tr '[A-F]' '[a-f]' | sed -e 's/\t/ /' | cut -d ' ' -f 1 | sort > tmp1
< $algo cut -d ' ' -f 1 | sort > tmp2
diff tmp1 tmp2 > /dev/null
report $? "multiple_files_sum"
rm tmp1 tmp2
}
multiple_files ()
{
$s $(seq 1 $N) | tr '[A-F]' '[a-f]' > tmp1
diff tmp1 $algo > /dev/null
report $? "multiple_files"
rm tmp1
}
one_file ()
{
$s 1 | tr '[A-F]' '[a-f]' > tmp1
< $algo head -n 1 > tmp2
diff tmp1 tmp2 > /dev/null
report $? "one_file"
rm tmp1
}
stdin ()
{
$s < 1 | tr '[A-F]' '[a-f]' | sed 's/[\t ]/ /' | cut -d ' ' -f 1 > tmp1
< $algo head -n 1 | cut -d ' ' -f 1 > tmp2
diff tmp1 tmp2 > /dev/null
report $? "stdin"
rm tmp1
}
dash ()
{
$s - < 1 | tr '[A-F]' '[a-f]' | sed 's/[\t ]/ /' | cut -d ' ' -f 1 > tmp1
< $algo head -n 1 | cut -d ' ' -f 1 > tmp2
diff tmp1 tmp2 > /dev/null
report $? "dash"
rm tmp1
}
check_file_match ()
{
$s $(seq 1 $N) > tmp1
$s -c tmp1 > /dev/null
report $? "check_file_match"
rm tmp1
}
check_stdin_match ()
{
$s $(seq 1 $N) > tmp1
$s -c < tmp1 > /dev/null
report $? "check_stdin_match"
rm tmp1
}
check_dash_match ()
{
$s $(seq 1 $N) > tmp1
$s -c - < tmp1 > /dev/null
report $? "check_dash_match"
rm tmp1
}
check_file_mismatch ()
{
$s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
! $s -c tmp1 > /dev/null 2> /dev/null
report $? "check_file_mismatch"
rm tmp1
}
check_stdin_mismatch ()
{
$s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
! $s -c < tmp1 > /dev/null 2> /dev/null
report $? "check_stdin_mismatch"
rm tmp1
}
check_dash_mismatch ()
{
$s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
! $s -c - < tmp1 > /dev/null 2> /dev/null
report $? "check_dash_mismatch"
rm tmp1
}
check_case ()
{
$s $(seq 1 $N) | tr '[A-F]' '[a-f]' > tmp1
tr '[a-f]' '[A-F]' < tmp1 > tmp2
$s -c tmp1 > /dev/null && $s -c tmp2 > /dev/null
report $? "check_case"
rm tmp1 tmp2
}
check_multi ()
{
$s $(seq 1 5) > tmp1
$s $(seq 6 $N) > tmp2
$s -c tmp1 tmp2 > /dev/null
report $? "check_multi"
rm tmp1 tmp2
}
massive ()
{
diff <($s $(cat bytes)) ${algo}-bytes > /dev/null
report $? "massive"
}
if test $# = 0; then
set multiple_files_order multiple_files_delim multiple_files_sum multiple_files one_file \
stdin dash check_file_match check_stdin_match check_dash_match check_file_mismatch \
check_stdin_mismatch check_dash_mismatch check_case check_multi massive
fi
(
for f in $@; do
$f
done
) | tee result
! grep FAILED < result > /dev/null
ret=$?
if test $ret != 0; then
if test $(grep FAILED < result | grep -v NON-POSIX | wc -l) = 0; then
ret=1
else
ret=2
fi
fi
rm result
exit $ret
|