diff options
author | V3n3RiX <venerix@koprulu.sector> | 2024-12-10 02:01:16 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2024-12-10 02:01:16 +0000 |
commit | 59437d191de3ff33f9bfa37f8656d849184fcaf0 (patch) | |
tree | 7d5e645c0aac6d8b71229a0e53d7a93136f83781 /eclass | |
parent | 1a95f960273f276a4fdefb824336b073d83bcb5e (diff) |
gentoo auto-resync : 10:12:2024 - 02:01:16
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/Manifest.gz | bin | 39029 -> 39366 bytes | |||
-rw-r--r-- | eclass/eapi9-pipestatus.eclass | 60 | ||||
-rwxr-xr-x | eclass/tests/eapi9-pipestatus.sh | 57 |
3 files changed, 117 insertions, 0 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz Binary files differindex 567962a4013f..e4c73afa80bc 100644 --- a/eclass/Manifest.gz +++ b/eclass/Manifest.gz diff --git a/eclass/eapi9-pipestatus.eclass b/eclass/eapi9-pipestatus.eclass new file mode 100644 index 000000000000..f92afe42ef14 --- /dev/null +++ b/eclass/eapi9-pipestatus.eclass @@ -0,0 +1,60 @@ +# Copyright 2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: eapi9-pipestatus.eclass +# @MAINTAINER: +# Ulrich Müller <ulm@gentoo.org> +# @AUTHOR: +# Ulrich Müller <ulm@gentoo.org> +# @SUPPORTED_EAPIS: 7 8 +# @BLURB: check the PIPESTATUS array +# @DESCRIPTION: +# A stand-alone implementation of a possible future pipestatus command +# (which would be aimed for EAPI 9). It is meant as a replacement for +# "assert". In its simplest form it can be called like this: +# +# @CODE +# foo | bar +# pipestatus || die +# @CODE +# +# With the -v option, the command will also echo the pipe status array, +# so it can be assigned to a variable like in the following example: +# +# @CODE +# local status +# foo | bar +# status=$(pipestatus -v) || die "foo | bar failed, status ${status}" +# @CODE +# +# Caveat: "pipestatus" must be the next command following the pipeline. +# In particular, the "local" declaration must be before the pipeline, +# otherwise it would reset the status. + +case ${EAPI} in + 7|8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +# @FUNCTION: pipestatus +# @USAGE: [-v] +# @RETURN: last non-zero element of PIPESTATUS, or zero if all are zero +# @DESCRIPTION: +# Check the PIPESTATUS array, i.e. the exit status of the command(s) +# in the most recently executed foreground pipeline. If called with +# option -v, also output the PIPESTATUS array. +pipestatus() { + local status=( "${PIPESTATUS[@]}" ) + local s ret=0 verbose="" + + [[ ${1} == -v ]] && { verbose=1; shift; } + [[ $# -ne 0 ]] && die "usage: ${FUNCNAME} [-v]" + + for s in "${status[@]}"; do + [[ ${s} -ne 0 ]] && ret=${s} + done + + [[ ${verbose} ]] && echo "${status[@]}" + + return "${ret}" +} diff --git a/eclass/tests/eapi9-pipestatus.sh b/eclass/tests/eapi9-pipestatus.sh new file mode 100755 index 000000000000..6264b63d9440 --- /dev/null +++ b/eclass/tests/eapi9-pipestatus.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Copyright 2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +source tests-common.sh || exit + +inherit eapi9-pipestatus + +tps() { + local exp_ret=${1} cmd=${2} + local have_ret + tbegin "${cmd} -> ret: ${exp_ret}" + eval "${cmd}; pipestatus" + have_ret=$? + [[ ${have_ret} -eq ${exp_ret} ]] + tend $? "returned: ${have_ret}" +} + +tpsv() { + local exp_ret=${1} exp_out=${2} cmd=${3} + local have_ret have_out + tbegin "${cmd} -> ret: ${exp_ret}, out: ${exp_out}" + have_out=$(eval "${cmd}; pipestatus -v") + have_ret=$? + [[ ${have_ret} -eq ${exp_ret} && ${have_out} == "${exp_out}" ]] + tend $? "returned: ${have_ret}, output: ${have_out}" +} + +txf() { + local out + tbegin "XFAIL: $*" + out=$("$@" 2>&1) + [[ ${out} == die:* ]] + tend $? "function did not die" +} + +ret() { + return ${1} +} + +tps 0 "true" +tps 1 "false" +tps 0 "true | true" +tps 1 "false | true" +tps 2 "ret 2 | true" +tps 1 "true | false | true" +tps 5 "true | false | ret 5 | true" +tpsv 0 "0 0 0" "true | true | true" +tpsv 1 "1 0" "false | true" +tpsv 2 "3 2 0" "ret 3 | ret 2 | true" + +txf pipestatus bad_arg +txf pipestatus -v extra_arg + +texit |