2 # 'md5sum' tests for generation and checking of
3 # BSD traditional and alternate formats (md5 [-r])
5 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
23 ## BSD alternate format tests ##
25 # Ensure we can --check BSD alternate format.
26 # Note we start this list with a name
27 # that's unambiguous in BSD format.
28 # I.e., one not starting with ' ' or '*'
29 for i
in 'a' ' b' '*c' 'dd' ' '; do
31 md5sum --text "$i" >> check.
md5sum || fail
=1
33 sed 's/ / /' check.
md5sum > check.md5
35 # Note only a single format is supported per run
36 md5sum --strict -c check.
md5sum || fail
=1
37 md5sum --strict -c check.md5 || fail
=1
39 # Ensure we don't trigger BSD reversed format with GPG headers etc.
40 { echo '____not_all_hex_so_no_match_____ blah';
41 cat check.
md5sum; } > check2.
md5sum || framework_failure_
42 md5sum -c check2.
md5sum 2>check2.err || fail
=1
43 echo 'md5sum: WARNING: 1 line is improperly formatted' >check2.exp
44 compare check2.exp check2.err || fail
=1
46 # If we skip the first entry in the BSD format checksums
47 # then it'll be detected as standard format and error.
48 # This unlikely caveat was thought better than mandating
49 # an option to avoid the ambiguity.
50 tail -n+2 check.md5 | returns_
1 md5sum --strict -c || fail
=1
53 ## BSD traditional format tests (--tag option) ##
55 # Ensure --tag and --check are mutually exclusive
56 returns_
1 md5sum --tag --check /dev
/null || fail
=1
58 # Ensure --tag and --text are mutually exclusive
59 # We don't support --text with BSD tradition format,
60 # as that would complicate the output format,
61 # while providing little benefit over --text processing
62 # available with the default md5sum output format.
63 returns_
1 md5sum --tag --text /dev
/null || fail
=1
65 # Ensure we can --check BSD traditional format we produce
67 for i
in 'a' ' b' '*c' 'dd' ' '; do
69 md5sum --tag "$i" >> check.md5 || fail
=1
71 md5sum --strict -c check.md5 || fail
=1
73 if : > 'backslash\is\not\dir\sep'; then
74 # Ensure we can --check BSD traditional format we produce
75 # with the GNU extension of escaped newlines
80 for i
in 'a\b' 'a\' '\a' "a${nl}b" "a${t}b"; do
82 md5sum --tag "$i" >> check.md5 || fail=1
84 md5sum --strict -c check.md5 > out || fail=1
85 printf '%s
: OK
\n' '\a\\b
' '\a\\' '\\\a' '\a\nb
' "a${t}b" > exp ||
87 compare exp out || fail=1
90 # Ensure BSD traditional format with GNU extension escapes
91 # is in the expected format
94 ex_output='\MD5
(test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e
'
96 printf "%s\n" "$ex_output" > exp
97 md5sum --tag "$ex_file" > out || fail=1
98 compare exp out || fail=1