PageRenderTime 36ms CodeModel.GetById 26ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/cvs/lib/test-getdate.sh

https://bitbucket.org/freebsd/freebsd-head/
Shell | 127 lines | 51 code | 8 blank | 68 comment | 2 complexity | baf9e190a909cde381548c2bf7e989a1 MD5 | raw file
  1#! /bin/sh
  2
  3# Test that a getdate executable meets its specification.
  4#
  5# Copyright (C) 2004 Free Software Foundation, Inc.
  6#
  7# This program is free software; you can redistribute it and/or modify
  8# it under the terms of the GNU General Public License as published by
  9# the Free Software Foundation; either version 2, or (at your option)
 10# any later version.
 11#
 12# This program is distributed in the hope that it will be useful,
 13# but WITHOUT ANY WARRANTY; without even the implied warranty of
 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15# GNU General Public License for more details.
 16#
 17# You should have received a copy of the GNU General Public License
 18# along with this program; if not, write to the Free Software Foundation,
 19# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 20
 21# Why are these dates tested?
 22#
 23# February 29, 2003
 24#   Is not a leap year - should be invalid.
 25#
 26# 2004-12-40
 27#   Make sure get_date does not "roll" date forward to January 9th.  Some
 28#   versions have been known to do this.
 29#
 30# Dec-5-1972
 31#   This is my birthday.  :)
 32#
 33# 3/29/1974
 34# 1996/05/12 13:57:45
 35#   Because.
 36#
 37# 12-05-12
 38#   This will be my 40th birthday.  Ouch.  :)
 39#
 40# 05/12/96
 41#   Because.
 42#
 43# third tuesday in March, 2078
 44#   Wanted this to work.
 45#
 46# 1969-12-32 2:00:00 UTC
 47# 1970-01-01 2:00:00 UTC
 48# 1969-12-32 2:00:00 +0400
 49# 1970-01-01 2:00:00 +0400
 50# 1969-12-32 2:00:00 -0400
 51# 1970-01-01 2:00:00 -0400
 52#   Playing near the UNIX Epoch boundry condition to make sure date rolling
 53#   is also disabled there.
 54#
 55# 1996-12-12 1 month
 56#   Test a relative date.
 57#
 58# Tue Jan 19 03:14:07 2038 +0000
 59#   For machines with 31-bit time_t, any date past this date will be an
 60#   invalid date. So, any test date with a value greater than this
 61#   time is not portable.
 62#
 63# Feb. 29, 2096 4 years
 64#   4 years from this date is _not_ a leap year, so Feb. 29th does not exist.
 65#
 66# Feb. 29, 2096 8 years
 67#   8 years from this date is a leap year, so Feb. 29th does exist,
 68#   but on many hosts with 32-bit time_t types time, this test will
 69#   fail. So, this is not a portable test.
 70#
 71
 72TZ=UTC0; export TZ
 73
 74cat >getdate-expected <<EOF
 75Enter date, or blank line to exit.
 76	> Bad format - couldn't convert.
 77	> Bad format - couldn't convert.
 78	> Bad format - couldn't convert.
 79	> Fri Mar 29 00:00:00 1974
 80	> Sun May 12 13:57:45 1996
 81	> Sat May 12 00:00:00 2012
 82	> Sun May 12 00:00:00 1996
 83	> Bad format - couldn't convert.
 84	> Bad format - couldn't convert.
 85	> Thu Jan  1 02:00:00 1970
 86	> Bad format - couldn't convert.
 87	> Bad format - couldn't convert.
 88	> Bad format - couldn't convert.
 89	> Thu Jan  1 06:00:00 1970
 90	> Sun Jan 12 00:00:00 1997
 91	> 
 92EOF
 93
 94./getdate >getdate-got <<EOF
 95February 29, 2003
 962004-12-40
 97Dec-5-1972
 983/29/1974
 991996/05/12 13:57:45
10012-05-12
10105/12/96
102third tuesday in March, 2078
1031969-12-32 2:00:00 UTC
1041970-01-01 2:00:00 UTC
1051969-12-32 2:00:00 +0400
1061970-01-01 2:00:00 +0400
1071969-12-32 2:00:00 -0400
1081970-01-01 2:00:00 -0400
1091996-12-12 1 month
110EOF
111
112echo >>getdate-got
113
114if cmp getdate-expected getdate-got >getdate.cmp; then :; else
115	LOGFILE=`pwd`/getdate.log
116	cat getdate.cmp >${LOGFILE}
117	echo "** expected: " >>${LOGFILE}
118	cat getdate-expected >>${LOGFILE}
119	echo "** got: " >>${LOGFILE}
120	cat getdate-got >>${LOGFILE}
121	echo "FAIL: getdate" | tee -a ${LOGFILE}
122	echo "Failed!  See ${LOGFILE} for more!" >&2
123	exit 1
124fi
125
126rm getdate-expected getdate-got getdate.cmp
127exit 0