/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. # Test that a getdate executable meets its specification.
  3. #
  4. # Copyright (C) 2004 Free Software Foundation, Inc.
  5. #
  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 2, or (at your option)
  9. # any later version.
  10. #
  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.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  19. # Why are these dates tested?
  20. #
  21. # February 29, 2003
  22. # Is not a leap year - should be invalid.
  23. #
  24. # 2004-12-40
  25. # Make sure get_date does not "roll" date forward to January 9th. Some
  26. # versions have been known to do this.
  27. #
  28. # Dec-5-1972
  29. # This is my birthday. :)
  30. #
  31. # 3/29/1974
  32. # 1996/05/12 13:57:45
  33. # Because.
  34. #
  35. # 12-05-12
  36. # This will be my 40th birthday. Ouch. :)
  37. #
  38. # 05/12/96
  39. # Because.
  40. #
  41. # third tuesday in March, 2078
  42. # Wanted this to work.
  43. #
  44. # 1969-12-32 2:00:00 UTC
  45. # 1970-01-01 2:00:00 UTC
  46. # 1969-12-32 2:00:00 +0400
  47. # 1970-01-01 2:00:00 +0400
  48. # 1969-12-32 2:00:00 -0400
  49. # 1970-01-01 2:00:00 -0400
  50. # Playing near the UNIX Epoch boundry condition to make sure date rolling
  51. # is also disabled there.
  52. #
  53. # 1996-12-12 1 month
  54. # Test a relative date.
  55. #
  56. # Tue Jan 19 03:14:07 2038 +0000
  57. # For machines with 31-bit time_t, any date past this date will be an
  58. # invalid date. So, any test date with a value greater than this
  59. # time is not portable.
  60. #
  61. # Feb. 29, 2096 4 years
  62. # 4 years from this date is _not_ a leap year, so Feb. 29th does not exist.
  63. #
  64. # Feb. 29, 2096 8 years
  65. # 8 years from this date is a leap year, so Feb. 29th does exist,
  66. # but on many hosts with 32-bit time_t types time, this test will
  67. # fail. So, this is not a portable test.
  68. #
  69. TZ=UTC0; export TZ
  70. cat >getdate-expected <<EOF
  71. Enter date, or blank line to exit.
  72. > Bad format - couldn't convert.
  73. > Bad format - couldn't convert.
  74. > Bad format - couldn't convert.
  75. > Fri Mar 29 00:00:00 1974
  76. > Sun May 12 13:57:45 1996
  77. > Sat May 12 00:00:00 2012
  78. > Sun May 12 00:00:00 1996
  79. > Bad format - couldn't convert.
  80. > Bad format - couldn't convert.
  81. > Thu Jan 1 02:00:00 1970
  82. > Bad format - couldn't convert.
  83. > Bad format - couldn't convert.
  84. > Bad format - couldn't convert.
  85. > Thu Jan 1 06:00:00 1970
  86. > Sun Jan 12 00:00:00 1997
  87. >
  88. EOF
  89. ./getdate >getdate-got <<EOF
  90. February 29, 2003
  91. 2004-12-40
  92. Dec-5-1972
  93. 3/29/1974
  94. 1996/05/12 13:57:45
  95. 12-05-12
  96. 05/12/96
  97. third tuesday in March, 2078
  98. 1969-12-32 2:00:00 UTC
  99. 1970-01-01 2:00:00 UTC
  100. 1969-12-32 2:00:00 +0400
  101. 1970-01-01 2:00:00 +0400
  102. 1969-12-32 2:00:00 -0400
  103. 1970-01-01 2:00:00 -0400
  104. 1996-12-12 1 month
  105. EOF
  106. echo >>getdate-got
  107. if cmp getdate-expected getdate-got >getdate.cmp; then :; else
  108. LOGFILE=`pwd`/getdate.log
  109. cat getdate.cmp >${LOGFILE}
  110. echo "** expected: " >>${LOGFILE}
  111. cat getdate-expected >>${LOGFILE}
  112. echo "** got: " >>${LOGFILE}
  113. cat getdate-got >>${LOGFILE}
  114. echo "FAIL: getdate" | tee -a ${LOGFILE}
  115. echo "Failed! See ${LOGFILE} for more!" >&2
  116. exit 1
  117. fi
  118. rm getdate-expected getdate-got getdate.cmp
  119. exit 0