mity / acutest

Simple header-only C/C++ unit testing facility.
MIT License
346 stars 96 forks source link

TEST_STRING_EQUAL method #47

Closed RedMoon32 closed 4 years ago

RedMoon32 commented 4 years ago

Why there is no method for string comparison? TEST_CHECK(strcmp(produced, expected) == 0) is not very comfortable. I think for exampleTEST_STRING_EQUAL("123456789","123567899") which will write to output smthn like " String Check Failed 123456789 123567899

4!=5 " will be very useful for many purposes I can implement it

gahr commented 4 years ago

In NeoMutt we have this:

https://github.com/neomutt/neomutt/blob/9222c6019c7fa3839008e9c6931666b8c81464de/test/address/common.h#L32-L40

mity commented 4 years ago

One of the original motivations for Acutest was my dislike of baroque interfaces in existing solutions which provide a comparison macro for every combination of type and comparison operator and sometime even for some other aspect of the test (e.g. assert-like versus check-like behavior).

See e.g. https://github.com/ThrowTheSwitch/Unity/blob/ae8b98e80b716eb6c627f1c98261ffe9f9d3acca/src/unity.h#L124 for an example what I mean.

To clarify: that's not meant as an objective criticism, it's just a matter of my subjective taste.

I am willing to make some concessions where there is a wide consensus that the potential benefit outweighs the purity of the interface (and the string comparison might perhaps be that case).

But let me state clearly that I don't want to end up with the dozens of comparison macros like in the linked example.

And actually even here I am wondering whether you are proposing just the one macro, or implicitly also TEST_STRING_NOT_EQUAL, TEST_STRING_LOWER_THAN, TEST_STRING_EQUAL_OR_LOWER_THAN etc. and then ditto for case insensitive comparison and then....