logo

utils

Old programs, got split in utils-std and utils-extra git clone https://anongit.hacktivis.me/git/utils.git/
commit: c7109ce5ce6cbf11ea6490acea624bc675cbf104
parent b935e1df4baff492e2986717444ef15ff3a32521
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 26 Sep 2023 15:16:34 +0200

sh/archive-tags: Moved to dotfiles

Diffstat:

Dsh/archive-tags23-----------------------
Atest-cmd/date93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 23 deletions(-)

diff --git a/sh/archive-tags b/sh/archive-tags @@ -1,23 +0,0 @@ -#!/bin/sh -# SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -workdir="$(git rev-parse --show-toplevel)" -name="$(basename "${workdir}")" -mkdir -p "${workdir}.archives" -# https://semver.org/ -# printf "%s\n" 'v1.0.0' '0.1.2' 'foobar' | egrep '^v?[0-9\.]+(-[0-9A-Za-z-]*)?' -git tag -l | egrep '^v?[0-9\.]+(-[0-9A-Za-z-]*)?' | while read -r tag; do - version="$(echo "$tag" | sed 's/^v//')" - file="${workdir}.archives/${name}-$(echo "${version}" | tr '/' '_').tar.gz" - - test -f "${file}" || git archive \ - --format tar.gz \ - --prefix "${name}-${version}/" \ - -o "${file}" \ - -- \ - "${tag}" - - test -f "${file}.sig" || gpg --detach-sign "${file}" - test -f "${file}.sign" || minisign -S -x "${file}.sign" -m "${file}" -done diff --git a/test-cmd/date b/test-cmd/date @@ -0,0 +1,93 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +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'\ndate [-uR][-d datetime] [+format]\n" ../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_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: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'\ndate [-uR][-d datetime] [+format]\n" ../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_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 +}