1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-15 16:26:01 +02:00
Files
coreutils/tests/misc/date-next-dow
Jim Meyering 1560848265 tests: write skip explanation from perl scripts also to outer stderr
* tests/CuSkip.pm (skip): New file/module/function, to help
the perl test scripts "skip" a test consistently, emitting
a diagnostic both into the log file and into the outermost
stderr stream that is more likely to be seen by a human.
* tests/check.mk (TESTS_ENVIRONMENT): Add -MCuSkip.
* tests/misc/date-next-dow: Use CuSkip::skip in place of warn+exit-77.
* tests/misc/tty-eof: Likewise.
* tests/misc/uniq: Likewise.
* tests/rm/fail-eperm: Likewise.
* tests/misc/md5sum-newline: Likewise.  Also, s/program_name/ME/.
* tests/misc/ls-misc (setuid_setup, main): Likewise.
* tests/misc/pwd-long: Likewise, and add -I"$abs_srcdir" -MCuSkip
to the $PERL invocation command.
Inspired by a request from Bruno Haible regarding misc/tty-eof:
http://debbugs.gnu.org/8570
2011-04-28 22:43:56 +02:00

79 lines
2.3 KiB
Perl
Executable File

#!/usr/bin/perl
# Test "date".
# Copyright (C) 2005-2011 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;
use POSIX qw(strftime);
(my $ME = $0) =~ s|.*/||;
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
# Export TZ=UTC0 so that zone-dependent strings match.
$ENV{TZ} = 'UTC0';
my $now = time;
my @d = localtime ($now);
my @d_week = localtime ($now + 7 * 24 * 3600);
my $wday = $d[6];
my $wday_str = qw(sun mon tue wed thu fri sat)[$wday];
my @Tests =
(
# test-name, [option, option, ...] {OUT=>"expected-output"}
#
# Running "date -d mon +%a" on a Monday must print Mon.
['dow', "-d $wday_str +%a", {OUT => ucfirst $wday_str}],
# It had better be the same date, too.
['dow2', "-d $wday_str +%Y-%m-%d", {OUT => strftime("%Y-%m-%d", @d)}],
['next-dow', "-d 'next $wday_str' +%Y-%m-%d",
{OUT => strftime("%Y-%m-%d", @d_week)}],
);
# Append "\n" to each OUT=> RHS if the expected exit value is either
# zero or not specified (defaults to zero).
foreach my $t (@Tests)
{
my $exit_val;
foreach my $e (@$t)
{
ref $e && ref $e eq 'HASH' && defined $e->{EXIT}
and $exit_val = $e->{EXIT};
}
foreach my $e (@$t)
{
ref $e && ref $e eq 'HASH' && defined $e->{OUT} && ! $exit_val
and $e->{OUT} .= "\n";
}
}
my $save_temps = $ENV{DEBUG};
my $verbose = $ENV{VERBOSE};
my $prog = 'date';
my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose);
# Skip the test if the starting and stopping day numbers differ.
my @d_post = localtime (time);
$d_post[7] == $d[7]
or CuSkip::skip "$ME: test straddled a day boundary; skipped";
exit $fail;