]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Test uniq's new --zero-terminated (-z) option.
authorJim Meyering <jim@meyering.net>
Sun, 13 May 2007 09:08:01 +0000 (11:08 +0200)
committerJim Meyering <jim@meyering.net>
Sun, 13 May 2007 09:29:54 +0000 (11:29 +0200)
* tests/uniq/Test.pm: When possible, create a "-z"-testing variant
of each existing test.
(2z, 3z, 4z, 5z, 20z, 122, 123): New tests from James Youngman.

ChangeLog
tests/uniq/Test.pm

index ed23b65cb94aac2f12a1e67ad5716f51290ccc74..bbbf99ff52278824a17752f2dc553945b18faf4f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-13  Jim Meyering  <jim@meyering.net>
+
+       Test uniq's new --zero-terminated (-z) option.
+       * tests/uniq/Test.pm: When possible, create a "-z"-testing variant
+       of each existing test.
+       (2z, 3z, 4z, 5z, 20z, 122, 123): New tests from James Youngman.
+
 2007-05-12  James Youngman  <jay@gnu.org>
 
        Add -z option to uniq.  Originally proposed by Egmont Koblinger.
index 1eda7e2243e4730f26669eb7fcd77340036cf913..ddc67ac6ab795077c8ff0033775c12977b8106a6 100644 (file)
@@ -1,7 +1,6 @@
 # Test "uniq".
 
-# Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006 Free
-# Software Foundation, Inc.
+# Copyright (C) 1998, 1999, 2001-2007 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -34,6 +33,14 @@ my @tv = (
 ['5',  '',    "a\na\nb",         "a\nb\n",          0],
 ['6',  '',    "b\na\na\n",       "b\na\n",          0],
 ['7',  '',    "a\nb\nc\n",       "a\nb\nc\n",       0],
+
+# Ensure that newlines are not interpreted with -z.
+['2z', '-z',  "a\na\n",          "a\na\n\0",        0],
+['3z', '-z',  "a\na",            "a\na\0",          0],
+['4z', '-z',  "a\nb",            "a\nb\0",          0],
+['5z', '-z',  "a\na\nb",         "a\na\nb\0",       0],
+['20z','-dz', "a\na\n",          "",                0],
+
 # Make sure that eight bit characters work
 ['8',  '',    "ö\nv\n",          "ö\nv\n",          0],
 # Test output of -u option; only unique lines
@@ -107,10 +114,15 @@ my @tv = (
 ['120', '-d -u', "a\na\n\b",        "",                         0],
 ['121', '-d -u -w340282366920938463463374607431768211456',
                 "a\na\n\b",        "",                         0],
+# Check that --zero-terminated is synonymous with -z.
+['122', '--zero-terminated',  "a\na\nb",         "a\na\nb\0",       0],
+['123', '--zero-terminated',  "a\0a\0b",         "a\0b\0",          0],
 );
 
 sub test_vector
 {
+  my @new;
+
   my $t;
   foreach $t (@tv)
     {
@@ -122,9 +134,29 @@ sub test_vector
 
       $ret
        and $Test::input_via{$test_name} = {REDIR => 0};
+
+      push @new, $t;
+
+      ###########################################################
+      # When possible, create a "-z"-testing variant of each test.
+
+      # skip any test whose input or output already contains a NUL byte
+      $in =~ /\0/ || $exp =~ /\0/
+       and next;
+      # skip any test that uses the -z option
+      $flags =~ /z/
+       and next;
+      # skip the obsolete-syntax tests
+      $test_name =~ /^obs-plus/
+       and next;
+
+      (my $inz = $in) =~ tr/\n/\0/;
+      (my $expz = $exp) =~ tr/\n/\0/;
+      my $t2 = ["$test_name-z", "-z $flags", $inz, $expz, $ret];
+      push @new, $t2;
     }
 
-  return @tv;
+  return @new;
 }
 
 1;