logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

date (2196B)


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