Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ewertons
Copy link
Contributor

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);
            }
        }

Copy link
Member

@dcristoloveanu dcristoloveanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

if ((umock_call_recorder == NULL) ||
/* Codes_SRS_UMOCKCALLRECORDER_31_057: [ If index is greater or equal to the current expected calls count, umockcallrecorder_can_call_fail shall return a non-zero value. ]*/
(index >= umock_call_recorder->expected_call_count))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, missing .md specs update, which should be used to write also the tests for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed most of the issues. I'm having this error though, need to understand why.

[ 93%] Linking C executable ../../../Debug/umock_c_negt_noint_tests_exe_umock_c/umock_c_negt_noint_tests_exe_umock_c
/usr/bin/ld: ../../../libumock_c.a(umockcallrecorder.c.o): in function `umockcallrecorder_destroy':
/home/ewertons/code/s2/umock-c/src/umockcallrecorder.c:150: multiple definition of `umockcallrecorder_destroy'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:155: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockcallrecorder.c.o): in function `umockcallrecorder_clone':
/home/ewertons/code/s2/umock-c/src/umockcallrecorder.c:595: multiple definition of `umockcallrecorder_clone'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:93: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockcallrecorder.c.o): in function `umockcallrecorder_get_expected_call_count':
/home/ewertons/code/s2/umock-c/src/umockcallrecorder.c:722: multiple definition of `umockcallrecorder_get_expected_call_count'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:106: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockcallrecorder.c.o): in function `umockcallrecorder_fail_call':
/home/ewertons/code/s2/umock-c/src/umockcallrecorder.c:752: multiple definition of `umockcallrecorder_fail_call'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:120: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockcallrecorder.c.o): in function `umockcallrecorder_can_call_fail':
/home/ewertons/code/s2/umock-c/src/umockcallrecorder.c:791: multiple definition of `umockcallrecorder_can_call_fail'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:147: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockalloc.c.o): in function `umockalloc_malloc':
/home/ewertons/code/s2/umock-c/src/umockalloc.c:10: multiple definition of `umockalloc_malloc'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:229: first defined here
/usr/bin/ld: ../../../libumock_c.a(umockalloc.c.o): in function `umockalloc_free':
/home/ewertons/code/s2/umock-c/src/umockalloc.c:31: multiple definition of `umockalloc_free'; libumock_c_negt_noint_tests_lib_umock_c.a(umock_c_negt_noint_tests.c.o):/home/ewertons/code/s2/umock-c/tests/umock_c_negt_noini_ut/umock_c_negt_noint_tests.c:234: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [tests/umock_c_negt_noini_ut/exe/CMakeFiles/umock_c_negt_noint_tests_exe_umock_c.dir/build.make:104: Debug/umock_c_negt_noint_tests_exe_umock_c/umock_c_negt_noint_tests_exe_umock_c] Error 1
make[1]: *** [CMakeFiles/Makefile2:2657: tests/umock_c_negt_noini_ut/exe/CMakeFiles/umock_c_negt_noint_tests_exe_umock_c.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Apparently the build is not happy that I introduced a new function in umockcallrecorder.c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I took the dependency on this new function off the PR I was actually working on so it gets unblocked. I'll come back to this once I get the other task done.

@dcristoloveanu
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants