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/>.
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.
31 my @d = localtime ($now);
32 my @d_week = localtime ($now + 7 * 24 * 3600);
34 my $wday_str = qw(sun mon tue wed thu fri sat)[$wday];
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)
57 ref $e && ref $e eq 'HASH' && defined $e->{EXIT
}
58 and $exit_val = $e->{EXIT
};
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
};
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);
76 or (warn "$ME: test straddled a day boundary; skipped"), exit 77;