umock-c icon indicating copy to clipboard operation
umock-c copied to clipboard

Add a function to negative_tests to get a call description (using stringify)

Open ewertons opened this issue 2 years ago • 1 comments

This will help identifying the offending STRICT_EXPECTED_CALL when defining negative tests.

Example:

...
        umock_c_negative_tests_snapshot();
        size_t call_count = umock_c_negative_tests_call_count();

        //act
        for (size_t i = 0; i < call_count; i++)
        {
            if (umock_c_negative_tests_can_call_fail(i))
            {
                // arrange
                char error_msg[128];
                char* call_description = umock_c_negative_tests_get_call_description(i);
                (void)sprintf(error_msg, "Failure in test %zu/%zu (%s)", i, call_count, call_description);
                my_gballoc_free(call_description);

                umock_c_negative_tests_reset();
                umock_c_negative_tests_fail_call(i);

                int result = call_my_public_function();

                //assert
                ASSERT_ARE_NOT_EQUAL(int, 0, result, error_msg);
            }
        }

ewertons avatar Feb 14 '24 00:02 ewertons

Nice initiative, ty! Had some comments about specs, tests and a little bit of poetry in the mix.

dcristoloveanu avatar Feb 15 '24 23:02 dcristoloveanu

This is a rather stale PR, closing.

dcristoloveanu avatar Nov 21 '24 18:11 dcristoloveanu