~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/sha1sum.pl

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# Test "sha1sum".
 
3
 
 
4
# Copyright (C) 2000-2012 Free Software Foundation, Inc.
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
 
 
19
use strict;
 
20
 
 
21
my $prog = 'sha1sum';
 
22
 
 
23
# Turn off localization of executable's output.
 
24
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
 
25
 
 
26
my $sha_degenerate = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
 
27
 
 
28
my @Tests =
 
29
    (
 
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', {IN=> {".\\foo"=> ''}},
 
48
                        {OUT=>"\\$sha_degenerate  .\\\\foo\n"}],
 
49
     # The sha1sum and md5sum drivers share a lot of code.
 
50
     # Ensure that sha1sum does *not* share the part that makes
 
51
     # md5sum accept BSD format.
 
52
     ['check-bsd', '--check', {IN=> {'f.md5' => "MD5 (f) = $sha_degenerate\n"}},
 
53
                        {AUX=> {f=> ''}},
 
54
                        {ERR=>"sha1sum: f.md5: no properly formatted "
 
55
                          . "SHA1 checksum lines found\n"},
 
56
                        {EXIT=> 1}],
 
57
     ['check-bsd2', '--check',
 
58
                        {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}},
 
59
                        {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
 
60
     ['check-bsd3', '--check', '--status',
 
61
                        {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}},
 
62
                        {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
 
63
     ['check-openssl', '--check',
 
64
                        {IN=> {'f.md5' => "MD5(f)= $sha_degenerate\n"}},
 
65
                        {AUX=> {f=> ''}},
 
66
                        {ERR=>"sha1sum: f.md5: no properly formatted "
 
67
                          . "SHA1 checksum lines found\n"},
 
68
                        {EXIT=> 1}],
 
69
     ['check-openssl2', '--check',
 
70
                        {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
 
71
                        {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
 
72
     ['check-openssl3', '--check', '--status',
 
73
                        {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
 
74
                        {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
 
75
     ['bsd-segv', '--check', {IN=> {'z' => "SHA1 ("}}, {EXIT=> 1},
 
76
      {ERR=> "$prog: z: no properly formatted SHA1 checksum lines found\n"}],
 
77
    );
 
78
 
 
79
# Insert the '--text' argument for each test.
 
80
my $t;
 
81
foreach $t (@Tests)
 
82
  {
 
83
    splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/;
 
84
  }
 
85
 
 
86
my $save_temps = $ENV{DEBUG};
 
87
my $verbose = $ENV{VERBOSE};
 
88
 
 
89
my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
 
90
exit $fail;