tests: add test for locale decimal processing
[coreutils.git] / tests / misc / md5sum-bsd.sh
blob0893227248eb991a44bb33236ccfc49b1a48ee33
1 #!/bin/sh
2 # 'md5sum' tests for generation and checking of
3 # BSD traditional and alternate formats (md5 [-r])
5 # Copyright (C) 2011-2019 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
21 print_ver_ md5sum
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
30 echo "$i" > "$i"
31 md5sum "$i" >> check.md5sum || fail=1
32 done
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
66 rm check.md5
67 for i in 'a' ' b' '*c' 'dd' ' '; do
68 echo "$i" > "$i"
69 md5sum --tag "$i" >> check.md5 || fail=1
70 done
71 md5sum --strict -c check.md5 || fail=1
73 # Ensure we can --check BSD traditional format we produce
74 # with the GNU extension of escaped newlines
75 nl='
77 tab=' '
78 rm check.md5
79 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do
80 : > "$i"
81 md5sum --tag "$i" >> check.md5 || fail=1
82 done
83 md5sum --strict -c check.md5 || fail=1
85 # Ensure BSD traditional format with GNU extension escapes
86 # is in the expected format
87 ex_file='test
88 \\file'
89 ex_output='\MD5 (test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e'
90 touch "$ex_file"
91 printf "%s\n" "$ex_output" > exp
92 md5sum --tag "$ex_file" > out || fail=1
93 compare exp out || fail=1
95 Exit $fail