| Q | A |
|---|
| OS | Linux |
| Shell | bash v5.1.16 |
| bashunit version | 0.18.0 |
Summary
If I use set -e in my script and source it to test the behavior of a function, the test always succeed. Even when it clearly should fail.
NOTE: this only happens when I source the script.
IMO this is a serious bug that puts into question the reliability of bashunit, as it reports a failing test as successful (it would be slightly less serious if it were the other way around).
How to reproduce
Here's my hello.sh script:
#!/usr/bin/env bash# NOTE: if this 'set -e' is removed, the bug reported here doesn't happen!set -e
hello() {
echo"Hello, World!"
}
[[ "${BASH_SOURCE[0]}"=="${0}" ]] && helloHere's the hello_test.sh (note that both are supposed to fail, X != "Hello, World!"):
#!/usr/bin/env bashtest_calling_hello.sh() {
# 👍 this assertion fails, which is expected
assert_same "X""$(./hello.sh)"
}
test_source_hello.sh_and_call_the_hello_function() {
# 👎 this assertion passes, which is an errorsource ./hello.sh
assert_same "X""$(hello)"
}When I run this test I have this:
$ bashunit ./hello_test.sh
bashunit - 0.18.0
Running hello_test.sh
✗ Failed: Calling hello.sh
Expected 'X'
but got 'Hello, World!'
✓ Passed: Source hello.sh and call the hello function
# ...
Again: if I remove the set -e in hello.sh this buggy success does NOT happen..
Expected behavior
Do not report a failing test behavior as success, even if the script has set -e and is sourced.

Summary
If I use
set -ein my script andsourceit to test the behavior of a function, the test always succeed. Even when it clearly should fail.NOTE: this only happens when I
sourcethe script.IMO this is a serious bug that puts into question the reliability of bashunit, as it reports a failing test as successful (it would be slightly less serious if it were the other way around).
How to reproduce
Here's my
hello.shscript:Here's the
hello_test.sh(note that both are supposed to fail,X != "Hello, World!"):When I run this test I have this:
Again: if I remove the
set -einhello.shthis buggy success does NOT happen..Expected behavior
Do not report a failing test behavior as success, even if the script has
set -eand issourced.