logo

utils-extra

Collection of extra tools for Unixes

date (2779B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. atf_test_case noargs
  5. noargs_body() {
  6. atf_check -o not-empty ../cmd/date
  7. }
  8. atf_test_case badarg
  9. badarg_body() {
  10. atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\ndate [-uR][-d datetime] [+format]\n" ../cmd/date -x
  11. }
  12. atf_test_case epoch
  13. epoch_body() {
  14. atf_check -o "match:^[0-9]+$" ../cmd/date '+%s'
  15. atf_check -o "inline:1155544496\n" ../cmd/date -uR -d @1155544496 '+%s'
  16. }
  17. atf_test_case rfc3339
  18. rfc3339_body() {
  19. atf_check -o "match:^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{4}$" ../cmd/date '+%FT%T%z'
  20. atf_check -o "match:^2006\-08\-14T08:34:56[+\-]00:?00$" ../cmd/date -uR -d @1155544496 '+%FT%T%z'
  21. }
  22. atf_test_case rfc5322
  23. rfc5322_body() {
  24. atf_check -o "match:^Mon, 14 Aug 2006 08:34:56 [+\-]00:?00$" ../cmd/date -uR -d @1155544496
  25. }
  26. atf_test_case empty
  27. empty_body() {
  28. atf_check -o 'inline:\n' ../cmd/date '+'
  29. }
  30. atf_test_case echolike
  31. echolike_body() {
  32. atf_check -o 'inline:hello world\n' ../cmd/date '+hello world'
  33. }
  34. atf_test_case devfull
  35. devfull_body() {
  36. has_glibc && atf_expect_fail "glibc ignoring write errors for puts()"
  37. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
  38. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
  39. atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full'
  40. }
  41. atf_test_case utc
  42. utc_body() {
  43. atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s'
  44. }
  45. atf_test_case timestamp
  46. timestamp_body() {
  47. atf_check -o "inline:1970-01-01T00:00:00\n" ../cmd/date -u -d @0 '+%FT%T'
  48. atf_check -o "inline:1970-01-01T00:01:09\n" ../cmd/date -u -d @69 '+%FT%T'
  49. atf_check -o "inline:1969-12-31T23:58:51\n" ../cmd/date -u -d @-69 '+%FT%T'
  50. atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\ndate [-uR][-d datetime] [+format]\n" ../cmd/date -u -d
  51. # 36893488147419103232 = 2^65
  52. atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232
  53. }
  54. atf_test_case isodate
  55. isodate_body() {
  56. atf_check -o "inline:0\n" ../cmd/date -u -d "1970-01-01T00:00:00Z" '+%s'
  57. atf_check -o "inline:69\n" ../cmd/date -u -d "1970-01-01T00:01:09Z" '+%s'
  58. atf_check -o "inline:-69\n" ../cmd/date -u -d "1969-12-31T23:58:51Z" '+%s'
  59. }
  60. atf_init_test_cases() {
  61. cd "$(atf_get_srcdir)" || exit 1
  62. . ../test_functions.sh
  63. atf_add_test_case noargs
  64. atf_add_test_case badarg
  65. atf_add_test_case empty
  66. atf_add_test_case echolike
  67. atf_add_test_case devfull
  68. atf_add_test_case epoch
  69. atf_add_test_case rfc3339
  70. atf_add_test_case rfc5322
  71. atf_add_test_case utc
  72. atf_add_test_case timestamp
  73. atf_add_test_case isodate
  74. }