commit: 8bd3564a02f6a33bc9bd650c7b6490c9e9ec39e7
parent d29156f63aa3173a454b2c7984e6b45c1c9b213e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 13 Jun 2024 12:46:10 +0200
test-cmd/date*: Change from ATF to tap.sh
Diffstat:
3 files changed, 57 insertions(+), 109 deletions(-)
diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile
@@ -9,7 +9,6 @@ basedir = fs.dirname(fs.dirname(current_kyuafile()))
-- 9,$|LC_ALL=C.UTF-8 sort
atf_test_program{name="base64", required_files=basedir.."/cmd/base64", timeout=1}
atf_test_program{name="cat", required_files=basedir.."/cmd/cat", timeout=1}
-atf_test_program{name="date", required_files=basedir.."/cmd/date", timeout=1}
atf_test_program{name="df", required_files=basedir.."/cmd/df", timeout=1}
atf_test_program{name="dirname", required_files=basedir.."/cmd/dirname", timeout=1}
atf_test_program{name="echo", required_files=basedir.."/cmd/echo", timeout=1}
@@ -28,6 +27,7 @@ atf_test_program{name="unlink", required_files=basedir.."/cmd/unlink", timeout=1
tap_test_program{name="arch.sh", required_files=basedir.."/cmd/arch", timeout=1}
tap_test_program{name="basename.sh", required_files=basedir.."/cmd/basename", timeout=1}
tap_test_program{name="chmod.sh", required_files=basedir.."/cmd/chmod", timeout=1}
+tap_test_program{name="date.sh", required_files=basedir.."/cmd/date", timeout=1}
tap_test_program{name="seq.sh", required_files=basedir.."/cmd/seq", timeout=1}
tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2}
tap_test_program{name="uname.sh", required_files=basedir.."/cmd/uname", timeout=1}
diff --git a/test-cmd/date b/test-cmd/date
@@ -1,108 +0,0 @@
-#!/usr/bin/env atf-sh
-# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
-# SPDX-License-Identifier: MPL-2.0
-
-usage="\
-date [-uR] [-d datetime] [+format]
-date [-uR] -f now_format now [+format]
-"
-
-atf_test_case noargs
-noargs_body() {
- atf_check -o not-empty ../cmd/date
-}
-
-atf_test_case badarg
-badarg_body() {
- atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\n${usage}" ../cmd/date -x
-}
-
-atf_test_case epoch
-epoch_body() {
- atf_check -o "match:^[0-9]+$" ../cmd/date '+%s'
- atf_check -o "inline:1155544496\n" ../cmd/date -uR -d @1155544496 '+%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}$" ../cmd/date '+%FT%T%z'
- atf_check -o "match:^2006\-08\-14T08:34:56[+\-]00:?00$" ../cmd/date -uR -d @1155544496 '+%FT%T%z'
-}
-
-atf_test_case rfc5322
-rfc5322_body() {
- atf_check -o "match:^Mon, 14 Aug 2006 08:34:56 [+\-]00:?00$" ../cmd/date -uR -d @1155544496
-}
-
-atf_test_case empty
-empty_body() {
- atf_check -o 'inline:\n' ../cmd/date '+'
-}
-
-atf_test_case echolike
-echolike_body() {
- atf_check -o 'inline:hello world\n' ../cmd/date '+hello world'
-}
-
-atf_test_case devfull
-devfull_body() {
- has_glibc && atf_skip "glibc ignoring write errors for puts()"
- [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
-
- atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full'
-}
-
-atf_test_case utc
-utc_body() {
- atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s'
-}
-
-atf_test_case timestamp
-timestamp_body() {
- atf_check -o "inline:1970-01-01T00:00:00\n" ../cmd/date -u -d @0 '+%FT%T'
- atf_check -o "inline:1970-01-01T00:01:09\n" ../cmd/date -u -d @69 '+%FT%T'
- atf_check -o "inline:1969-12-31T23:58:51\n" ../cmd/date -u -d @-69 '+%FT%T'
-
- atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\n${usage}" ../cmd/date -u -d
-
- # 36893488147419103232 = 2^65
- atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232
-}
-
-atf_test_case isodate
-isodate_body() {
- atf_check -o "inline:0\n" ../cmd/date -u -d "1970-01-01T00:00:00Z" '+%s'
- atf_check -o "inline:69\n" ../cmd/date -u -d "1970-01-01T00:01:09Z" '+%s'
- atf_check -o "inline:-69\n" ../cmd/date -u -d "1969-12-31T23:58:51Z" '+%s'
- atf_check -o "inline:-69\n" ../cmd/date -u -d "1969-12-31T23:58:51.00Z" '+%s'
- atf_check -o "inline:-69\n" ../cmd/date -u -d "1969-12-31T23:58:51,00Z" '+%s'
-}
-
-atf_test_case now_format
-now_format_body() {
- # Note: POSIX doesn't specifies %s for strptime(3)
- atf_check -o "inline:1155544496\n" ../cmd/date -u -f '%Y-%m-%dT%H:%M:%S' '2006-08-14T08:34:56' '+%s'
-}
-
-
-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 rfc5322
- atf_add_test_case utc
-
- atf_add_test_case timestamp
- atf_add_test_case isodate
- atf_add_test_case now_format
-}
diff --git a/test-cmd/date.sh b/test-cmd/date.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+target="$(dirname "$0")/../cmd/date"
+plans=15
+. "$(dirname "$0")/tap.sh"
+
+unset TZ
+
+t 'noargs' '' "$(date +%c)"$'\n'
+t 'epoch' '-u -d @1155544496 +%s' '1155544496'$'\n'
+t 'rfc3339' '-u -d @1155544496 +%FT%T%z' '2006-08-14T08:34:56+0000'$'\n'
+t 'rfc5322' '-u -d @1155544496 -R' 'Mon, 14 Aug 2006 08:34:56 +0000'$'\n'
+t 'empty' '+' ''$'\n'
+t 'echolike' '+hello_world' 'hello_world'$'\n'
+
+t '@0' '-u -d @0 +%FT%T' '1970-01-01T00:00:00'$'\n'
+t '@69' '-u -d @69 +%FT%T' '1970-01-01T00:01:09'$'\n'
+t '@-69' '-u -d @-69 +%FT%T' '1969-12-31T23:58:51'$'\n'
+
+t '1970-01-01T00:00:00Z' '-u -d 1970-01-01T00:00:00Z +%s' '0'$'\n'
+t '1970-01-01T00:01:09Z' '-u -d 1970-01-01T00:01:09Z +%s' '69'$'\n'
+t '1969-12-31T23:58:51Z' '-u -d 1969-12-31T23:58:51Z +%s' '-69'$'\n'
+t '1969-12-31T23:58:51.00Z' '-u -d 1969-12-31T23:58:51.00Z +%s' '-69'$'\n'
+t '1969-12-31T23:58:51,00Z' '-u -d 1969-12-31T23:58:51,00Z +%s' '-69'$'\n'
+
+t 'f_option' '-u -f %Y-%m-%dT%H:%M:%S 2006-08-14T08:34:56 +%s' '1155544496'$'\n'
+
+#usage="\
+#date [-uR] [-d datetime] [+format]
+#date [-uR] -f now_format now [+format]
+#"
+# atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\n${usage}" ../cmd/date -x
+
+#atf_test_case devfull
+#devfull_body() {
+# has_glibc && atf_skip "glibc ignoring write errors for puts()"
+# [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
+# [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
+#
+# atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full'
+#}
+
+#atf_test_case utc
+#utc_body() {
+# atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s'
+#}
+
+#atf_test_case timestamp
+#timestamp_body() {
+# atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\n${usage}" ../cmd/date -u -d
+#
+# # 36893488147419103232 = 2^65
+# atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232
+#}