# Tests @'s date/time parsing # # Copyright (C) 2022 P. J. McDermott # # This file is part of @ # # @ is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # @ is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with @. If not, see . set -eu . "${TOP_SRCDIR}/tests/aux/tap-functions.sh" fmts="$(TZ=UTC0 "${TOP_BUILDDIR}/@" -d '1970-01-01 00:00:00' -F)" time_fmts="$(printf '%s\n' "${fmts}" | \ sed -n '/^Time formats:$/,/^Date formats:$/s/^ \* //p')" date_fmts="$(printf '%s\n' "${fmts}" | \ sed -n '/^Date formats:$/,/^Additional formats:$/s/^ \* //p')" misc_fmts="$(printf '%s\n' "${fmts}" | \ sed -n '/^Additional formats:$/,$s/^ \* //p')" plan_ $((\ $(printf '%s\n' "${time_fmts}" | wc -l) + \ $(printf '%s\n' "${time_fmts}" | wc -l) * \ $(printf '%s\n' "${date_fmts}" | wc -l) * \ 2 + \ $(printf '%s\n' "${misc_fmts}" | wc -l) \ )) run_test() { datetime="${1}" shift 1 got="$(TZ=UTC0 "${TOP_BUILDDIR}/@" -d '1969-12-31 23:59:30' \ "${datetime}" 2>&1)" || : if [ x"${got}" = x'0' ]; then ok_ -- "${datetime}" else not_ok_ -- "${datetime}" diag_ " Failed test '${datetime}'" diag_ " got: '${got}'" diag_ " expected: '0'" fi } IFS=' ' for time_fmt in ${time_fmts}; do run_test "${time_fmt}" for date_fmt in ${date_fmts}; do run_test "${date_fmt} ${time_fmt}" run_test "${time_fmt} ${date_fmt}" done done for misc_fmt in ${misc_fmts}; do run_test "${misc_fmt}" done