md5sum: quote all printed file names
[coreutils.git] / tests / misc / sha1sum.pl
blob0c22e7a18c1868fefef93b165fc11e654a502476
1 #!/usr/bin/perl
2 # Test "sha1sum".
4 # Copyright (C) 2000-2015 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
21 my $prog = 'sha1sum';
23 # Turn off localization of executable's output.
24 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
26 my $sha_degenerate = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
28 my @Tests =
30 ['s1', {IN=> {f=> ''}},
31 {OUT=>"$sha_degenerate f\n"}],
32 ['s2', {IN=> {f=> 'a'}},
33 {OUT=>"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 f\n"}],
34 ['s3', {IN=> {f=> 'abc'}},
35 {OUT=>"a9993e364706816aba3e25717850c26c9cd0d89d f\n"}],
36 ['s4',
37 {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}},
38 {OUT=>"84983e441c3bd26ebaae4aa1f95129e5e54670f1 f\n"}],
39 ['s5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}},
40 {OUT=>"32d10c7b8cf96570ca04ce37f2a19d84240d3a89 f\n"}],
41 ['s6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}},
42 {OUT=>"761c457bf73b14d27e9e9265c46f4b4dda11f940 f\n"}],
43 ['s7', {IN=> {f=> '1234567890' x 8}},
44 {OUT=>"50abf5706a150990a08b2c5ea40fa0e585554732 f\n"}],
45 ['million-a', {IN=> {f=> 'a' x 1000000}},
46 {OUT=>"34aa973cd4c4daa4f61eeb2bdbad27316534016f f\n"}],
47 ['bs-sha-1', {IN=> {".\nfoo"=> ''}},
48 {OUT=>"\\$sha_degenerate .\\nfoo\n"}],
49 ['bs-sha-2', {IN=> {".\\foo"=> ''}},
50 {OUT=>"\\$sha_degenerate .\\\\foo\n"}],
51 # The sha1sum and md5sum drivers share a lot of code.
52 # Ensure that sha1sum does *not* share the part that makes
53 # md5sum accept BSD format.
54 ['check-bsd', '--check', {IN=> {'f.md5' => "MD5 (f) = $sha_degenerate\n"}},
55 {AUX=> {f=> ''}},
56 {ERR=>"sha1sum: 'f.md5': no properly formatted "
57 . "SHA1 checksum lines found\n"},
58 {EXIT=> 1}],
59 ['check-bsd2', '--check',
60 {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}},
61 {AUX=> {f=> ''}}, {OUT=>"'f': OK\n"}],
62 ['check-bsd3', '--check', '--status',
63 {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}},
64 {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
65 ['check-openssl', '--check',
66 {IN=> {'f.md5' => "MD5(f)= $sha_degenerate\n"}},
67 {AUX=> {f=> ''}},
68 {ERR=>"sha1sum: 'f.md5': no properly formatted "
69 . "SHA1 checksum lines found\n"},
70 {EXIT=> 1}],
71 ['check-openssl2', '--check',
72 {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
73 {AUX=> {f=> ''}}, {OUT=>"'f': OK\n"}],
74 ['check-openssl3', '--check', '--status',
75 {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
76 {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
77 ['bsd-segv', '--check', {IN=> {'z' => "SHA1 ("}}, {EXIT=> 1},
78 {ERR=> "$prog: 'z': no properly formatted SHA1 checksum lines found\n"}],
81 # Insert the '--text' argument for each test.
82 my $t;
83 foreach $t (@Tests)
85 splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/;
88 my $save_temps = $ENV{DEBUG};
89 my $verbose = $ENV{VERBOSE};
91 my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
92 exit $fail;