bashunit icon indicating copy to clipboard operation
bashunit copied to clipboard

Can't run with "errexit"

Open bemeyert opened this issue 7 years ago • 2 comments

Hi,

I'm trying out bashunit and found a bug. Most of the times I run my script with set -e errexit. But then bashunit no longer works. Only when I turn it off with set +e, bashunit does it's job.

bemeyert avatar Jun 15 '18 08:06 bemeyert

Can you describe in which form the script "no longer works"? Does it not even start up/run?

djui avatar Jul 23 '18 07:07 djui

Uh, it's some time ago. I no longer have the code. Take for example a script that relies on errexit. Now I want to test if a command fails and the script exits (because of errexit). That no longer works because bashunit won't run at all. Example code:

#!/usr/bin/env bash

set -euo pipefail

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

testFindBuilds () {
    assertEqual "$( eco 2 )" "2"
}
source "$DIRNAME"/bashunit.bash

This gives when run the result:

[shorty@krusty 25] test > ./test.sh 
./test.sh: Zeile 14: eco: command not found
[shorty@krusty 26] test > echo $?
1

The output is not coming from Bashunit but from the shell. I expected the output to be coming from Bashunit. If I run it with set +e just before sourcing bashunit.bash I get this:

[shorty@krusty 32] test > ./findBuildFiles.sh 
./findBuildFiles.sh: Zeile 14: eco: command not found
[./findBuildFiles.sh:testFindBuilds:14:Failed
Done. 0 passed. 1 failed. 0 skipped.
[shorty@krusty 33] test > echo $?
1

bemeyert avatar Jul 23 '18 14:07 bemeyert