2 # $MirOS: src/gnu/usr.bin/cvs/lib/test-getdate.sh,v 1.2 2016/10/22 15:34:32 tg Exp $
4 # Test that a getdate executable meets its specification.
6 # Copyright (C) 2004 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 # as this uses POSIX behaviour and does not count leap seconds...
24 if test -n "$GETDATE_LD_PRELOAD"; then
25 LD_PRELOAD=$GETDATE_LD_PRELOAD
32 LOGFILE=`pwd`/getdate.log
33 if test -f "$LOGFILE"; then
45 if cmp getdate-expected getdate-got >getdate.cmp; then
46 echo "PASS: $1" >>$LOGFILE
48 cat getdate.cmp >>$LOGFILE
49 echo "** expected: " >>$LOGFILE
50 cat getdate-expected >>$LOGFILE
51 echo "** got: " >>$LOGFILE
52 cat getdate-got >>$LOGFILE
53 echo "FAIL: $1" | tee -a $LOGFILE >&2
54 echo "Failed! See $LOGFILE for more!" >&2
63 echo "SKIP: $1"${2+" ($2)"} >>$LOGFILE
68 # Prep for future calls to valid_timezone().
70 # This should set $UTZ to three spaces, `GMT', `Unrecognized/Unrecognized', or
71 # possibly the empty string, depending on what system we are running on. With
72 # any luck, this will catch any other existing variations as well. The way it
73 # is used later does have the disadvantage of rejecting at least the
74 # `Europe/London' timezone for half the year when $UTZ gets set to `GMT', like
75 # happens on NetBSD, but, since I haven't come up with any better ideas and
76 # since rejecting a timezone just causes a few tests to be skipped, this will
79 # UTZ stands for Unrecognized Time Zone.
80 UTZ=`TZ=Unrecognized/Unrecognized date +%Z`
82 # The following function will return true if $1 is a valid timezone. It will
83 # return false and set $skipreason, otherwise.
85 # Clobbers $NTZ & $skipreason.
87 # SUS2 says `date +%Z' will return `no characters' if `no timezone is
88 # determinable'. It is, unfortunately, not very specific about what
89 # `determinable' means. On GNU/Linux, `date +%Z' returns $TZ when $TZ is not
90 # recognized. NetBSD 1.6.1 "determines" that an unrecognizable value in $TZ
91 # really means `GMT'. On Cray, the standard is ignored and `date +%Z' returns
92 # three spaces when $TZ is not recognized. We test for all three cases, plus
93 # the empty string for good measure, though I know of no set of conditions
94 # which will actually cause `date +%Z' to return the empty string SUS2
97 # Due to the current nature of this test, this will not work for the
98 # three-letter zone codes on some systems. e.g.:
100 # test `TZ=EST date +%Z` = "EST"
102 # should, quite correctly, evaluate to true on most systems, but:
104 # TZ=Asia/Calcutta date +%Z
106 # would return `IST' on GNU/Linux, and hopefully any system which understands
107 # the `Asia/Calcutta' timezone, and ` ' on Cray. Similarly:
109 # TZ=Doesnt_Exist/Doesnt_Exist date +%Z
111 # returns `Doesnt_Exist/Doesnt_Exist' on GNU/Linux and ` ' on Cray.
113 # Unfortunately, the %z date format string (-HHMM format time zone) supported
114 # by the GNU `date' command is not part of any standard I know of and,
115 # therefore, is probably not portable.
120 if test "$NTZ" = "$UTZ" || test "$NTZ" = "$1"; then
121 skipreason="$1 is not a recognized timezone on this system"
133 # Why are these dates tested?
136 # Is not a leap year - should be invalid.
139 # Make sure get_date does not "roll" date forward to January 9th. Some
140 # versions have been known to do this.
143 # This is my birthday. :)
146 # 1996/05/12 13:57:45
150 # This will be my 40th birthday. Ouch. :)
155 # third tuesday in March, 2078
156 # Wanted this to work.
158 # 1969-12-32 2:00:00 UTC
159 # 1970-01-01 2:00:00 UTC
160 # 1969-12-32 2:00:00 +0400
161 # 1970-01-01 2:00:00 +0400
162 # 1969-12-32 2:00:00 -0400
163 # 1970-01-01 2:00:00 -0400
164 # Playing near the UNIX Epoch boundry condition to make sure date rolling
165 # is also disabled there.
168 # Test a relative date.
172 # The following tests are currently being skipped for being unportable:
174 # Tue Jan 19 03:14:07 2038 +0000
175 # For machines with 31-bit time_t, any date past this date will be an
176 # invalid date. So, any test date with a value greater than this
177 # time is not portable.
179 # Feb. 29, 2096 4 years
180 # 4 years from this date is _not_ a leap year, so Feb. 29th does not exist.
182 # Feb. 29, 2096 8 years
183 # 8 years from this date is a leap year, so Feb. 29th does exist,
184 # but on many hosts with 32-bit time_t types time, this test will
185 # fail. So, this is not a portable test.
190 cat >getdate-expected <<EOF
191 Enter date, or blank line to exit.
192 > Bad format - couldn't convert.
193 > Bad format - couldn't convert.
194 > 92361600 = 1972-12-05 00:00:00.000000000
195 > 133747200 = 1974-03-29 00:00:00.000000000
196 > 831909465 = 1996-05-12 13:57:45.000000000
197 > 1336780800 = 2012-05-12 00:00:00.000000000
198 > 831859200 = 1996-05-12 00:00:00.000000000
199 > Bad format - couldn't convert.
200 > Bad format - couldn't convert.
201 > 7200 = 1970-01-01 02:00:00.000000000
202 > Bad format - couldn't convert.
203 > -7200 = 1969-12-31 22:00:00.000000000
204 > Bad format - couldn't convert.
205 > 21600 = 1970-01-01 06:00:00.000000000
206 > 853027200 = 1997-01-12 00:00:00.000000000
210 ./getdate >getdate-got <<EOF
218 third tuesday in March, 2078
219 1969-12-32 2:00:00 UTC
220 1970-01-01 2:00:00 UTC
221 1969-12-32 2:00:00 +0400
222 1970-01-01 2:00:00 +0400
223 1969-12-32 2:00:00 -0400
224 1970-01-01 2:00:00 -0400
232 # Why are these dates tested?
234 # Ian Abbot reported these odd boundry cases. After daylight savings time went
235 # into effect, non-daylight time zones would cause
236 # "Bad format - couldn't convert." errors, even when the non-daylight zone
237 # happened to be a universal one, like GMT.
239 TZ=Europe/London; export TZ
240 if valid_timezone $TZ; then
241 cat >getdate-expected <<EOF
242 Enter date, or blank line to exit.
243 > 1109635200 = 2005-03-01 00:00:00.000000000
244 > 1111881600 = 2005-03-27 00:00:00.000000000
245 > 1111968000 = 2005-03-28 01:00:00.000000000
246 > 1111968000 = 2005-03-28 01:00:00.000000000
247 > 1112054400 = 2005-03-29 01:00:00.000000000
248 > 1112054400 = 2005-03-29 01:00:00.000000000
249 > 1112140800 = 2005-03-30 01:00:00.000000000
250 > 1112140800 = 2005-03-30 01:00:00.000000000
251 > 1112227200 = 2005-03-31 01:00:00.000000000
252 > 1112227200 = 2005-03-31 01:00:00.000000000
253 > 1112313600 = 2005-04-01 01:00:00.000000000
254 > 1112313600 = 2005-04-01 01:00:00.000000000
255 > 1113091200 = 2005-04-10 01:00:00.000000000
256 > 1113091200 = 2005-04-10 01:00:00.000000000
257 > 1112310000 = 2005-04-01 00:00:00.000000000
261 ./getdate >getdate-got <<EOF
281 skip getdate-2 "$skipreason"
286 # Many of the following cases were also submitted by Ian Abbott, but the same
287 # errors are not exhibited. The original problem had a similar root, but
288 # managed to produce errors with GMT, which is considered a "Universal Zone".
291 # The deeper problem has to do with "local zone" processing in getdate.y
292 # that causes local daylight zones to be excluded when local standard time is
293 # in effect and vice versa. This used to cause trouble with GMT in Britian
294 # when British Summer Time was in effect, but this was overridden for the
295 # "Universal Timezones" (GMT, UTC, & UT), that might double as a local zone in
296 # some locales. We still see in these tests the local daylight/standard zone
297 # exclusion in EST/EDT. According to Paul Eggert in a message to
298 # bug-gnulib@gnu.org on 2005-04-12, this is considered a bug but may not be
299 # fixed soon due to its complexity.
301 TZ=America/New_York; export TZ
302 if valid_timezone $TZ; then
303 cat >getdate-expected <<EOF
304 Enter date, or blank line to exit.
305 > 1109653200 = 2005-03-01 00:00:00.000000000
306 > 1109631600 = 2005-02-28 18:00:00.000000000
307 > 1112331600 = 2005-04-01 00:00:00.000000000
308 > Bad format - couldn't convert.
309 > 1114902000 = 2005-04-30 19:00:00.000000000
310 > 1114905600 = 2005-04-30 20:00:00.000000000
311 > 1114920000 = 2005-05-01 00:00:00.000000000
312 > 1114905600 = 2005-04-30 20:00:00.000000000
313 > Bad format - couldn't convert.
314 > 1117580400 = 2005-05-31 19:00:00.000000000
315 > 1117584000 = 2005-05-31 20:00:00.000000000
316 > 1117598400 = 2005-06-01 00:00:00.000000000
317 > 1117584000 = 2005-05-31 20:00:00.000000000
321 ./getdate >getdate-got <<EOF
339 skip getdate-3 "$skipreason"
344 rm getdate-expected getdate-got getdate.cmp