martinmoene / lest

A modern, C++11-native, single-file header-only, tiny framework for unit-tests, TDD and BDD (includes C++98 variant)
Boost Software License 1.0
390 stars 45 forks source link

Add quieter EXPECT #68

Closed ninnghazad closed 5 years ago

ninnghazad commented 5 years ago

It'd be nice to have an EXPECT that does not print evaluated statements in stdout when -p is used. when i EXPECT compare two pieces of binary data and use -p, it prints them to stdout and messes up the terminal. would also be nice for comparing rather long strings and such - i wanna see the output from -p, but not the actual values in every case.

martinmoene commented 5 years ago

Can you provide examples of such current and desired outputs?

ninnghazad commented 5 years ago

while testing a rle-compressor and xor-thingy used for some delta-compression in a thing, comparing bytestrings returned from those functions in a loop:

src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "�A5��E�d�Er��CATy" == "�A5��E�d�Er��CATy"
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "����#�i$�|�x����" == "����#�i$�|�x����"
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "k�Y�J�`�Y�%����C-" == "k�Y�J�`�Y�%����C-"
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "�Z�t����k۬�'p��y�O" == "�Z�t����k۬�'p��y�O"
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "��E�@I
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "�1A�~f��m�p" == "�1A�~f��m��$o�1�����
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "e��:Y=����.�:�+�r9�mi7�E." == "e��:Y=����.�:�+�r9�mi7�E."
��^,�ς:K.u� 5f��W��x�5u" == "c�: passed: rle [rle,strxor] : r==b for "c�
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "ɀP�?K�l�]��W�L�sM�<��ص�" == "ɀP�?K�l�]��W�L�sM�<��ص�"
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b for "�=80'���8}�
 �J�v�+�T��F)�\{�" == "�=80'���8}�
                                  �J�v�+�T��F)�\{�
All 1 selected test passed.
$ 1;2c1;2c1;2c1;2c

also note uncalled for '1;2c' s on the commandline. the full test also beeps a lot because some bytes the terminal sees as bell codes. what i would much prefer to see:

src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b
...
src/tests/test_003_util.cpp:102: passed: rle [rle,strxor] : r==b
All 1 selected test passed.
$

the code for something like that looks like this:

{
        bytes a = "000000000";
        bytes b = "000001000";
        bytes r = sxor(a,rle_decompress(rle_compress(sxor(a,b))));
        EXPECT(r==b);
}
martinmoene commented 5 years ago

@ninnghazad , Btw, what is your use for --pass reports (w/o the expansions)?

martinmoene commented 5 years ago

Plan:

Option names could be

ninnghazad commented 5 years ago

@martinmoene thanks! that already is nicer - especially for cases where i want to see string output, but a failed case might produce some nasty strings. no more bell escapes already. i use --pass when writing new tests - checking if all tests are properly executed and if (except for machine-readable stuff) the used values are what i wanted. and then i use it when manually compiling - for satisfaction. just nice to write a few new bits and bobs and have all the green "passed" messages scroll by. in most cases the expansion of the condition is nice, just these cases where i test non-printable strings and those where i compare big strings.

martinmoene commented 5 years ago

Thanks, I'm off for a couple of days, so next actions will have to wait a little.

ninnghazad commented 5 years ago

thank you very much @martinmoene . i'm good with the lastest changes, and consider this solved.