logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 4869d5dee59d4b44970c94e93409a22df27506b4
parent 4435933486c5913e189acb67d0b88126514e3749
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 26 Aug 2024 10:10:15 +0200

selfcheck.sh: split into check-funcs.sh and check-cmds.sh

Diffstat:

MMakefile7+++++--
Acheck-cmds.sh22++++++++++++++++++++++
Acheck-funcs.sh41+++++++++++++++++++++++++++++++++++++++++
Dselfcheck.sh53-----------------------------------------------------
4 files changed, 68 insertions(+), 55 deletions(-)

diff --git a/Makefile b/Makefile @@ -22,8 +22,11 @@ all: $(EXE) $(MAN1SO) # selfcheck: Check without extra dependencies .PHONY: selfcheck -selfcheck: all - ./selfcheck.sh +selfcheck: selfcheck-cmds + +.PHONY: selfcheck-cmds +selfcheck-cmds: $(EXE) + ./check-cmds.sh # Manpages with examples that cram/prysk can grok MAN_EXAMPLES = cmd/readlink.1 diff --git a/check-cmds.sh b/check-cmds.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +WD="$(realpath "$(dirname "$0")")" +log="${WD}/check-cmds.log" +err=0 +. "${WD}/check-funcs.sh" + +cd "$WD" + +rm "$log" + +for runner in test-cmd/*.sh +do + [ "$runner" = "test-cmd/tap.sh" ] && continue + [ "$runner" = "test-cmd/init_env.sh" ] && continue + wrap_test "${runner}" +done + +[ $err = 0 ] && rm "$log" +exit $err diff --git a/check-funcs.sh b/check-funcs.sh @@ -0,0 +1,41 @@ +#!/bin/false +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +set -o pipefail + +tmpdir= + +run_test() { + env MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 "$1" 2>&1 +} + +wrap_test() { + runner="$1" + echo "${PS4}${runner}" + + if command -v mktemp 2>/dev/null >/dev/null + then + cd "$WD" + tmpdir="$(mktemp -d selfcheck.XXXXXX)" + cd "$tmpdir" + fi + + run_test "${WD}/${runner}" | tee -a "${log}" | grep -v '^ok' + ret="$?" + if [ "$ret" != 0 ] + then + printf '## %s exited with code %s\n' "$runner" "$ret" + err=1 + fi + + if [ -n "$tmpdir" ] + then + cd "$WD" + if ! rm -d "$tmpdir" + then + printf '## Error: %s left files:\n%s\n' "$runner" "$(ls -R "$tmpdir")" + err=1 + fi + fi +} diff --git a/selfcheck.sh b/selfcheck.sh @@ -1,53 +0,0 @@ -#!/bin/sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -set -o pipefail - -WD="$(realpath "$(dirname "$0")")" -tmpdir= -err=0 - -run_test() { - env MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 "$1" 2>&1 - return $? -} - -cd "$WD" - -rm "${WD}/selfcheck.out" - -for runner in test-cmd/*.sh -do - [ "$runner" = "test-cmd/tap.sh" ] && continue - [ "$runner" = "test-cmd/init_env.sh" ] && continue - echo "${PS4}${runner}" - - if command -v mktemp 2>/dev/null >/dev/null - then - cd "$WD" - tmpdir="$(mktemp -d selfcheck.XXXXXX)" - cd "$tmpdir" - fi - - run_test "${WD}/${runner}" | tee -a "$WD/selfcheck.out" | grep -v '^ok' - ret="$?" - if [ "$ret" != 0 ] - then - printf '## %s exited with code %s\n' "$runner" "$ret" - err=1 - fi - - if [ -n "$tmpdir" ] - then - cd "$WD" - if ! rm -d "$tmpdir" - then - printf '## Error: %s left files:\n%s\n' "$runner" "$(ls -R "$tmpdir")" - err=1 - fi - fi -done - -[ $err = 0 ] && rm "${WD}/selfcheck.out" -exit $err