3 # Exercise head's --bytes=-N option.
8 $PERL -e 1 > /dev
/null
2>&1 ||
{
9 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
10 "so can't run this test"
14 exec $PERL -w -I$srcdir/..
-MCoreutils -- - <<\EOF
19 (my
$program_name = $0) =~ s|.
*/||
;
23 # Turn off localization of executable's ouput.
24 @ENV
{qw
(LANGUAGE LANG LC_ALL
)} = ('C') x
3;
26 # This should match the definition in head.c.
27 my
$READ_BUFSIZE = 4096;
31 # Elide the exact size of the file.
32 ['elide-b1', "--bytes=-2", {IN
=>"a\n"}, {OUT
=>''}],
33 # Elide more than the size of the file.
34 ['elide-b2', "--bytes=-2", {IN
=>"a"}, {OUT
=>''}],
35 # Leave just one byte.
36 ['elide-b3', "--bytes=-2", {IN
=>"abc"}, {OUT
=>'a'}],
37 # Make it so the elided bytes straddle the end of the first
38 # $READ_BUFSIZE block.
39 ['elide-b4', "--bytes=-2",
40 {IN
=> 'a' x
($READ_BUFSIZE-3) .
"\nbcd"},
41 {OUT
=>'a' x
($READ_BUFSIZE-3) .
"\nb"}],
42 # Make it so the elided bytes straddle the end of the 2nd
43 # $READ_BUFSIZE block.
44 ['elide-b5', "--bytes=-2",
45 {IN
=> 'a' x
(2 * $READ_BUFSIZE - 2) .
'bcd'},
46 {OUT
=>'a' x
(2 * $READ_BUFSIZE - 2) .
'b'}],
48 ['elide-l0', "--lines=-1", {IN
=>''}, {OUT
=>''}],
49 ['elide-l1', "--lines=-1", {IN
=>"a\n"}, {OUT
=>''}],
50 ['elide-l2', "--lines=-1", {IN
=>"a"}, {OUT
=>''}],
51 ['elide-l3', "--lines=-1", {IN
=>"a\nb"}, {OUT
=>"a\n"}],
52 ['elide-l4', "--lines=-1", {IN
=>"a\nb\n"}, {OUT
=>"a\n"}],
55 if ($ENV{RUN_EXPENSIVE_TESTS
})
57 # Brute force: use all combinations of file sizes [0..20] and
58 # number of bytes to elide [0..20]. For better coverage, recompile
59 # head with -DHEAD_TAIL_PIPE_READ_BUFSIZE=4 and
60 # -DHEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD=8
61 my
$s = "abcdefghijklmnopqrst";
62 for my
$file_size (0.
.20)
64 for my
$n_elide (0.
.20)
66 my
$input = substr
$s, 0, $file_size;
67 my
$out_len = $n_elide < $file_size ?
$file_size - $n_elide : 0;
68 my
$output = substr
$input, 0, $out_len;
69 my
$t = ["elideb$file_size-$n_elide", "--bytes=-$n_elide",
70 {IN
=>$input}, {OUT
=>$output}];
73 # Insert the --presume-input-pipe option.
75 $u[1] .
= ' --presume-input-pipe';
81 for my
$file_size (0.
.20)
83 for my
$n_elide (0.
.20)
85 my
$input = substr
$s, 0, 2 * $file_size;
86 my
$out_len = $n_elide < $file_size ?
$file_size - $n_elide : 0;
87 my
$output = substr
$input, 0, 2 * $out_len;
88 my
$t = ["elidel$file_size-$n_elide", "--lines=-$n_elide",
89 {IN
=>$input}, {OUT
=>$output}];
92 # Insert the --presume-input-pipe option.
94 $u[1] .
= ' --presume-input-pipe';
100 my
$save_temps = $ENV{DEBUG
};
101 my
$verbose = $ENV{VERBOSE
};
103 my
$prog = $ENV{PROG
} || die
"$0: \$PROG not specified in environment\n";
104 my
$fail = run_tests
($program_name, $prog, \@Tests
, $save_temps, $verbose);