summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-05-05 10:11:59 +0200
committerJim Meyering <meyering@redhat.com>2008-05-06 08:21:30 +0200
commit6ec3a4f03356a79a49f03e4b8c4d59bca30ca671 (patch)
tree6aedc70bc1ee46ba57a09b86757ac226adb87e7d
parent7cc3733f29a7c319a4a100ae48c4ce5486a69440 (diff)
downloadcoreutils-6ec3a4f03356a79a49f03e4b8c4d59bca30ca671.tar.xz
tests: translate uniq-z-test-adding code to new framework
* tests/misc/uniq (add-z-variants): New function. Use it.
-rwxr-xr-xtests/misc/uniq75
1 files changed, 55 insertions, 20 deletions
diff --git a/tests/misc/uniq b/tests/misc/uniq
index a9fe7b8bc..1c85735a2 100755
--- a/tests/misc/uniq
+++ b/tests/misc/uniq
@@ -34,6 +34,60 @@ my $try = "Try \`$prog --help' for more information.\n";
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+# When possible, create a "-z"-testing variant of each test.
+sub add_z_variants($)
+{
+ my ($tests) = @_;
+ my @new;
+ TEST:
+ foreach my $t (@$tests)
+ {
+ push @new, $t;
+
+ # skip the obsolete-syntax tests
+ $t->[0] =~ /^obs-plus/
+ and next;
+
+ my @args;
+ my @list_of_hash;
+
+ foreach my $e (@$t)
+ {
+ !ref $e
+ and push (@args, $e), next;
+
+ ref $e && ref $e eq 'HASH'
+ or (warn "$0: $t->[0]: unexpected entry type\n"), next;
+ my $tmp = $e;
+ foreach my $k (qw(IN OUT))
+ {
+ my $val = $e->{$k};
+ # skip any test whose input or output already contains a NUL byte
+ if (defined $val)
+ {
+ $val =~ /\0/
+ and next TEST;
+
+ # Convert each NL in input or output to \0.
+ $val =~ s/\n/\0/g;
+ $tmp = {$k => $val};
+ last;
+ }
+ }
+ push @list_of_hash, $tmp;
+ }
+
+ shift @args; # discard test name
+
+ # skip any test that uses the -z option
+ grep /z/, @args
+ and next;
+
+ push @new, ["$t->[0]-z", '-z', @args, @list_of_hash];
+ }
+ return @new;
+}
+
# I've only ever triggered the problem in a non-C locale.
my $locale = $ENV{LOCALE_FR};
@@ -155,26 +209,7 @@ foreach my $t (@Tests)
and push @$t, {ENV=>'_POSIX2_VERSION=199209'};
}
-my $ignore = <<\EOF1;
-###########################################################
-# 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;
-EOF1
-
+@Tests = add_z_variants \@Tests;
@Tests = triple_test \@Tests;
my $save_temps = $ENV{DEBUG};