shunit2 icon indicating copy to clipboard operation
shunit2 copied to clipboard

assertNotNull not working with set -e

Open lwinkler opened this issue 2 years ago • 3 comments

It seems that shunit2 does not work with the -e flag of bash in some cases (but works fine in other). In particular assertNotNull raises an error (no matter if the assert fails or not). I don't know if the -e flag of bash is compatible with shunit2 but I use it to be sure to catch all errors.

set -e : Exit immediately if a command exits with a non-zero status.

Observed with bash 5.1.16. Here is a simple script to reproduce the bug:

set -e

testSomething() {

  # this behaves correctly
  assertNotSame "Not same" "aaa" "bbb"

  # this fails with message: ASSERT:Unknown failure encountered running a test
  assertNotNull "Not null(1)" "something"
}

source shunit2

lwinkler avatar Oct 25 '23 07:10 lwinkler

What is your version of shunit2?

williamdes avatar Oct 25 '23 08:10 williamdes

I see the same when assertSame is used. I downloaded shUnit2 the 7th of February last year ( 2023 ). So the fix in https://github.com/kward/shunit2/issues/141 is there.

When

set -eo pipefail
shopt -s inherit_errexit

is active ... I get: ASSERT:unknown failure encountered running a test

Commenting them out:

#set -eo pipefail
#shopt -s inherit_errexit

And I get:

ASSERT:The returned base worker name should be the same as: test-test-worker expected:<ASS> but was:<test-test-worker>
shunit2:ERROR testReturnsCorrectBaseWorkerName() returned non-zero return code.

Further debugging showed that when using set without -e then I get no ASSERT:unknown failure encountered running a test error.

larssb avatar Jan 30 '24 13:01 larssb