Skip to content

Commit

Permalink
Added testPipefail() to test that 'set -o pipefail' doesn't break shu…
Browse files Browse the repository at this point in the history
…nit2.
  • Loading branch information
kward committed Aug 18, 2023
1 parent 47be8b2 commit 3334e53
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion shunit2_misc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# shUnit2 unit tests of miscellaneous things
#
# Copyright 2008-2021 Kate Ward. All Rights Reserved.
# Copyright 2008-2023 Kate Ward. All Rights Reserved.
# Released under the Apache 2.0 license.
# http://www.apache.org/licenses/LICENSE-2.0
#
Expand Down Expand Up @@ -269,6 +269,31 @@ mock_tput() {
return 1
}

# Note: the test script is prefixed with '#' chars so that shUnit2 does not
# incorrectly interpret the embedded functions as real functions.
testPipefail() {
unittestF="${SHUNIT_TMPDIR}/unittest"
sed 's/^#//' >"${unittestF}" <<EOF
## Test that using 'set -o pipefail' does not break shunit2.
#set -o pipefail
#
#pipefail() { true; } # shunit2 should remain happy with this simple test.
#test_pipefail() {
# assertEquals 1 1
# pipefail
# assertEquals 0 \$?
#}
#SHUNIT_COLOR='none'
#. ${TH_SHUNIT}
EOF
if ! ( exec "${SHELL:-sh}" "${unittestF}" >"${stdoutF}" 2>"${stderrF}" ); then
fail 'expected a zero exit value'
fi
if ! grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null; then
fail 'test count message was not generated'
fi
}

setUp() {
for f in "${stdoutF}" "${stderrF}"; do
cp /dev/null "${f}"
Expand Down

0 comments on commit 3334e53

Please sign in to comment.