coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] tests: test: Add tests for file-type tests, including the


From: Mattias Andrée
Subject: [PATCH v2 2/2] tests: test: Add tests for file-type tests, including the new -E flag
Date: Thu, 7 Apr 2016 10:34:57 +0200

---
 tests/local.mk           |   3 +-
 tests/misc/test.pl       | 197 -----------------------------------------------
 tests/test/file-types.sh | 190 +++++++++++++++++++++++++++++++++++++++++++++
 tests/test/misc.pl       | 197 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 389 insertions(+), 198 deletions(-)
 delete mode 100755 tests/misc/test.pl
 create mode 100755 tests/test/file-types.sh
 create mode 100755 tests/test/misc.pl

diff --git a/tests/local.mk b/tests/local.mk
index a83c3d0..c648998 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -233,7 +233,8 @@ all_tests =                                 \
   tests/fmt/goal-option.sh                     \
   tests/misc/env.sh                            \
   tests/misc/ptx.pl                            \
-  tests/misc/test.pl                           \
+  tests/test/misc.pl                           \
+  tests/test/file-types.sh                     \
   tests/misc/seq.pl                            \
   tests/misc/seq-long-double.sh                        \
   tests/misc/seq-precision.sh                  \
diff --git a/tests/misc/test.pl b/tests/misc/test.pl
deleted file mode 100755
index 1091d3a..0000000
--- a/tests/misc/test.pl
+++ /dev/null
@@ -1,197 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright (C) 2008-2016 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/>.
-
-use strict;
-
-my $limits = getlimits ();
-
-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}],
-  ['streqeq-1', qw(t == t)],
-  ['streqeq-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', "$limits->{UINTMAX_OFLOW} -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', "$limits->{UINTMAX_OFLOW} -gt $limits->{INTMAX_UFLOW}"],
-
-  ['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', "$limits->{INTMAX_UFLOW} -lt $limits->{UINTMAX_OFLOW}"],
-
-  ['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;
diff --git a/tests/test/file-types.sh b/tests/test/file-types.sh
new file mode 100755
index 0000000..a2bbc14
--- /dev/null
+++ b/tests/test/file-types.sh
@@ -0,0 +1,190 @@
+#!/bin/sh
+# Verify test's file-type test flags.
+
+# Copyright (C) 2016 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/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ test
+
+test -e /dev/null        || skip_ 'requires /dev/null'
+test -e /dev/sda         || skip_ 'requires /dev/sda'
+test -x /usr/bin/python3 || skip_ 'requires /usr/bin/python3'
+
+mkdir dir.empty                || framework_failure_
+mkdir dir.visible              || framework_failure_
+touch dir.visible/x            || framework_failure_
+mkdir dir.hidden               || framework_failure_
+touch dir.hidden/.x            || framework_failure_
+touch reg                      || framework_failure_
+mkfifo fifo                    || framework_failure_
+ln -s reg lreg                 || framework_failure_
+ln -s dir.empty ldir.empty     || framework_failure_
+ln -s dir.hidden ldir.hidden   || framework_failure_
+ln -s dir.visible ldir.visible || framework_failure_
+ln -s /dev/sda lblock          || framework_failure_
+ln -s /dev/null lchar          || framework_failure_
+ln -s fifo lfifo               || framework_failure_
+ln -s socket lsocket           || framework_failure_
+ln -s nonexisting dangling     || framework_failure_
+ln -s selfref selfref          || framework_failure_
+/usr/bin/python3 <<EOF         || framework_failure_
+import socket
+socket.socket(socket.AF_UNIX, socket.SOCK_STREAM).bind('socket')
+EOF
+
+# Block devices.
+env test -b /dev/sda     || fail=1
+env test -b lblock       || fail=1
+env test -b /dev/null    && fail=1
+env test -b lchar        && fail=1
+env test -b dir.empty    && fail=1
+env test -b dir.hidden   && fail=1
+env test -b dir.visible  && fail=1
+env test -b reg          && fail=1
+env test -b fifo         && fail=1
+env test -b socket       && fail=1
+env test -b ldir.empty   && fail=1
+env test -b ldir.hidden  && fail=1
+env test -b ldir.visible && fail=1
+env test -b lreg         && fail=1
+env test -b lfifo        && fail=1
+env test -b lsocket      && fail=1
+env test -b dangling     && fail=1
+env test -b selfref      && fail=1
+
+# Character devices.
+env test -c /dev/null    || fail=1
+env test -c lchar        || fail=1
+env test -c /dev/sda     && fail=1
+env test -c lblock       && fail=1
+env test -c dir.empty    && fail=1
+env test -c dir.hidden   && fail=1
+env test -c dir.visible  && fail=1
+env test -c reg          && fail=1
+env test -c fifo         && fail=1
+env test -c socket       && fail=1
+env test -c ldir.empty   && fail=1
+env test -c ldir.hidden  && fail=1
+env test -c ldir.visible && fail=1
+env test -c lreg         && fail=1
+env test -c lfifo        && fail=1
+env test -c lsocket      && fail=1
+env test -c dangling     && fail=1
+env test -c selfref      && fail=1
+
+# Directories.
+env test -d dir.empty    || fail=1
+env test -d dir.visible  || fail=1
+env test -d dir.hidden   || fail=1
+env test -d ldir.empty   || fail=1
+env test -d ldir.visible || fail=1
+env test -d ldir.hidden  || fail=1
+env test -d /dev/null    && fail=1
+env test -d lchar        && fail=1
+env test -d /dev/sda     && fail=1
+env test -d lblock       && fail=1
+env test -d reg          && fail=1
+env test -d fifo         && fail=1
+env test -d socket       && fail=1
+env test -d lreg         && fail=1
+env test -d lfifo        && fail=1
+env test -d lsocket      && fail=1
+env test -d dangling     && fail=1
+env test -d selfref      && fail=1
+
+# Empty directories.
+env test -E dir.empty    || fail=1
+env test -E ldir.empty   || fail=1
+env test -E dir.visible  && fail=1
+env test -E dir.hidden   && fail=1
+env test -E ldir.visible && fail=1
+env test -E ldir.hidden  && fail=1
+env test -E /dev/null    && fail=1
+env test -E lchar        && fail=1
+env test -E /dev/sda     && fail=1
+env test -E lblock       && fail=1
+env test -E reg          && fail=1
+env test -E fifo         && fail=1
+env test -E socket       && fail=1
+env test -E lreg         && fail=1
+env test -E lfifo        && fail=1
+env test -E lsocket      && fail=1
+env test -E dangling     && fail=1
+env test -E selfref      && fail=1
+
+# Symbolic links.
+env test -L lreg         || fail=1
+env test -L ldir.empty   || fail=1
+env test -L ldir.visible || fail=1
+env test -L ldir.hidden  || fail=1
+env test -L lblock       || fail=1
+env test -L lchar        || fail=1
+env test -L lfifo        || fail=1
+env test -L lsocket      || fail=1
+env test -L dangling     || fail=1
+env test -L selfref      || fail=1
+env test -L dir.empty    && fail=1
+env test -L dir.visible  && fail=1
+env test -L dir.hidden   && fail=1
+env test -L reg          && fail=1
+env test -L fifo         && fail=1
+env test -L socket       && fail=1
+
+# Named pipes.
+env test -p fifo         || fail=1
+env test -p lfifo        || fail=1
+env test -p dir.empty    && fail=1
+env test -p ldir.empty   && fail=1
+env test -p dir.visible  && fail=1
+env test -p dir.hidden   && fail=1
+env test -p ldir.visible && fail=1
+env test -p ldir.hidden  && fail=1
+env test -p /dev/null    && fail=1
+env test -p lchar        && fail=1
+env test -p /dev/sda     && fail=1
+env test -p lblock       && fail=1
+env test -p reg          && fail=1
+env test -p socket       && fail=1
+env test -p lreg         && fail=1
+env test -p lsocket      && fail=1
+env test -p dangling     && fail=1
+env test -p selfref      && fail=1
+
+# Sockets.
+env test -S socket       || fail=1
+env test -S lsocket      || fail=1
+env test -S /dev/sda     && fail=1
+env test -S lblock       && fail=1
+env test -S /dev/null    && fail=1
+env test -S lchar        && fail=1
+env test -S dir.empty    && fail=1
+env test -S dir.hidden   && fail=1
+env test -S dir.visible  && fail=1
+env test -S reg          && fail=1
+env test -S fifo         && fail=1
+env test -S ldir.empty   && fail=1
+env test -S ldir.hidden  && fail=1
+env test -S ldir.visible && fail=1
+env test -S lreg         && fail=1
+env test -S lfifo        && fail=1
+env test -S dangling     && fail=1
+env test -S selfref      && fail=1
+
+rm dir.visible/x dir.hidden/.x reg fifo socket dangling selfref
+rm lreg ldir.empty ldir.visible lblock lchar lfifo lsocket
+rmdir dir.empty dir.visible dir.hidden
+
+Exit $fail
diff --git a/tests/test/misc.pl b/tests/test/misc.pl
new file mode 100755
index 0000000..1091d3a
--- /dev/null
+++ b/tests/test/misc.pl
@@ -0,0 +1,197 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2008-2016 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/>.
+
+use strict;
+
+my $limits = getlimits ();
+
+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}],
+  ['streqeq-1', qw(t == t)],
+  ['streqeq-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', "$limits->{UINTMAX_OFLOW} -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', "$limits->{UINTMAX_OFLOW} -gt $limits->{INTMAX_UFLOW}"],
+
+  ['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', "$limits->{INTMAX_UFLOW} -lt $limits->{UINTMAX_OFLOW}"],
+
+  ['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;
-- 
2.8.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]