[rfc][icedtea-web] C++ unit tests support for ITW :D
Pavel Tisnovsky
ptisnovs at redhat.com
Wed Nov 21 07:17:39 PST 2012
Hi Adam,
----- Adam Domurad <adomurad at redhat.com> wrote:
> To lay the groundwork for future C++ refactoring I have created a patch
> that integrates UnitTest++ into the source of icedtea-web. Some notes on
> design decisions:
Yes, we definitely need *some* unittest tool for C++ side - and to improve
code coverage too :-)
Some notes:
- DOS/Windows EOLs are used in the first patch. I'm not sure how some
changes will be handled by diff/patch/Mercurial in such case...
>
> - Two new folders in tests/, UnitTest++ and cpp-unit-tests.
> - UnitTest++ contains the source of UnitTest++ (minus test cases
> which I decided to not copy over for simplicity). The makefile provided
> is not used, instead a simple for loop over the source is used to
> compile it in the target for the library. Feel free to advise ways to
> improve this.
if you mean this code:
+ for cppfile in $$(find $(CPP_UNITTEST_FRAMEWORK_SRCDIR) -name '*.cpp') ; \
+ do \
+ objfile="$(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/$$(basename $${cppfile%.cpp}).o" ; \
+ $(CXX) $(CXXFLAGS) -c $$cppfile -o $$objfile || exit 1 ; \
+ done ; \
+ ar cr $(CPP_UNITTEST_FRAMEWORK_LIB) $(CPP_UNITTEST_FRAMEWORK_BUILDDIR)/*.o ; \
I think this is ok in our case.
> - cpp-unit-tests contains the source of the unit tests. Each .cpp
> file contains test cases that are3 compiled and linked with
> libUnitTest++.a as well as the object files from the plugin. These as
> well are compiled using a simple for loop. If you can think of a way to
> correctly add dependencies for the makefile without too much cruft let
> me know.
> - A new make target, make run-cpp-unit-tests runs the unit tests.
>
> UnitTest++ was chosen because its lightweight, and only requires that
> you include a TEST (...) { } definition in .cpp files, no header files
> required.
>
It looks reasonable, but does it have any form of more detailed reports?
Or does it just print number of passed and failed tests w/o analyzing
code coverage etc. etc.?
Still I think it is a very important adition to ITW HEAD!
Cheers,
Pavel
> Two patches are included, one that adds the source from UnitTest++ and
> does nothing else, and the rest that does the infrastructure to compile
> and run the unit tests.
>
> AddUnitTest++.patch and its ChangeLog attached.
>
> ChangeLog for integration:
>
> 2012-11-20 Adam Domurad <adomurad at redhat.com>
>
> Support for C++ unit testing with UnitTest++ for IcedTeaWeb.
> * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc: New, contains tests
> for utility functions.
> * tests/cpp-unit-tests/main.cc: New, contains unit test runner.
> * plugin/icedteanp/IcedTeaPluginUtils.h: Remove incorrect circular
> include dependency
> * plugin/icedteanp/IcedTeaRunnable.h: Add includes necessary for
> self-sustaining header.
> * Makefile.am: Add targets for unit test compilation and running,
> eg 'make run-cpp-unit-tests'.
>
>
> (I toyed around with setting up my Eclipse project for the icedtea-web
> C++ code to run the unit tests via External Tool, its quite nice like
> that :)
>
More information about the distro-pkg-dev
mailing list