theboocock / shunit2

Automatically exported from code.google.com/p/shunit2
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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: