5 # Copyright (C) 2006 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 2 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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $PERL -e 1 > /dev/null 2>&1 || {
26 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
27 "so can't run this test"
31 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
35 (my $program_name = $0) =~ s|.*/||;
37 # Turn off localisation of executable's ouput.
38 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
40 my $a39 = "YWFhY\nWFhYW\nFhYWF\nhYWFh\nYWFhY\nWFhYW\nFhYWF\n"
41 . "hYWFh\nYWFhY\nWFhYW\nFh";
45 ['empty', {IN=>''}, {OUT=>""}],
46 ['inout', {IN=>'a'}, {OUT=>"YQ==\n"}],
47 ['wrap', '--wrap 0', {IN=>'foo'}, {OUT=>'Zm9v'}],
48 ['wrap5-39', '--wrap=5', {IN=>'a' x 39}, {OUT=>"${a39}\n"}],
49 ['wrap5-40', '--wrap=5', {IN=>'a' x 40}, {OUT=>"${a39}YQ=\n=\n"}],
50 ['wrap5-41', '--wrap=5', {IN=>'a' x 41}, {OUT=>"${a39}YWE\n=\n"}],
51 ['wrap5-42', '--wrap=5', {IN=>'a' x 42}, {OUT=>"${a39}YWF\nh\n"}],
52 ['wrap5-43', '--wrap=5', {IN=>'a' x 43}, {OUT=>"${a39}YWF\nhYQ==\n"}],
53 ['wrap5-44', '--wrap=5', {IN=>'a' x 44}, {OUT=>"${a39}YWF\nhYWE=\n"}],
54 ['wrap5-45', '--wrap=5', {IN=>'a' x 45}, {OUT=>"${a39}YWF\nhYWFh\n"}],
55 ['wrap5-46', '--wrap=5', {IN=>'a' x 46}, {OUT=>"${a39}YWF\nhYWFh\nYQ==\n"}],
56 ['baddecode', '--decode', {IN=>'a'}, {OUT=>""},
57 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
58 ['baddecode2', '--decode', {IN=>'ab'}, {OUT=>"i"},
59 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
60 ['baddecode3', '--decode', {IN=>'Zzz'}, {OUT=>"g<"},
61 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
62 ['baddecode4', '--decode', {IN=>'Zz='}, {OUT=>"g"},
63 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
64 ['baddecode5', '--decode', {IN=>'Z==='}, {OUT=>""},
65 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}]
68 # For each non-failing test, create a --decode test using the
69 # expected output (with newlines removed) as input.
71 foreach my $t (@Tests)
78 ref $e && ref $e eq 'HASH'
81 and $exit_val = $e->{EXIT};
85 and ($out = $e->{OUT}) =~ tr/\n//d;
87 defined $out && ! $exit_val
88 and push @new, ["d-$t->[0]", '--decode', {IN => $out}, {OUT => $in}];
92 my $save_temps = $ENV{DEBUG};
93 my $verbose = $ENV{VERBOSE};
95 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
96 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);