]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Add tests of head's new --lines=-N
authorJim Meyering <jim@meyering.net>
Fri, 4 Jul 2003 10:15:47 +0000 (10:15 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 4 Jul 2003 10:15:47 +0000 (10:15 +0000)
option, and perform the 1600 invocations of head IFF the envvar
RUN_EXPENSIVE_TESTS is set.

tests/misc/head-elide-tail

index 43d39b2b195d62a92f22756fdc748bebd5d0efd5..7d29f98a05cca1f16838ceab187ee31203276d3c 100755 (executable)
@@ -29,41 +29,71 @@ my $READ_BUFSIZE = 4096;
 my @Tests =
   (
    # Elide the exact size of the file.
-   ['elide-1', "--bytes=-2", {IN=>"a\n"}, {OUT=>''}],
+   ['elide-b1', "--bytes=-2", {IN=>"a\n"}, {OUT=>''}],
    # Elide more than the size of the file.
-   ['elide-2', "--bytes=-2", {IN=>"a"},   {OUT=>''}],
+   ['elide-b2', "--bytes=-2", {IN=>"a"},   {OUT=>''}],
    # Leave just one byte.
-   ['elide-3', "--bytes=-2", {IN=>"abc"}, {OUT=>'a'}],
+   ['elide-b3', "--bytes=-2", {IN=>"abc"}, {OUT=>'a'}],
    # Make it so the elided bytes straddle the end of the first
    # $READ_BUFSIZE block.
-   ['elide-4', "--bytes=-2",
+   ['elide-b4', "--bytes=-2",
     {IN=> 'a' x ($READ_BUFSIZE-3) . "\nbcd"},
     {OUT=>'a' x ($READ_BUFSIZE-3) . "\nb"}],
    # Make it so the elided bytes straddle the end of the 2nd
    # $READ_BUFSIZE block.
-   ['elide-5', "--bytes=-2",
+   ['elide-b5', "--bytes=-2",
     {IN=> 'a' x (2 * $READ_BUFSIZE - 2) . 'bcd'},
     {OUT=>'a' x (2 * $READ_BUFSIZE - 2) . 'b'}],
+
+   ['elide-l0', "--lines=-1", {IN=>''}, {OUT=>''}],
+   ['elide-l1', "--lines=-1", {IN=>"a\n"}, {OUT=>''}],
+   ['elide-l2', "--lines=-1", {IN=>"a"}, {OUT=>''}],
+   ['elide-l3', "--lines=-1", {IN=>"a\nb"}, {OUT=>"a\n"}],
+   ['elide-l4', "--lines=-1", {IN=>"a\nb\n"}, {OUT=>"a\n"}],
   );
 
-# Brute force: use all combinations of file sizes [0..20] and
-# number of bytes to elide [0..20].
-my $s = "abcdefghijklmnopqrst";
-for my $file_size (0..20)
+if ($ENV{RUN_EXPENSIVE_TESTS})
   {
-    for my $n_elide (0..20)
+    # Brute force: use all combinations of file sizes [0..20] and
+    # number of bytes to elide [0..20].  For better coverage, recompile
+    # head with -DHEAD_TAIL_PIPE_READ_BUFSIZE=4 and
+    # -DHEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD=8
+    my $s = "abcdefghijklmnopqrst";
+    for my $file_size (0..20)
+      {
+       for my $n_elide (0..20)
+         {
+           my $input = substr $s, 0, $file_size;
+           my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0;
+           my $output = substr $input, 0, $out_len;
+           my $t = ["elideb$file_size-$n_elide", "--bytes=-$n_elide",
+                    {IN=>$input}, {OUT=>$output}];
+           push @Tests, $t;
+           my @u = @$t;
+           # Insert the --presume-input-pipe option.
+           $u[0] .= 'p';
+           $u[1] .= ' --presume-input-pipe';
+           push @Tests, \@u;
+         }
+      }
+
+    $s =~ s/(.)/$1\n/g;
+    for my $file_size (0..20)
       {
-       my $input = substr $s, 0, $file_size;
-       my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0;
-       my $output = substr $input, 0, $out_len;
-       my $t = ["elide-$file_size-$n_elide", "--bytes=-$n_elide",
-                {IN=>$input}, {OUT=>$output}];
-       push @Tests, $t;
-       my @u = @$t;
-       # Insert the --presume-input-pipe option.
-       $u[0] .= 'p';
-       $u[1] .= ' --presume-input-pipe';
-       push @Tests, \@u;
+       for my $n_elide (0..20)
+         {
+           my $input = substr $s, 0, 2 * $file_size;
+           my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0;
+           my $output = substr $input, 0, 2 * $out_len;
+           my $t = ["elidel$file_size-$n_elide", "--lines=-$n_elide",
+                    {IN=>$input}, {OUT=>$output}];
+           push @Tests, $t;
+           my @u = @$t;
+           # Insert the --presume-input-pipe option.
+           $u[0] .= 'p';
+           $u[1] .= ' --presume-input-pipe';
+           push @Tests, \@u;
+         }
       }
   }