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

assertTrue does not work with "set -e" #37

Closed
GoogleCodeExporter opened this issue Jun 26, 2015 · 3 comments
Closed

assertTrue does not work with "set -e" #37

GoogleCodeExporter opened this issue Jun 26, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

The below script crashes but would works fine if you remove '-e'

    #! /bin/sh -e

    testTrue()
    {
      assertTrue 0
    }

    . shunit2


I'm using shunit2 v2.1.6-1 from ubuntu raring

Original issue reported on code.google.com by ert...@gmail.com on 21 Jul 2013 at 9:28

@GoogleCodeExporter
Copy link
Author

The problem in this case was the shunit_match_=`expr "${shunit_condition_}" : 
'\([0-9]*\)'` which returned a 1. i attached an || true to ensure that return 
value is always 0 (since it won't be evaluated by the script).

I also fixed the problem for the AssertEquals and AssertNotEquals functions. 
there the problem came frmo failNotEquals.

One remaining problem is that an `assertTrue 1` will still cause the crash 
since the assertion function returns failure in this case. I'm not sure if this 
is a responsibility of the assetion function or the caller that should check 
the return value. I tend to give the responsibility to the caller.

I did not write test yet because I'm not sure how this behaviour could be 
tested.

Original comment by bitschup...@googlemail.com on 13 Sep 2013 at 11:49

Attachments:

@alexharv074
Copy link
Contributor

@kward this is quite a gotcha. Is this issue just waiting on someone to rebase the above patch on the latest shunit2 in master?

kward added a commit that referenced this issue Mar 29, 2020
@kward kward closed this as completed Mar 29, 2020
@kward kward added this to the 2.1.9 milestone Mar 29, 2020
@williamdes
Copy link
Collaborator

Fixed by 6f6a642

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

No branches or pull requests

4 participants