tests: remove directory, tests/test/
authorJim Meyering <meyering@redhat.com>
Wed, 7 May 2008 23:23:32 +0000 (01:23 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 8 May 2008 07:12:53 +0000 (09:12 +0200)
* configure.ac (AC_CONFIG_FILES): Remove tests/test/Makefile.
* tests/Makefile.am (SUBDIRS): Remove test.
* tests/misc/test: Many new tests, from...
* tests/test/Test.pm: ...here.  Remove file.

configure.ac
tests/Makefile.am
tests/misc/test [new file with mode: 0755]
tests/test/Test.pm [deleted file]

index 0bf3362..42ca02e 100644 (file)
@@ -352,6 +352,5 @@ AC_CONFIG_FILES(
   tests/sort/Makefile
   tests/tac/Makefile
   tests/tail/Makefile
-  tests/test/Makefile
   )
 AC_OUTPUT
index a23d830..701c5f8 100644 (file)
@@ -23,7 +23,7 @@ EXTRA_DIST =          \
 
 ## N O T E :: Do not add more names to this list.
 ## N O T E :: Even these are expected to go away.
-SUBDIRS = join pr sort tac tail test
+SUBDIRS = join pr sort tac tail
 
 root_tests =                                   \
   chown/basic                                  \
@@ -124,6 +124,7 @@ TESTS =                                             \
   chgrp/no-x                                   \
   chgrp/posix-H                                        \
   chgrp/recurse                                        \
+  misc/test                                    \
   misc/seq                                     \
   misc/head                                    \
   misc/head-elide-tail                         \
diff --git a/tests/misc/test b/tests/misc/test
new file mode 100755 (executable)
index 0000000..e3090ce
--- /dev/null
@@ -0,0 +1,201 @@
+#!/bin/sh
+# -*- perl -*-
+
+# Copyright (C) 2008 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+: ${top_srcdir=../..}
+. $top_srcdir/tests/require-perl
+
+me=`echo $0|sed 's,.*/,,'`
+exec $PERL -w -I$top_srcdir/tests -MCoreutils -M"CuTmpdir qw($me)" -- - <<\EOF
+require 5.003;
+use strict;
+
+my $prog = 'test';
+
+# Turn off localization of executable's output.
+@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+
+sub digest_test ($)
+{
+  my ($t) = @_;
+  my @args;
+  my $ret = 0;
+  my @list_of_hashref;
+  foreach my $e (@$t)
+    {
+      !ref $e
+       and push (@args, $e), next;
+      ref $e eq 'HASH'
+       or (warn "$0: $t->[0]: unexpected entry type\n"), next;
+
+      exists $e->{EXIT}
+       and $ret = $e->{EXIT}, next;
+
+      push @list_of_hashref, $e;
+    }
+  shift @args; # discard test name
+  my $flags = join ' ', @args;
+
+  return ($flags, $ret, \@list_of_hashref);
+}
+
+sub add_inverse_op_tests($)
+{
+  my ($tests) = @_;
+  my @new;
+
+  my %inverse_op =
+    (
+     eq => 'ne',
+     lt => 'ge',
+     gt => 'le',
+    );
+
+  foreach my $t (@$tests)
+    {
+      push @new, $t;
+
+      my $test_name = $t->[0];
+      my ($flags, $ret, $LoH) = digest_test $t;
+
+      # Generate corresponding tests of inverse ops.
+      # E.g. generate tests of `-ge' from those of `-lt'.
+      foreach my $op (qw(gt lt eq))
+       {
+         if ($test_name =~ /$op-/ && $flags =~ / -$op /)
+           {
+             my $inv = $inverse_op{$op};
+             $test_name =~ s/$op/$inv/;
+             $flags =~ s/-$op/-$inv/;
+             $ret = 1 - $ret;
+             push (@new, [$test_name, $flags, {EXIT=>$ret}, @$LoH]);
+           }
+       }
+    }
+  return @new;
+}
+
+sub add_pn_tests($)
+{
+  my ($tests) = @_;
+  my @new;
+
+  # Generate parenthesized and negated versions of each test.
+  # There are a few exceptions.
+  my %not_N   = map {$_ => 1} qw (1a);
+  my %not_P   = map {$_ => 1} qw (1a
+                                 streq-6 strne-6
+                                 paren-1 paren-2 paren-3 paren-4 paren-5);
+  foreach my $t (@$tests)
+    {
+      push @new, $t;
+
+      my $test_name = $t->[0];
+      my ($flags, $ret, $LoH) = digest_test $t;
+      next if $ret == 2;
+
+      push (@new, ["N-$test_name", "! $flags", {EXIT=>1-$ret}, @$LoH])
+       unless $not_N{$test_name};
+      push (@new, ["P-$test_name", "'(' $flags ')'", {EXIT=>$ret}, @$LoH])
+       unless $not_P{$test_name};
+      push (@new, ["NP-$test_name", "! '(' $flags ')'", {EXIT=>1-$ret}, @$LoH])
+       unless $not_P{$test_name};
+      push (@new, ["NNP-$test_name", "! ! '(' $flags ')'", {EXIT=>$ret, @$LoH}])
+       unless $not_P{$test_name};
+    }
+
+  return @new;
+}
+
+my @Tests =
+(
+  ['1a', {EXIT=>1}],
+  ['1b', qw(-z '')],
+  ['1c', 'any-string'],
+  ['1d', qw(-n any-string)],
+  ['1e', "''", {EXIT=>1}],
+  ['1f', '-'],
+  ['1g', '--'],
+  ['1h', '-0'],
+  ['1i', '-f'],
+  ['1j', '--help'],
+  ['1k', '--version'],
+
+  ['streq-1', qw(t = t)],
+  ['streq-2', qw(t = f), {EXIT=>1}],
+  ['streq-3', qw(! = !)],
+  ['streq-4', qw(= = =)],
+  ['streq-5', "'(' = '('"],
+  ['streq-6', "'(' = ')'", {EXIT=>1}],
+  ['strne-1', qw(t != t), {EXIT=>1}],
+  ['strne-2', qw(t != f)],
+  ['strne-3', qw(! != !), {EXIT=>1}],
+  ['strne-4', qw(= != =), {EXIT=>1}],
+  ['strne-5', "'(' != '('", {EXIT=>1}],
+  ['strne-6', "'(' != ')'"],
+
+  ['and-1', qw(t -a t)],
+  ['and-2', qw('' -a t), {EXIT=>1}],
+  ['and-3', qw(t -a ''), {EXIT=>1}],
+  ['and-4', qw('' -a ''), {EXIT=>1}],
+
+  ['or-1', qw(t -o t)],
+  ['or-2', qw('' -o t)],
+  ['or-3', qw(t -o '')],
+  ['or-4', qw('' -o ''), {EXIT=>1}],
+
+  ['eq-1', qw(9 -eq 9)],
+  ['eq-2', qw(0 -eq 0)],
+  ['eq-3', qw(0 -eq 00)],
+  ['eq-4', qw(8 -eq 9), {EXIT=>1}],
+  ['eq-5', qw(1 -eq 0), {EXIT=>1}],
+  ['eq-6', qw(340282366920938463463374607431768211456 -eq 0), {EXIT=>1}],
+
+  ['gt-1', qw(5 -gt 5), {EXIT=>1}],
+  ['gt-2', qw(5 -gt 4)],
+  ['gt-3', qw(4 -gt 5), {EXIT=>1}],
+  ['gt-4', qw(-1 -gt -2)],
+  ['gt-5', qw(18446744073709551616 -gt -18446744073709551616)],
+
+  ['lt-1', qw(5 -lt 5), {EXIT=>1}],
+  ['lt-2', qw(5 -lt 4), {EXIT=>1}],
+  ['lt-3', qw(4 -lt 5)],
+  ['lt-4', qw(-1 -lt -2), {EXIT=>1}],
+  ['lt-5', qw(-18446744073709551616 -lt 18446744073709551616)],
+
+  ['inv-1', qw(0x0 -eq 00), {EXIT=>2},
+   {ERR=>"$prog: invalid integer `0x0'\n"}],
+
+  ['t1', "-t"],
+  ['t2', qw(-t 1), {EXIT=>1}],
+
+  ['paren-1', "'(' '' ')'", {EXIT=>1}],
+  ['paren-2', "'(' '(' ')'"],
+  ['paren-3', "'(' ')' ')'"],
+  ['paren-4', "'(' ! ')'"],
+  ['paren-5', "'(' -a ')'"],
+);
+
+@Tests = add_inverse_op_tests \@Tests;
+@Tests = add_pn_tests \@Tests;
+
+my $save_temps = $ENV{DEBUG};
+my $verbose = $ENV{VERBOSE};
+
+my $fail = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose);
+exit $fail;
+EOF
diff --git a/tests/test/Test.pm b/tests/test/Test.pm
deleted file mode 100644 (file)
index 7a81e7c..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-# Test "test".
-
-# Copyright (C) 1998, 2003, 2005, 2006 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
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# -*-perl-*-
-package Test;
-require 5.002;
-use strict;
-
-sub test_vector
-{
-  my @tvec =
-    (
-     # test-name options input expected-output expected-return-code
-     #
-     ['1a', '', {}, '', 1],
-     ['1b', "-z ''", {}, '', 0],
-     ['1c', 'any-string', {}, '', 0],
-     ['1d', '-n any-string', {}, '', 0],
-     ['1e', "''", {}, '', 1],
-     ['1f', '-', {}, '', 0],
-     ['1g', '--', {}, '', 0],
-     ['1h', '-0', {}, '', 0],
-     ['1i', '-f', {}, '', 0],
-     ['1j', '--help', {}, '', 0],
-     ['1k', '--version', {}, '', 0],
-
-     ['streq-1', 't = t', {}, '', 0],
-     ['streq-2', 't = f', {}, '', 1],
-     ['streq-3', '! = !', {}, '', 0],
-     ['streq-4', '= = =', {}, '', 0],
-     ['streq-5', "'(' = '('", {}, '', 0],
-     ['streq-6', "'(' = ')'", {}, '', 1],
-     ['strne-1', 't != t', {}, '', 1],
-     ['strne-2', 't != f', {}, '', 0],
-     ['strne-3', '! != !', {}, '', 1],
-     ['strne-4', '= != =', {}, '', 1],
-     ['strne-5', "'(' != '('", {}, '', 1],
-     ['strne-6', "'(' != ')'", {}, '', 0],
-
-     ['and-1', 't -a t', {}, '', 0],
-     ['and-2', "'' -a t", {}, '', 1],
-     ['and-3', "t -a ''", {}, '', 1],
-     ['and-4', "'' -a ''", {}, '', 1],
-
-     ['or-1', 't -o t', {}, '', 0],
-     ['or-2', "'' -o t", {}, '', 0],
-     ['or-3', "t -o ''", {}, '', 0],
-     ['or-4', "'' -o ''", {}, '', 1],
-
-     ['eq-1', '9 -eq 9', {}, '', 0],
-     ['eq-2', '0 -eq 0', {}, '', 0],
-     ['eq-3', '0 -eq 00', {}, '', 0],
-     ['eq-4', '8 -eq 9', {}, '', 1],
-     ['eq-5', '1 -eq 0', {}, '', 1],
-     ['eq-6', '340282366920938463463374607431768211456 -eq 0', {}, '', 1],
-
-     ['gt-1', '5 -gt 5', {}, '', 1],
-     ['gt-2', '5 -gt 4', {}, '', 0],
-     ['gt-3', '4 -gt 5', {}, '', 1],
-     ['gt-4', '-1 -gt -2', {}, '', 0],
-     ['gt-5', '18446744073709551616 -gt -18446744073709551616', {}, '', 0],
-
-     ['lt-1', '5 -lt 5', {}, '', 1],
-     ['lt-2', '5 -lt 4', {}, '', 1],
-     ['lt-3', '4 -lt 5', {}, '', 0],
-     ['lt-4', '-1 -lt -2', {}, '', 1],
-     ['lt-5', '-18446744073709551616 -lt 18446744073709551616', {}, '', 0],
-
-     # This evokes `test: 0x0: integer expression expected'.
-     ['inv-1', '0x0 -eq 00', {}, '', 2],
-
-     ['t1', "-t", {}, '', 0],
-     ['t2', "-t 1", {}, '', 1],
-
-     ['paren-1', "'(' '' ')'", {}, '', 1],
-     ['paren-2', "'(' '(' ')'", {}, '', 0],
-     ['paren-3', "'(' ')' ')'", {}, '', 0],
-     ['paren-4', "'(' ! ')'", {}, '', 0],
-     ['paren-5', "'(' -a ')'", {}, '', 0],
-    );
-
-  my %inverse_op =
-    (
-     eq => 'ne',
-     lt => 'ge',
-     gt => 'le',
-    );
-
-  # Generate corresponding tests of inverse ops.
-  # E.g. generate tests of `-ge' from those of `-lt'.
-  my @tv;
-  my $t;
-  foreach $t (@tvec)
-    {
-      my ($test_name, $flags, $in, $exp, $ret) = @$t;
-
-      my $op;
-      for $op (qw(gt lt eq))
-       {
-         if ($test_name =~ /$op-/ && $flags =~ / -$op /)
-           {
-             my $inv = $inverse_op{$op};
-             $test_name =~ s/$op/$inv/;
-             $flags =~ s/-$op/-$inv/;
-             $ret = 1 - $ret;
-             push (@tv, [$test_name, $flags, $in, $exp, $ret]);
-           }
-       }
-    }
-
-  # Generate parenthesized and negated versions of each test.
-  # There are a few exceptions.
-  my %not_N   = map {$_ => 1} qw (1a);
-  my %not_P   = map {$_ => 1} qw (1a
-                                 streq-6 strne-6
-                                 paren-1 paren-2 paren-3 paren-4 paren-5);
-  foreach $t (@tvec)
-    {
-      my ($test_name, $flags, $in, $exp, $ret) = @$t;
-      next if $ret == 2;
-      push (@tv, ["N-$test_name", "! $flags", $in, $exp, 1 - $ret])
-         unless $not_N{$test_name};
-      push (@tv, ["P-$test_name", "'(' $flags ')'", $in, $exp, $ret])
-         unless $not_P{$test_name};
-      push (@tv, ["NP-$test_name", "! '(' $flags ')'", $in, $exp, 1 - $ret])
-         unless $not_P{$test_name};
-      push (@tv, ["NNP-$test_name", "! ! '(' $flags ')'", $in, $exp, $ret])
-         unless $not_P{$test_name};
-    }
-
-  return (@tv, @tvec);
-}
-
-1;