touch (6781B)
- #!/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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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 -a -d 2007-11-12T10:15:30Z ./foo
- atf_check touch -m -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
- atime="$(./stat_atime ./foo.d)"
- mtime="$(./stat_mtime ./foo.d)"
- maybe_sleep
- 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
- # No support for displaying fractional seconds on FreeBSD stat(1)
- if uname -s | grep -iq FreeBSD; then
- # shellcheck disable=SC2317
- maybe_sleep() { sleep 1; }
- else
- atf_add_test_case optd_frac
- # shellcheck disable=SC2317
- maybe_sleep() { sleep .1; }
- fi
- }