d0facd32f3e24774b3b67c68ccccb9800be849f4
[platform/upstream/coreutils.git] / tests / md5sum / newline-1
1 #!/bin/sh
2
3 : ${PERL=perl}
4 : ${srcdir=.}
5
6 $PERL -e 1 > /dev/null 2>&1 || {
7   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
8     "so can't run this test"
9   exit 77
10 }
11
12 # See if we can create a filename that contains a newline.
13 # Be careful to do it in a subshell so that we can redirect the
14 # error output if it fails.
15 (> 'a
16 b') 2> /dev/null \
17   && filename_may_contain_newline=yes \
18   || filename_may_contain_newline=no
19 rm -f 'a
20 b'
21
22 if test $filename_may_contain_newline = no; then
23   echo 1>&2 "$0: can't create newline-containing file name," \
24     "so can't run this test"
25   exit 77
26 fi
27
28 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
29 require 5.003;
30 use strict;
31
32 (my $program_name = $0) =~ s|.*/||;
33
34 # Turn off localisation of executable's ouput.
35 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
36
37 my $degenerate = "d41d8cd98f00b204e9800998ecf8427e";
38 my $t = '--text';
39
40 my @Tests =
41     (
42      ['newline', $t, {IN=> {"a\nb"=> ''}}, {OUT=>"\\$degenerate  a\\nb\n"}],
43     );
44
45 my $save_temps = $ENV{DEBUG};
46 my $verbose = $ENV{VERBOSE};
47
48 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
49 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
50 exit $fail;
51 EOF