summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2020-07-07 10:33:59 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2020-07-07 10:33:59 +0000
commitbbdc823dbfcb874c29fa4138c2591f5196aab521 (patch)
tree8e8816f54aaf4c4d0562aae01a7bff98d8a67fb2 /regress
parentcdac567044ac69c43238666f5fa17eca2f28138e (diff)
Add support for set -o pipefail
With the pipefail option set, the exit status of a pipeline is 0 if all commands succeed, or the return status of the rightmost command that fails. This can help stronger error checking, but is not a silver bullet. For example, commands will exhibit a non-zero exit status if they're killed by a SIGPIPE when writing to a pipe. Yet pipefail was considered useful enough to be included in the next POSIX standard. This implementation remembers the value of the pipefail option when a pipeline is started, as described as option 1) in https://www.austingroupbugs.net/view.php?id=789#c4102 Requested by ajacoutot@, ok millert@
Diffstat (limited to 'regress')
-rw-r--r--regress/bin/ksh/obsd-regress.t90
1 files changed, 89 insertions, 1 deletions
diff --git a/regress/bin/ksh/obsd-regress.t b/regress/bin/ksh/obsd-regress.t
index d94695111cf..b9b33d17655 100644
--- a/regress/bin/ksh/obsd-regress.t
+++ b/regress/bin/ksh/obsd-regress.t
@@ -1,4 +1,4 @@
-# $OpenBSD: obsd-regress.t,v 1.11 2020/05/22 08:45:23 anton Exp $
+# $OpenBSD: obsd-regress.t,v 1.12 2020/07/07 10:33:58 jca Exp $
#
# ksh regression tests from OpenBSD
@@ -514,3 +514,91 @@ description:
stdin:
kill -s SIGINFO $$
---
+
+name: pipeline-pipefail-1
+description:
+ check pipeline return status
+stdin:
+ set -o pipefail
+ true | true
+---
+
+name: pipeline-pipefail-2
+description:
+ check pipeline return status
+stdin:
+ set -o pipefail
+ false | true
+expected-exit: e == 1
+---
+
+name: pipeline-pipefail-3
+description:
+ check pipeline return status
+stdin:
+ set -o pipefail
+ true | false
+expected-exit: e == 1
+---
+
+name: pipeline-pipefail-4
+description:
+ check pipeline return status
+stdin:
+ set -o pipefail
+ ! false | true
+---
+
+name: pipeline-pipefail-errexit-1
+description:
+ check pipeline return status
+stdin:
+ set -e
+ false | true
+ echo "ok"
+expected-stdout: ok
+---
+
+name: pipeline-pipefail-errexit-2
+description:
+ check pipeline return status
+stdin:
+ set -e
+ set -o pipefail
+ false | true
+ echo "should not print"
+expected-exit: e == 1
+expected-stdout:
+---
+
+name: pipeline-pipefail-errexit-3
+description:
+ check pipeline return status
+stdin:
+ set -e
+ set -o pipefail
+ false | true || echo "ok"
+expected-stdout: ok
+---
+
+name: pipeline-pipefail-check-time-1
+description:
+ check pipeline return status
+stdin:
+ false | true &
+ p=$!
+ set -o pipefail
+ wait $p
+---
+
+name: pipeline-pipefail-check-time-2
+description:
+ check pipeline return status
+stdin:
+ set -o pipefail
+ false | true &
+ p=$!
+ set +o pipefail
+ wait $p
+expected-exit: e == 1
+---