Assert macro suggestion

71 views
Skip to first unread message

svunit16

unread,
Jul 3, 2016, 3:16:13 AM7/3/16
to SVUnit User Group
Coming from other unit test frameworks (like Python's unittest), I've found the built in assert macros that come with svunit to be a little counterintuitive (`FAIL_IF instead of `ASSERT_EQ) and I was also surprised that they don't print out the expected vs. actual values in an error message when they fail.
 
I find myself defining my own macros like this and using these instead:
 
`define ASSERT_EQ(exp,act) `FAIL_UNLESS_LOG(exp === act, $sformatf("Expected: %0d  Actual: %0d", exp, act));
`define ASSERT_STR_EQ(exp,act) string stre, stra; stre=exp; stra=act; `FAIL_UNLESS_LOG(stre.compare(stra) == 0, $sformatf("Expected: '%s'  Actual: '%s'", stre, stra));
 
I think it would be useful for something like these to be included in the svunit code, along with ones like `ASSERT_TRUE/FALSE, `ASSERT_NULL/NOTNULL, etc.


 

Bryan Morris

unread,
Jul 3, 2016, 10:13:46 AM7/3/16
to SVUnit User Group
Personally speaking, I'd say go ahead and add them and submit to the library (it is open-source after all).  Your suggestions are clear, and backward compatible.  They'd be a good addition.  As well, if you find them more obvious, someone else will as well.  

You could continue to wrap your assertions using the FAIL_* macros, but it's probably better to use the underlying functionality similar to the style used by the existing FAIL_* macros.

Thanks for the suggestion.
Reply all
Reply to author
Forward
0 new messages