fe68912bd42037338bba062ad8c7d8e4fb9c3706
[platform/upstream/coreutils.git] / tests / dd / skip-seek
1 #!/bin/sh
2 # -*- perl -*-
3
4 : ${PERL=perl}
5 : ${srcdir=.}
6
7 $PERL -e 1 > /dev/null 2>&1 || {
8   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
9     "so can't run this test"
10   exit 77
11 }
12
13 SCRIPT_NAME=$0
14 export SCRIPT_NAME
15
16 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
17 require 5.003;
18 use strict;
19
20 (my $program_name = $0) =~ s|.*/||;
21
22 # Turn off localisation of executable's ouput.
23 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
24 my $out = 'out';
25 my $script_name = $ENV{SCRIPT_NAME};
26
27 my @Tests =
28     (
29      [
30       'sk-seek1',
31       qw (bs=1 skip=1 seek=2 conv=notrunc count=3 status=noxfer of=@AUX@ < ),
32       {IN=> '0123456789abcdef'},
33       {AUX=> 'zyxwvutsrqponmlkji'},
34       {OUT=> ''},
35       {ERR=> "3+0 records in\n3+0 records out\n"},
36       {CMP=> ['zy123utsrqponmlkji', {'@AUX@'=> undef}]},
37      ],
38      [
39       'sk-seek2',
40       qw (bs=5 skip=1 seek=1 conv=notrunc count=1 status=noxfer of=@AUX@ < ),
41       {IN=> '0123456789abcdef'},
42       {AUX=> 'zyxwvutsrqponmlkji'},
43       {OUT=> ''},
44       {ERR=> "1+0 records in\n1+0 records out\n"},
45       {CMP=> ['zyxwv56789ponmlkji', {'@AUX@'=> undef}]},
46      ],
47      [
48       'sk-seek3',
49       qw (bs=5 skip=1 seek=1 count=1 status=noxfer of=@AUX@ < ),
50       {IN=> '0123456789abcdef'},
51       {AUX=> 'zyxwvutsrqponmlkji'},
52       {OUT=> ''},
53       {ERR=> "1+0 records in\n1+0 records out\n"},
54       {CMP=> ['zyxwv56789', {'@AUX@'=> undef}]},
55      ],
56      [
57       # Before fileutils-4.0.45, the last 10 bytes of output
58       # were these "\0\0\0\0\0\0\0\0  ".
59       'block-sync-1', qw(ibs=10 cbs=10 status=noxfer), 'conv=block,sync', '<',
60       {IN=> "01234567\nabcdefghijkl\n"},
61       {OUT=> "01234567  abcdefghij          "},
62       {ERR=> "2+1 records in\n0+1 records out\n1 truncated record\n"},
63      ],
64      [
65       # Before coreutils-5.93, this would output just "c\n".
66       'sk-seek4', qw(bs=1 skip=1 status=noxfer),
67       {IN_PIPE=> "abc\n"},
68       {OUT=> "bc\n"},
69       {ERR=> "3+0 records in\n3+0 records out\n"},
70      ],
71     );
72
73 my $save_temps = $ENV{DEBUG};
74 my $verbose = $ENV{VERBOSE};
75
76 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
77 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
78 exit $fail;
79 EOF