date (2196B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- atf_test_case noargs
- noargs_body() {
- atf_check -o not-empty ../bin/date
- }
- atf_test_case badarg
- badarg_body() {
- atf_check -s 'exit:1' -e "inline:Error: Unrecognised option: '-x'\ndate [-u][-d datetime] [+format]\n" ../bin/date -x
- }
- atf_test_case epoch
- epoch_body() {
- atf_check -o "match:^[0-9]+$" ../bin/date '+%s'
- }
- atf_test_case rfc3339
- rfc3339_body() {
- 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'
- }
- atf_test_case empty
- empty_body() {
- atf_check -o 'inline:\n' ../bin/date '+'
- }
- atf_test_case echolike
- echolike_body() {
- atf_check -o 'inline:hello world\n' ../bin/date '+hello world'
- }
- atf_test_case devfull
- devfull_body() {
- has_glibc && atf_expect_fail "glibc ignoring write errors for puts()"
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
- atf_check -s exit:1 -e 'inline:puts: No space left on device\n' sh -c '../bin/date >/dev/full'
- }
- atf_test_case utc
- utc_body() {
- atf_check -o "match:^[0-9]+$" ../bin/date -u '+%s'
- }
- atf_test_case timestamp
- timestamp_body() {
- atf_check -o "inline:1970-01-01T00:00:00\n" ../bin/date -u -d @0 '+%FT%T'
- atf_check -o "inline:1970-01-01T00:01:09\n" ../bin/date -u -d @69 '+%FT%T'
- atf_check -o "inline:1969-12-31T23:58:51\n" ../bin/date -u -d @-69 '+%FT%T'
- atf_check -s 'exit:1' -e "inline:Error: Missing operand for option: '-d'\ndate [-u][-d datetime] [+format]\n" ../bin/date -u -d
- atf_check -s 'exit:1' ../bin/date -u -d 69
- # 36893488147419103232 = 2^65
- atf_check -s 'exit:1' -e not-empty ../bin/date -u -d @36893488147419103232
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case noargs
- atf_add_test_case badarg
- atf_add_test_case empty
- atf_add_test_case echolike
- atf_add_test_case devfull
- atf_add_test_case epoch
- atf_add_test_case rfc3339
- atf_add_test_case utc
- atf_add_test_case timestamp
- }