rm: remove no-op -d option
[coreutils.git] / tests / misc / date-next-dow
blobcd9d8cd4a765ec4edab94d663114735e602c6773
1 #!/usr/bin/perl
2 # Test "date".
4 # Copyright (C) 2005-2010 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
20 use POSIX qw(strftime);
22 (my $ME = $0) =~ s|.*/||;
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
27 # Export TZ=UTC0 so that zone-dependent strings match.
28 $ENV{TZ} = 'UTC0';
30 my $now = time;
31 my @d = localtime ($now);
32 my @d_week = localtime ($now + 7 * 24 * 3600);
33 my $wday = $d[6];
34 my $wday_str = qw(sun mon tue wed thu fri sat)[$wday];
36 my @Tests =
38 # test-name, [option, option, ...] {OUT=>"expected-output"}
41 # Running "date -d mon +%a" on a Monday must print Mon.
42 ['dow', "-d $wday_str +%a", {OUT => ucfirst $wday_str}],
43 # It had better be the same date, too.
44 ['dow2', "-d $wday_str +%Y-%m-%d", {OUT => strftime("%Y-%m-%d", @d)}],
46 ['next-dow', "-d 'next $wday_str' +%Y-%m-%d",
47 {OUT => strftime("%Y-%m-%d", @d_week)}],
50 # Append "\n" to each OUT=> RHS if the expected exit value is either
51 # zero or not specified (defaults to zero).
52 foreach my $t (@Tests)
54 my $exit_val;
55 foreach my $e (@$t)
57 ref $e && ref $e eq 'HASH' && defined $e->{EXIT}
58 and $exit_val = $e->{EXIT};
60 foreach my $e (@$t)
62 ref $e && ref $e eq 'HASH' && defined $e->{OUT} && ! $exit_val
63 and $e->{OUT} .= "\n";
67 my $save_temps = $ENV{DEBUG};
68 my $verbose = $ENV{VERBOSE};
70 my $prog = 'date';
71 my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose);
73 # Skip the test if the starting and stopping day numbers differ.
74 my @d_post = localtime (time);
75 $d_post[7] == $d[7]
76 or (warn "$ME: test straddled a day boundary; skipped"), exit 77;
78 exit $fail;