I've been kicking around the idea of a C++ test harness that lets tests use
things internal to libxul for a while. The basic idea would be to link
libxul twice, once as a dynamic shared object and once as a static library,
and then later in the build link the static version of libxul against the
tests to form 'libxulwithtests.so' (or whatever). There are some details to
handle with tests that require clean xpcom environments but nothing terribly
hard.
Ted has suggested using GoogleTest <http://code.google.com/p/googletest/> as
the underlying framework, and that seems reasonable to me. GoogleTest is
used by Chromium and LLVM among other large projects. It'd also let
us use GoogleMock
<http://code.google.com/p/googlemock/>which will likely come in very handy.
We ought to be able to teach pyxpidl to write out mock xpcom objects that
tests can use.
If nobody has any objections I'll likely give this a go sometime soon and
convert some of our existing compiled tests to use it.
Questions/comments/concerns?
- Kyle
I think this is great. While we do quite well with integration testing, I get the impression that things
that aren't easy to test with our existing frameworks tend not to be tested. (the code in mfbt/ etc.)
This would hopefully make some of those things easier to test.
-Jeff
>The basic idea would be to link libxul twice, once as a dynamic shared object and once as a static library
>
Can't we use fakelibs to simplify this?
--
Warning: May contain traces of nuts.
> Kyle Huey wrote:
>
> The basic idea would be to link libxul twice, once as a dynamic shared
>> object and once as a static library
>>
>> Can't we use fakelibs to simplify this?
Yes. In practice the "linking as a static library" will translate to "write
down a file with the list of all the object files that go into libxul".
I just didn't want to get too technical with build system internals here :-)
- Kyle
In case it helps, the IPDL unit tests do something very much like this:
when --enable-ipdl-tests, the C++ tests are built into libxul, and
there's a separate ipdlunittest binary that knows how to call into test
"Main()" functions, as a kind of meta-binary. For example,
|ipdlunittest TestSanity| invokes TestSanity::Main(), approximately.
Not familiar with the google stuff, but it's probably doing like that
but better. The IPDL harness was an afternoon hack.
Cheers,
Chris
> Ted has suggested using GoogleTest<http://code.google.com/p/googletest/> as
> the underlying framework, and that seems reasonable to me. GoogleTest is
> used by Chromium and LLVM among other large projects. It'd also let
> us use GoogleMock
> <http://code.google.com/p/googlemock/>which will likely come in very handy.
> We ought to be able to teach pyxpidl to write out mock xpcom objects that
> tests can use.
We already have a header somewhere for some basic testing. If it's not
too much to add, an ability to "expect" an assertion would be helpful.
In terms of mock objects, I doubt the framework would work nicely with
all of our xpidl objects (ACString, jsvals can be problematic). It
should be possible to use our stub library to do enough to replicate the
mock library, but I'm not looking to writing that. In any case, being
able to do mock xpcom stuff from xpcshell tests would also be useful, I
think.
Rob
--
"If we claim to be without sin, we deceive ourselves and the truth is not in
us. If we confess our sins, he is faithful and just and will forgive us our
sins and purify us from all unrighteousness. If we claim we have not sinned,
we make him out to be a liar and his word is not in us." [1 John 1:8-10]
The purpose of the external string API was twofold: 1) to provide an
ABI-stable base (which is no longer important) 2) to avoid exporting the
internal API, which reduces the number of relocations on startup and
improved startup time by 2-5%.
I think the startup time improvement is still important to keep.
--BDS