unit testing - Replacing a C function from a common .o file for the scope of a single test executable -
Then, I got a library call init_foo ()
, and a function bar ()
which calls it live with some other useful stuff in the library.o
, both are needed.
I have to write some code, bar_init_failure.tc
, what happens to test when init_foo ()
fails, install failure Without doing In Pearl, a large part of our codebase, I launch and replace the library call with a stub that returns the failure code. To accomplish something similar in C, I have the impression that I can redefine the init_foo
in the source of bar_init_failure.tc
and still For the rest of the code in library.o
, but complain about the GCC
and ld
duplicate symbols (instead of choosing the first one), then I suppose Is that I should be wrong about something (and I'm quite rusting on these kinds of things, so I More confidence in Nniti'm not).
Is there any way to please Linkkar, or is there another strategy that I should use? (I do not have to hack library.c
code if I can help it.)
If you can recompile the library to a shared library, you can redefine the init_foo ()
in unit tests. UDD will not complain about duplicate symbols, nor will the time be compiled, will not be executed, and in the executable which is a dynamic library, at least it will call a function on Unix-like systems - I never try on Windows Of
This can prevent you from examining the bar ()
because you will not be able to call the actual init_foo ()
in other tests; Unless you apply it to your own init_foo ()
, for example when a global variable is set
Comments
Post a Comment