Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Sep 2017 06:36:03 +0000
From:      Shivansh Rai <shivansh@freebsd.org>
To:        Alan Somers <asomers@freebsd.org>, John-Mark Gurney <jmg@funkthat.com>
Cc:        "freebsd-testing@freebsd.org" <freebsd-testing@freebsd.org>
Subject:   Re: suggestion library for mocking C functions
Message-ID:  <CAF%2Bp1HthAun=C4opf9ubW7SuDm0eMDjJ0pjBDHMsEazYbybcLQ@mail.gmail.com>
In-Reply-To: <CAOtMX2iGwcLgYNbs0KUSOpnQ2kWSifY=cFekesVNBtudvpdPtA@mail.gmail.com>
References:  <20170924070506.GQ64616@funkthat.com> <CAOtMX2iGwcLgYNbs0KUSOpnQ2kWSifY=cFekesVNBtudvpdPtA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
To add to the information by asomers@, this comment [1] might also be
relevant.

[1]: https://github.com/google/cmockery/pull/30#issuecomment-251064107

Regards,
-- Shivansh


On Sun, Sep 24, 2017 at 9:52 PM Alan Somers <asomers@freebsd.org> wrote:

> On Sun, Sep 24, 2017 at 1:05 AM, John-Mark Gurney <jmg@funkthat.com>
> wrote:
> > Is there a recommended/supported library for mocking C functions?
> >
> > I want to write some test cases for functions that call other code
> > in the same compilation unit that I want to be able to mock.
> >
> > There are a few out there, but was wondering if anyone has suggestions?
> >
> > Thanks.
> >
> > --
> >   John-Mark Gurney                              Voice: +1 415 225 5579
> <(415)%20225-5579>
>
> There is no good C mocking library.  The language simply doesn't
> provide a good way to do it.  CMockery is the best I've seen.
> However, it's got some big limitations because it relies on the linker
> to swap out function implementations.  Your other option is to use a
> C++ mocking library.  It's usually possible to build your application
> as C, but build the tests as C++.  However, you'll still need to make
> a few modifications to the application source to be able to mock
> functions.  You can probably hide it all in the preprocessor.  If you
> go this route, I recommend googletest, which nowadays includes mocking
> functionality too.
>
> https://github.com/google/cmockery
> https://github.com/google/googletest
>
> -Alan
> _______________________________________________
> freebsd-testing@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-testing
> To unsubscribe, send any mail to "freebsd-testing-unsubscribe@freebsd.org"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF%2Bp1HthAun=C4opf9ubW7SuDm0eMDjJ0pjBDHMsEazYbybcLQ>