On 1/22/20 10:09 AM, Nikola Forró wrote:
On Thu, 2020-01-16 at 14:46 -0700, Tom Hromatka wrote:
I briefly looked through the entire function and it looks like a
great candidate for unit testing (except for the readlink() and
fopen() lines but that's easily worked around.)
Is it? I'm not sure how. Do you have a suggestion?

So there are two methods I would typically use in a case like this:

1.  Mock out the external calls - like readlink(), fopen(), etc.
    Usually I don't like mocking stuff in C, but - barring a refactor
    with a focus on testability - using mocks may be the best
    solution for this particular function.

2.  Split the read logic (fopen(), fget(), etc.) and the parsing
    logic into separate functions.  I started prototyping this, but
    ran into troubles with readlink() and other couplings between
    the read and parsing logic.  As an aside, I retract the "easily
    worked around" comment above.  :)  It can be done, but my
    prototype was not going as I hoped.  As I said above, I think a
    rewrite or mocking would be more successful.

Thanks.

Tom



Regards,
Nikola




_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to