aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2023-08-18 14:42:57 +0200
committerKate Ward <kate.ward@forestent.com>2023-08-18 14:42:57 +0200
commitbbe2a3d234fd7927b833fc182ebd63726d21162a (patch)
tree200fccc78c67c57e91d76efc8f93bda962049631
parent2a5bc77621c14193e3596a81baa1410aa36a198d (diff)
downloadshflags-bbe2a3d234fd7927b833fc182ebd63726d21162a.tar.gz
Added test to ensure 'set -o pipefail' doesn't break shFlags.
-rwxr-xr-xshflags_issue_57.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/shflags_issue_57.sh b/shflags_issue_57.sh
new file mode 100755
index 0000000..2969f5f
--- /dev/null
+++ b/shflags_issue_57.sh
@@ -0,0 +1,67 @@
+#! /bin/sh
+# vim:et:ft=sh:sts=2:sw=2
+#
+# shFlags unit test for Issue #57.
+# https://github.com/kward/shflags/issues/57
+#
+# Copyright 2023 Kate Ward. All Rights Reserved.
+# Released under the Apache 2.0 license.
+#
+# Author: kate.ward@forestent.com (Kate Ward)
+# https://github.com/kward/shflags
+#
+### ShellCheck (http://www.shellcheck.net/)
+# Disable source following.
+# shellcheck disable=SC1090,SC1091
+# $() are not fully portable (POSIX != portable).
+# shellcheck disable=SC2006
+
+# These variables will be overridden by the test helpers.
+returnF="${TMPDIR:-/tmp}/return"
+stdoutF="${TMPDIR:-/tmp}/STDOUT"
+stderrF="${TMPDIR:-/tmp}/STDERR"
+
+# Load test helpers.
+. ./shflags_test_helpers
+
+# Test proper functionality with 'set -o pipefail' enabled.
+testIssue57() {
+ set -o pipefail
+
+ th_clearReturn
+ (
+ FLAGS -h >"${stdoutF}" 2>"${stderrF}"
+ echo $? >"${returnF}"
+ )
+
+ assertFalse \
+ 'short help request should have returned a false exit code.' \
+ "$(th_queryReturn)"
+ ( grep 'show this help' "${stderrF}" >/dev/null )
+ r3turn=$?
+ assertTrue \
+ 'short request for help should have produced some help output.' \
+ ${r3turn}
+ [ ${r3turn} -ne "${FLAGS_TRUE}" ] && th_showOutput
+
+ return ${SHUNIT_TRUE}
+}
+
+oneTimeSetUp() {
+ th_oneTimeSetUp
+
+ if flags_getoptIsStd; then
+ th_warn 'Standard version of getopt found. Enhanced tests will be skipped.'
+ return
+ fi
+ th_warn 'Enhanced version of getopt found. Standard tests will be skipped.'
+}
+
+setUp() {
+ flags_reset
+}
+
+# Load and run shUnit2.
+# shellcheck disable=SC2034
+[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
+. "${TH_SHUNIT}"