summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-05-04 11:38:31 +0200
committerJim Meyering <meyering@redhat.com>2008-05-06 08:21:30 +0200
commitbc2b9e04e9c4f715d460cb3748f1d27d2602b764 (patch)
tree02bb319e3bfb7162b076772d371a11e37bbb917d /tests
parent5ad6145142ad3417fe3598349d75a6fa366f6647 (diff)
downloadcoreutils-bc2b9e04e9c4f715d460cb3748f1d27d2602b764.tar.xz
tests: remove directory, tests/head/
* configure.ac (AC_CONFIG_FILES): Remove tests/head/Makefile. * tests/Makefile.am (SUBDIRS): Remove head. * tests/misc/head: New file, derived from ... * tests/head/Test.pm: ...this. Remove file. * tests/head/in: Remove file. * tests/head/in-1024: Remove file. * tests/Coreutils.pm (triple_test): New function.
Diffstat (limited to 'tests')
-rw-r--r--tests/Coreutils.pm43
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/head/Test.pm108
-rw-r--r--tests/head/in15
-rw-r--r--tests/head/in-102413
-rwxr-xr-xtests/misc/head90
6 files changed, 134 insertions, 138 deletions
diff --git a/tests/Coreutils.pm b/tests/Coreutils.pm
index 36dae2c13..e97596563 100644
--- a/tests/Coreutils.pm
+++ b/tests/Coreutils.pm
@@ -25,7 +25,7 @@ use File::Compare qw(compare);
@ISA = qw(Exporter);
($VERSION = '$Revision: 1.5 $ ') =~ tr/[0-9].//cd;
-@EXPORT = qw (run_tests);
+@EXPORT = qw (run_tests triple_test);
my $debug = $ENV{DEBUG};
@@ -562,5 +562,46 @@ sub run_tests ($$$$$)
return $fail;
}
+# For each test in @$TESTS, generate two additional tests,
+# one using stdin, the other using a pipe. I.e., given this one
+# ['idem-0', {IN=>''}, {OUT=>''}],
+# generate these:
+# ['idem-0.r', '<', {IN=>''}, {OUT=>''}],
+# ['idem-0.p', {IN_PIPE=>''}, {OUT=>''}],
+# Generate new tests only if there is exactly one input spec.
+# The returned list of tests contains each input test, followed
+# by zero or two derived tests.
+sub triple_test($)
+{
+ my ($tests) = @_;
+ my @new;
+ foreach my $t (@$tests)
+ {
+ push @new, $t;
+
+ my @in;
+ 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;
+ defined $e->{IN}
+ and (push @in, $e->{IN}), next;
+ push @list_of_hash, $e;
+ }
+ # Add variants IFF there is exactly one input file.
+ @in == 1
+ or next;
+ shift @args; # discard test name
+ push @new, ["$t->[0].r", @args, '<', {IN => $in[0]}, @list_of_hash];
+ push @new, ["$t->[0].p", @args, {IN_PIPE => $in[0]}, @list_of_hash];
+ }
+ return @new;
+}
+
## package return
1;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3674d3f32..5d352b96b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 = cut head join pr sort tac tail test tr uniq
+SUBDIRS = cut join pr sort tac tail test tr uniq
root_tests = \
chown/basic \
@@ -124,6 +124,7 @@ TESTS = \
chgrp/posix-H \
chgrp/recurse \
misc/seq \
+ misc/head \
misc/head-elide-tail \
tail-2/tail-n0f \
misc/ls-misc \
diff --git a/tests/head/Test.pm b/tests/head/Test.pm
deleted file mode 100644
index ebe573515..000000000
--- a/tests/head/Test.pm
+++ /dev/null
@@ -1,108 +0,0 @@
-# Test "head".
-
-# Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2005 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/>.
-
-package Test;
-require 5.002;
-use strict;
-
-my @tv = (
-# test name, options, input, expected output, expected return code
-#
-['idem-0', '', "", "", 0],
-['idem-1', '', "a", "a", 0],
-['idem-2', '', "\n", "\n", 0],
-['idem-3', '', "a\n", "a\n", 0],
-
-['basic-0-10', '',
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
-
-['basic-0-09', '',
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n",
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n", 0],
-
-['basic-0-11', '',
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\nb\n",
- "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
-
-['obs-0', '-1', "1\n2\n", "1\n", 0],
-['obs-1', '-1c', "", "", 0],
-['obs-2', '-1c', "12", "1", 0],
-['obs-3', '-14c', "1234567890abcdefg", "1234567890abcd", 0],
-['obs-4', '-2b', [\'in'], [\'in-1024'], 0],
-['obs-5', '-1k', [\'in'], [\'in-1024'], 0],
-
-# This test fails for textutils-1.22, because head let 4096m overflow to 0
-# and did not fail. Now head fails with a diagnostic.
-
-# Disable this test because it fails on systems with 64-bit longs.
-# ['fail-0', '-n 4096m', "a\n", "", 1],
-
-# In spite of its name, this test passes -- just to contrast with the above.
-['fail-1', '-n 2048m', "a\n", "a\n", 0],
-
-# Make sure we don't break like AIX 4.3.1 on files with \0 in them.
-['null-1', '', "a\0a\n", "a\0a\n", 0],
-
-# Make sure counts are interpreted as decimal.
-# Before 2.0f, these would have been interpreted as octal
-['no-oct-1', '-08', "\n"x12, "\n"x8, 0],
-['no-oct-2', '-010', "\n"x12, "\n"x10, 0],
-['no-oct-3', '-n 08', "\n"x12, "\n"x8, 0],
-['no-oct-4', '-c 08', "\n"x12, "\n"x8, 0],
-
-);
-
-sub test_vector
-{
- my @derived_tests;
- foreach my $t (@tv)
- {
- my ($test_name, $flags, $in, $exp, $ret) = @$t;
-
- # Derive equivalent, posix-style tests from the obsolescent ones.
- next if $test_name !~ /^obs-/;
-
- $test_name =~ s/^obs-/posix-/;
- if ($flags =~ /-(\d+)$/)
- {
- $flags = "-n $1";
- }
- elsif ($flags =~ /-(\d+)([cbk])$/)
- {
- my $suffix = $2;
- $suffix = '' if $suffix eq 'c';
- $flags = "-c $1$suffix";
- }
- else
- {
- $flags = "-l $`";
- }
- push (@derived_tests, [$test_name, $flags, $in, $exp, $ret]);
- }
-
- foreach my $t (@tv, @derived_tests)
- {
- my ($test_name) = @$t;
- $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
- }
-
- return (@tv, @derived_tests);
-}
-
-1;
diff --git a/tests/head/in b/tests/head/in
deleted file mode 100644
index d5b2b7566..000000000
--- a/tests/head/in
+++ /dev/null
@@ -1,15 +0,0 @@
-8ca240627bbeaa9066aa9ba0ce6de080db8d19a6e26c423663c7a6e0185207841a467de16d80db
-c5a4a1ee35a8b13d4cc26cb47e05686db78cc71bc8c1e0769245988dd58d03974600b59872857c
-934cd484c093949db0676a3ac679a8bae4d41256959874c02ab792cb42ca33de72469a69d521aa
-060877520abad96725a85ace28072cd566b5b189e58331288d92e601c393ddad1eb60cddc46bb7
-4b7666dd9b8c36688cd3d0e6c4b091c5c6926b4468b19a40018d655d1840ed11da6a360bdc0e3c
-75355ad402c13a9c49228e11980eadb65a32070c1716b07074422534029bc6941981e65ae774e7
-6762616d66391aa2be539d2c2853e324429859ca998410ee54cc1521001804e5811bde40439d29
-bc8a304a58b823a69d1a2d5351993d1642b17398c031c8b7e78b451735e6326bb949141d3d5736
-2b03ad03c1ab427076be6e785722a18cc6846248e6b35483ec3aa85b2ae22bbb6e2919686a5a95
-a71785d1e1e12e1412cb14334dc7a591b83ed785474132993e69377ac4c1747a0db2a8cb1811ac
-722e7aa3e5c3d21c885bc6eeb2b0eb502476abe2d77691ce42587dd0934b44b568d2b113e12a39
-eb1853ec3a5c9ed7321b127422da35451a2e289c09ed2b19857922099275a0dd14ba2487180a85
-8d5e9796ad1c5c44d3a910a7623363718684b667a48a26e3ad85b008ce5a20e94ebe57da18edc6
-b661009a8a113ed6a922840da8d51c13ca4973b9a76dc05c142496c3083adcd8ba24686b471a77
-77ca4bb8
diff --git a/tests/head/in-1024 b/tests/head/in-1024
deleted file mode 100644
index 448aeaa6b..000000000
--- a/tests/head/in-1024
+++ /dev/null
@@ -1,13 +0,0 @@
-8ca240627bbeaa9066aa9ba0ce6de080db8d19a6e26c423663c7a6e0185207841a467de16d80db
-c5a4a1ee35a8b13d4cc26cb47e05686db78cc71bc8c1e0769245988dd58d03974600b59872857c
-934cd484c093949db0676a3ac679a8bae4d41256959874c02ab792cb42ca33de72469a69d521aa
-060877520abad96725a85ace28072cd566b5b189e58331288d92e601c393ddad1eb60cddc46bb7
-4b7666dd9b8c36688cd3d0e6c4b091c5c6926b4468b19a40018d655d1840ed11da6a360bdc0e3c
-75355ad402c13a9c49228e11980eadb65a32070c1716b07074422534029bc6941981e65ae774e7
-6762616d66391aa2be539d2c2853e324429859ca998410ee54cc1521001804e5811bde40439d29
-bc8a304a58b823a69d1a2d5351993d1642b17398c031c8b7e78b451735e6326bb949141d3d5736
-2b03ad03c1ab427076be6e785722a18cc6846248e6b35483ec3aa85b2ae22bbb6e2919686a5a95
-a71785d1e1e12e1412cb14334dc7a591b83ed785474132993e69377ac4c1747a0db2a8cb1811ac
-722e7aa3e5c3d21c885bc6eeb2b0eb502476abe2d77691ce42587dd0934b44b568d2b113e12a39
-eb1853ec3a5c9ed7321b127422da35451a2e289c09ed2b19857922099275a0dd14ba2487180a85
-8d5e9796ad1c5c44d3a910a7623363718684b667a48a26e3ad85b008ce5a20e94ebe57da18ed \ No newline at end of file
diff --git a/tests/misc/head b/tests/misc/head
new file mode 100755
index 000000000..d4d55e208
--- /dev/null
+++ b/tests/misc/head
@@ -0,0 +1,90 @@
+#!/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 = 'head';
+
+# Turn off localization of executable's output.
+@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+
+my $in = join ('', map { "$_\n" } 0..600);
+my $in_1024 = substr $in, 0, 1024;
+
+# FIXME: set this properly
+my $x32_bit_long = 0;
+
+my @Tests =
+(
+ ['idem-0', {IN=>''}, {OUT=>''}],
+ ['idem-1', {IN=>'a'}, {OUT=>'a'}],
+ ['idem-2', {IN=>"\n"}, {OUT=>"\n"}],
+ ['idem-3', {IN=>"a\n"}, {OUT=>"a\n"}],
+
+ ['basic-10',
+ {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"},
+ {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"}],
+
+ ['basic-09',
+ {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n"},
+ {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n"}],
+
+ ['basic-11',
+ {IN=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\nb\n"},
+ {OUT=>"1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n"}],
+
+ ['obs-0', '-1', {IN=>"1\n2\n"}, {OUT=>"1\n"}],
+ ['obs-1', '-1c', {IN=>''}, {OUT=>''}],
+ ['obs-2', '-1c', {IN=>'12'}, {OUT=>'1'}],
+ ['obs-3', '-14c', {IN=>'1234567890abcdefg'}, {OUT=>'1234567890abcd'}],
+ ['obs-4', '-2b', {IN=>$in}, {OUT=>$in_1024}],
+ ['obs-5', '-1k', {IN=>$in}, {OUT=>$in_1024}],
+
+ # This test fails for textutils-1.22, because head let 4096m overflow to 0
+ # and did not fail. Now head fails with a diagnostic.
+ # Disable this test because it fails on systems with 64-bit uintmax_t.
+ # ['fail-0', qw(-n 4096m), {IN=>"a\n"}, {EXIT=>1}],
+
+ # In spite of its name, this test passes -- just to contrast with the above.
+ ['fail-1', qw(-n 2048m), {IN=>"a\n"}, {OUT=>"a\n"}],
+
+ # Make sure we don't break like AIX 4.3.1 on files with \0 in them.
+ ['null-1', {IN=>"a\0a\n"}, {OUT=>"a\0a\n"}],
+
+ # Make sure counts are interpreted as decimal.
+ # Before 2.0f, these would have been interpreted as octal
+ ['no-oct-1', '-08', {IN=>"\n"x12}, {OUT=>"\n"x8}],
+ ['no-oct-2', '-010', {IN=>"\n"x12}, {OUT=>"\n"x10}],
+ ['no-oct-3', '-n 08', {IN=>"\n"x12}, {OUT=>"\n"x8}],
+ ['no-oct-4', '-c 08', {IN=>"\n"x12}, {OUT=>"\n"x8}],
+);
+
+@Tests = triple_test \@Tests;
+
+my $save_temps = $ENV{DEBUG};
+my $verbose = $ENV{VERBOSE};
+
+my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
+exit $fail;
+EOF