Azure / umock-c

A pure C mocking library
MIT License
32 stars 25 forks source link

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

Open ewertons opened 8 months ago

ewertons commented 8 months ago

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);
            }
        }
dcristoloveanu commented 8 months ago

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