2 # 'md5sum' tests for generation and checking of
3 # BSD traditional and alternate formats (md5 [-r])
5 # Copyright (C) 2011-2013 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 <http://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 "$i" >> check.md5sum
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 # If we skip the first entry in the BSD format checksums
40 # then it'll be detected as standard format and error.
41 # This unlikely caveat was thought better than mandating
42 # an option to avoid the ambiguity.
43 tail -n+2 check.md5 | md5sum --strict -c && fail=1
46 ## BSD traditional format tests (--tag option) ##
48 # Ensure --tag and --check are mutually exclusive
49 md5sum --tag --check /dev/null && fail=1
51 # Ensure --tag and --text are mutually exclusive
52 # We don't support --text with BSD tradition format,
53 # as that would complicate the output format,
54 # while providing little benefit over --text processing
55 # available with the default md5sum output format.
56 md5sum --tag --text /dev/null && fail=1
58 # Ensure we can --check BSD traditional format we produce
60 for i in 'a' ' b' '*c' 'dd' ' '; do
62 md5sum --tag "$i" >> check.md5
64 md5sum --strict -c check.md5 || fail=1
66 # Ensure we can --check BSD traditional format we produce
67 # with the GNU extension of escaped newlines
72 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do
74 md5sum --tag "$i" >> check.md5
76 md5sum --strict -c check.md5 || fail=1
78 # Ensure BSD traditional format with GNU extension escapes
79 # is in the expected format
82 ex_output='\MD5 (test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e'
84 printf "%s\n" "$ex_output" > exp
85 md5sum --tag "$ex_file" > out
86 compare exp out || fail=1