assertTrue results in "ASSERT:Unknown failure ..." with "set -o errexit"
HankB opened this issue · comments
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
set -o nounset
#set -x
test_assertTrue() {
assertTrue 'test failed' "[ -r /some/non-existant/file' ]"
}
# Load shUnit2.
. shunit2
produces
test_assertTrue
ASSERT:Unknown failure encountered running a test
Ran 1 test.
FAILED (failures=1)
With "set -o errexit" commented out,
test_assertTrue
ASSERT:test failed
Ran 1 test.
FAILED (failures=1)
Debian Bullseye, bash
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
and shunit
ii shunit2 2.1.6-1.2 all unit test framework for Bourne based shell scripts
Same result on Debian Buster with bash
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
and shunit
ii shunit2 2.1.6-1.1 all unit test framework for Bourne based shell scripts
Could you try the latest shUnit2 from the master branch? I believe that the set -e
(set -o errexit) issues are fixed as part of the not-yet-released 2.1.9 series.
Ok, I've been able to reproduce this on my local machine. I'll see what I can figure out. Note, this was against 2.1.8.
$ ./i141_test.sh
test_assertTrue
ASSERT:unknown failure encountered running a test
Ran 1 test.
FAILED (failures=1)
OK, confirmed that older releases (including 2.1.8 which I tested) don't work. Please upgrade to the latest shunit2 from HEAD as it works.
$ ./i141_test.sh
test_assertTrue
ASSERT:test failed
shunit2:ERROR test_assertTrue() returned non-zero return code.
Ran 1 test.
FAILED (failures=1)
To fix the "shunit2:ERROR test_assertTrue()" error, add a return 0
to the end of the test so the test_assertTrue()
function returns successfully.