Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertNotNull not working with set -e #174

Open
lwinkler opened this issue Oct 25, 2023 · 2 comments
Open

assertNotNull not working with set -e #174

lwinkler opened this issue Oct 25, 2023 · 2 comments

Comments

@lwinkler
Copy link

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
@williamdes
Copy link
Collaborator

What is your version of shunit2?

@larssb
Copy link

larssb commented Jan 30, 2024

I see the same when assertSame is used. I downloaded shUnit2 the 7th of February last year ( 2023 ). So the fix in #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants