logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: c9a96f1bf99b39b734de75e2446e9bcf61b19c4d
parent 086906e21eab6f3445e5b7715bc85a262f5ed416
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 19 Sep 2024 10:09:43 +0200

test-cmd/touch: Change from atf-sh to tap.sh

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/touch192-------------------------------------------------------------------------------
Atest-cmd/touch.sh74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 193 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -8,7 +8,6 @@ basedir = fs.dirname(fs.dirname(current_kyuafile())) -- 9,$|LC_ALL=C.UTF-8 sort atf_test_program{name="df", required_files=basedir.."/cmd/df", timeout=1} -atf_test_program{name="touch", required_files=basedir.."/cmd/touch", timeout=1} tap_test_program{name="arch.sh", required_files=basedir.."/cmd/arch", timeout=1} tap_test_program{name="base64.sh", required_files=basedir.."/cmd/base64", timeout=1} tap_test_program{name="basename.sh", required_files=basedir.."/cmd/basename", timeout=1} @@ -45,6 +44,7 @@ tap_test_program{name="split.sh", required_files=basedir.."/cmd/split", timeout= tap_test_program{name="strings.sh", required_files=basedir.."/cmd/strings", timeout=1} tap_test_program{name="tee.sh", required_files=basedir.."/cmd/tee", timeout=1} tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2} +tap_test_program{name="touch.sh", required_files=basedir.."/cmd/touch", timeout=1} tap_test_program{name="true.sh", required_files=basedir.."/cmd/true", timeout=1} tap_test_program{name="tty.sh", required_files=basedir.."/cmd/tty", timeout=1} tap_test_program{name="uname.sh", required_files=basedir.."/cmd/uname", timeout=1} diff --git a/test-cmd/touch b/test-cmd/touch @@ -1,192 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -atf_test_case noargs -noargs_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo -} - -atf_test_case ref_noargs -ref_noargs_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -r ../cmd/touch ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo - atf_check -o "inline:$(./stat_atime ../cmd/touch)\n" ./stat_atime ./foo - atf_check -o "inline:$(./stat_mtime ../cmd/touch)\n" ./stat_mtime ./foo -} - -atf_test_case mtime -mtime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -m ./foo - atf_check -o "inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo -} - -atf_test_case ref_mtime -ref_mtime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -m -r ../cmd/touch ./foo - atf_check -o "inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo - atf_check -o "not-inline:$(./stat_atime ../cmd/touch)\n" ./stat_atime ./foo - atf_check -o "inline:$(./stat_mtime ../cmd/touch)\n" ./stat_mtime ./foo -} - -atf_test_case atime -atime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -a ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "inline:${mtime}\n" ./stat_mtime ./foo -} - -atf_test_case ref_atime -ref_atime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -a -r ../cmd/touch ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "inline:${mtime}\n" ./stat_mtime ./foo - atf_check -o "inline:$(./stat_atime ../cmd/touch)\n" ./stat_atime ./foo - atf_check -o "not-inline:$(./stat_mtime ../cmd/touch)\n" ./stat_mtime ./foo -} - -atf_test_case amtime -amtime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -a -m ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo -} - -atf_test_case ref_amtime -ref_amtime_body() { - atf_check touch -d 2007-11-12T10:15:30Z ./foo - atime="$(./stat_atime ./foo)" - mtime="$(./stat_mtime ./foo)" - - atf_check ../cmd/touch -a -m -r ../cmd/touch ./foo - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo - atf_check -o "inline:$(./stat_atime ../cmd/touch)\n" ./stat_atime ./foo - atf_check -o "inline:$(./stat_mtime ../cmd/touch)\n" ./stat_mtime ./foo -} - -atf_test_case dir -dir_body() { - mkdir -p ./foo.d - touch -d 2007-11-12T10:15:30Z ./foo.d - atime="$(./stat_atime ./foo.d)" - mtime="$(./stat_mtime ./foo.d)" - - atf_check ../cmd/touch ./foo.d - atf_check -o "not-inline:${atime}\n" ./stat_atime ./foo.d - atf_check -o "not-inline:${mtime}\n" ./stat_mtime ./foo.d -} - -atf_test_case optd -optd_body() { - export TZ=UTC - - atf_check ../cmd/touch -d 2003-06-02T13:37:42Z ./foo_d - sync ./foo_d - atf_check -o 'match:^2003-06-02[T ]13:37:42(\.0+)? ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo_d - atf_check -o 'match:^2003-06-02[T ]13:37:42(\.0+)? ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo_d -} - -atf_test_case optd_tz -optd_tz_body() { - export TZ=UTC - - atf_check ../cmd/touch -d 2003-04-20T13:37:42+0000 ./foo_tz1 - sync ./foo_tz1 - atf_check -o 'match:^2003-04-20[T ]13:37:42(\.[0-9]+)? ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo_tz1 - atf_check -o 'match:^2003-04-20[T ]13:37:42(\.[0-9]+)? ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo_tz1 - - atf_check ../cmd/touch -d 2003-04-20T13:37:42.0+0666 ./foo_tz2 - sync ./foo_tz2 - atf_check -o 'match:^2003-04-20[T ]06:31:42(\.[0-9]+)? ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo_tz2 - atf_check -o 'match:^2003-04-20[T ]06:31:42(\.[0-9]+)? ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo_tz2 -} - -atf_test_case optd_frac -optd_frac_body() { - export TZ=UTC - - atf_check ../cmd/touch -d 2003-06-02T13:37:42.713Z ./foo_frac1 - sync ./foo_frac1 - atf_check -o 'match:^2003-06-02[T ]13:37:42.7130+ ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo_frac1 - atf_check -o 'match:^2003-06-02[T ]13:37:42.7130+ ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo_frac1 - - atf_check ../cmd/touch -d 2003-06-02T13:37:42.123456789Z ./foo_frac2 - sync ./foo_frac2 - atf_check -o 'match:^2003-06-02[T ]13:37:42.123456789 ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo_frac2 - atf_check -o 'match:^2003-06-02[T ]13:37:42.123456789 ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo_frac2 - - atf_check -s 'exit:1' \ - -e 'inline:touch: iso_parse("2003-06-02T13:37:42.1234567890Z", …): Too many digits (> 10) for fractional seconds\n' \ - ../cmd/touch -d 2003-06-02T13:37:42.1234567890Z ./foo_frac_big -} - -atf_test_case optt -optt_body() { - export TZ=UTC - - atf_check ../cmd/touch -t 200306021337.42 ./foo - atf_check -o 'match:^2003-06-02[T ]13:37:42(\.0+)? ?(Z|[\+\-]00:?00)$' ./stat_atime ./foo - atf_check -o 'match:^2003-06-02[T ]13:37:42(\.0+)? ?(Z|[\+\-]00:?00)$' ./stat_mtime ./foo -} - -atf_test_case empty_str -empty_str_body() { - atf_check -s exit:1 -o empty -e "inline:touch: error: Failed opening file '': No such file or directory\n" ../cmd/touch '' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case noargs - atf_add_test_case atime - atf_add_test_case mtime - atf_add_test_case amtime - - atf_add_test_case ref_noargs - atf_add_test_case ref_atime - atf_add_test_case ref_mtime - atf_add_test_case ref_amtime - - atf_add_test_case dir - - atf_add_test_case optd - atf_add_test_case optd_tz - - atf_add_test_case optt - - atf_add_test_case empty_str -} diff --git a/test-cmd/touch.sh b/test-cmd/touch.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 +WD=$(dirname "$0") +plans=33 +target="${WD}/../cmd/touch" +. "${WD}/tap.sh" + +tempfile="$(mktemp)" +tempdir="$(mktemp -d)" + +t noargs + +t file "$tempfile" + +t ref_file:setup "-d 2007-11-12T10:15:30Z $tempfile" +t ref_file "-r $target $tempfile" +t_cmd ref_file:atime "$("${WD}/stat_atime" "$target") +" "${WD}/stat_atime" "$tempfile" +t_cmd ref_file:mtime "$("${WD}/stat_mtime" "$target") +" "${WD}/stat_mtime" "$tempfile" + +t mtime:setup "-d 2007-11-12T10:15:30Z $tempfile" +atime=$("${WD}/stat_atime" "$tempfile") +t mtime "-m $tempfile" +t_cmd mtime:atime "$atime +" "${WD}/stat_atime" "$tempfile" + +t ref_mtime:setup "-d 2007-11-12T10:15:30Z $tempfile" +atime=$("${WD}/stat_atime" "$tempfile") +t ref_mtime "-m -r $target $tempfile" +t_cmd ref_mtime:atime "$atime +" "${WD}/stat_atime" "$tempfile" +t_cmd ref_mtime:mtime "$("${WD}/stat_mtime" "$target") +" "${WD}/stat_mtime" "$tempfile" + +t atime:setup "-d 2007-11-12T10:15:30Z $tempfile" +mtime=$("${WD}/stat_mtime" "$tempfile") +t atime "-a $tempfile" +t_cmd atime:mtime "$mtime +" "${WD}/stat_mtime" "$tempfile" + +t ref_atime:setup "-d 2007-11-12T10:15:30Z $tempfile" +mtime=$("${WD}/stat_mtime" "$tempfile") +t ref_atime "-a -r $target $tempfile" +t_cmd ref_atime:mtime "$mtime +" "${WD}/stat_mtime" "$tempfile" +t_cmd ref_atime:atime "$("${WD}/stat_atime" "$target") +" "${WD}/stat_atime" "$tempfile" + +t amtime "-a -m $tempfile" + +t ref_amtime:setup "-d 2007-11-12T10:15:30Z $tempfile" +t ref_amtime "-a -m -r $target $tempfile" +t_cmd ref_amtime:atime "$("${WD}/stat_atime" "$target") +" "${WD}/stat_atime" "$tempfile" +t_cmd ref_amtime:mtime "$("${WD}/stat_mtime" "$target") +" "${WD}/stat_mtime" "$tempfile" + +t dir "${tempdir}" + +t dir_optd "-d 2003-06-02T13:37:42Z $tempdir" + +TZ=UTC t dir_optd_tz:utc "-d 2003-06-02T13:37:42Z $tempdir" +TZ=UTC t dir_optd_tz:0666 "-d 2003-06-02T13:37:42+0666 $tempdir" + +t optt "-t 200306021337.42 $tempfile" + +touch_empty_str() { "$target" ''; } +t_cmd --exit=1 empty_str "touch: error: Failed opening file '': No such file or directory +" touch_empty_str + +t_cmd rm_tempfile '' rm "${tempfile}" +t_cmd rm_tempdir '' rm -r "${tempdir}"