Boost logo

Boost :

From: Jens Seidel (jensseidel_at_[hidden])
Date: 2007-12-20 11:16:35


Hi,

I know it may no longer fit on this list but as I started here let's not
move the list ...

I read most of the new documentation but to make it short: I still fail
to use unit tests. It worked in the past but after a lot of changes
in Boost.Tests it is now unusable for me.

On Wed, Dec 19, 2007 at 10:02:39AM +0100, Jens Seidel wrote:
> On Tue, Dec 18, 2007 at 03:46:29PM +0000, Gennadiy Rozental wrote:
> > Jens Seidel <jensseidel <at> users.sf.net> writes:
> > > I recently had again some trouble because of it:
> > > * It broke the general autoconf test in boost.m4 as the existance of
> > > a Boost library can normally easily be tested by using boost code
> > > in main() and not init_unit_test_suite(). (Will probably be fixed
> > > soon in boost.m4.)

Benoit: Have fun updating boost.m4.
Additionally you have now to care about incompatible differences in recent
versions, different handling depending on linkage and probably more. It
will be interesting to see you solving this for all possibilities :-)
 
> > > * According to http://lists.boost.org/Archives/boost/2007/05/121601.php
> > > linkers don't look into libraries (either static or dynamic) to
> > > find main so that unit tests cannot be cimpiled as shared library.
 
> > It's not a bug. It's a feature. ;) Starting 1.34.1 main() doesn't reside in
> > shared libs.
 
> > In any case Boost.Test supports
> > what you want. In many, many cases you don't need init_.. function anymore and
> > boost test provides a way for users to get away without it and function main()
> > as well both with static and shared library usage variant of the UTF. If you
>
> OK. This is probably preferred.

But now I wonder why I should make a lot of incompatibles changes? I
want my program and all tests beeing able to compile everywhere with
(nearly) all versions of Boost.

Using some small code parts condionally depending on autotools system
and Boost tests (version of boost, shared library is available?, ...)
would be acceptable but I'm no willing to make major changes to my code.
 
> > prefer to define main youself and invoke init function you can do it as well
> > with shared library variant.

And how?
 
> > Please look for more details here:
> >
> > http://www.patmedia.net/~rogeeff/html/index.html
> >
> > Please let me know if there is any issues still.

I read again carefully the documentation (http://www.patmedia.net/~rogeeff/html)
which exists in parallel to http://www.boost.org/libs/test/doc and can confirm
that the problem that main() is not found still exists!

Including the header boost/test/included/unit_test.hpp *once* per binary seems
to work but normal using of boost/test/unit_test.hpp together with an additional
#define BOOST_TEST_DYN_LINK
still leads to a missing main() function. I get since 1.34.1:
/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

I defined also a dummy main function (just to make the linker happy as I
assumed the tests are maybe started in the contructor of a static variable) but
my test is not called. Even calling init_unit_test_suite() from main() does not
work.

I also defined BOOST_TEST_DYN_LINK on the comandline to ensure that all code
uses it. Same result! Defining addionally BOOST_TEST_MAIN results in a
a proper empty test with the output
 "Test setup error: test tree is empty"
I thought I have also seen a conflict with my own init_unit_test_suite()
implementation if I define BOOST_TEST_MAIN but cannot reproduce it.

A question: Would it be save to define BOOST_TEST_DYN_LINK also for static
linkage? I hope so as I have never, really never used different code depending
on linker options.

Even after renaming my main
test_suite* init_unit_test_suite(int, char *[])
function into
bool init_unit_test()
(but only for dynamic linkage?) as noticed on
http://www.patmedia.net/~rogeeff/html/utf/user-guide/initialization.html
I fail as usual.

Short: In the past it was so simple:

#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
test_suite* init_unit_test_suite(int, char *[])
{
   test_suite *test = BOOST_TEST_SUITE("Master test suite");
   test->add(BOOST_TEST_CASE(&JacobiTest1));
   return test;
}

Now I use

* Additional autoconf code to define HAVE_UNIT_TEST_LIB if the (shared?) library is
  used.

#ifdef HAVE_CONFIG_H
#include <config.h> // HAVE_UNIT_TEST_LIB
#endif

#ifdef HAVE_UNIT_TEST_LIB
# define BOOST_TEST_DYN_LINK
# include <boost/test/unit_test.hpp>
#else
# include <boost/test/included/unit_test.hpp>
#endif

using boost::unit_test::test_suite;

bool init_unit_test()
{
  // my old init_unit_test_suite code
}

/*
int main(int argc, char *argv[])
{
  init_unit_test_suite(argc, argv);
  return 0;
}
*/

I'm now really tired and stoped. A more or less easy to use
library (I had to follow only same advises on
http://www.boost.org/libs/test/doc/components/utf/index.html)
is now more or less unusable. The code depends on the linkage,
the documentation can be found outside of the boost.org domain,
the required information is wrong and incomplete and addionally
scattered across multiple pages such as
http://www.patmedia.net/~rogeeff/html/utf/compilation.html
http://www.patmedia.net/~rogeeff/html/utf/compilation/direct-include.html
http://www.patmedia.net/~rogeeff/html/utf/user-guide/usage-variants.html
 (and all referenced sub pages)
http://www.patmedia.net/~rogeeff/html/utf/user-guide/test-runners.html
http://www.patmedia.net/~rogeeff/html/utf/user-guide/initialization.html

To show you that I really read (at least up to UTF) the documenation I mention
a few errors in it:

http://www.patmedia.net/~rogeeff/html/faq.html:
 * "provide provide"
 * "link with libunit_test_framework.lib"
    that's platform specific!!!
 * "The reasons for this error is that in your implementation you should
    specify second argument of init_unit_test_suite exactly as in a
    specification, i.e.: char* []."
   s/as in a specification/as in the specification/ (I first read e.g.
   instead of i.e. which confused me even more, maybe you should avoid "i.e.".)

http://www.patmedia.net/~rogeeff/html/open-issues.html
 * "Finish update for CLA support"
   What is CLA?
 * Remove two or three full stops in the enumeration
 * "Better Unicode support (reports and log in wostream)"
   Sorry, I don't see any relation of wostream and Unicode!
   You mean UTF16 encoding? UTF8 should work fine with both
   ostream and wostream, right?

http://www.patmedia.net/~rogeeff/html/execution-monitor.html
 * "Also The Execution Monitor"
   s/The/the/

http://www.patmedia.net/~rogeeff/html/execution-monitor/reference.html
 * Page misses a "next" link to
   http://www.patmedia.net/~rogeeff/html/boost/execution_exception.html

http://www.patmedia.net/~rogeeff/html/prg-exec-monitor/impl.html
 * Link to libs/test/execution_monitor.cpp does not work
 * "wraps a several system headers"
   s/a//

http://www.patmedia.net/~rogeeff/html/minimal.html
 * "other then include boost/test/minimal.hpp"
   s/include/including/
 * "This approach is are similar" (belongs to folded text for example 4)
   s/are//

http://www.patmedia.net/~rogeeff/html/tutorials/intro-in-testing.html
 * "why testing worth the effort"
   s/testing/testing is/

http://www.patmedia.net/~rogeeff/html/tutorials/new-year-resolution.html
 * s/BOOST_AUTO_EST_CASE/BOOST_AUTO_TEST_CASE/
 * "As a result my test suite became to look like this:"
   Wrong example!!! data_access_test() was expected

http://www.patmedia.net/~rogeeff/html/utf/user-guide/initialization.html
 * "Alternatively in you can employ"
   s/in//
 * "with the static library or single-header variants of the UTF requires the
    specific function specification."
   Check this! s/specification/signature/, s/specific/original/?

Per accident (used wrong browser window) I read also partely the old
documentation:
http://www.boost.org/libs/test/doc/components/utf/index.html
 * s/messy a error/messy error/
 * "The framework" ... "provides function main() that initialize the framework"

   That's wrong!
 * Example file "unit_test_example1.cpp" does not exist on your server (error 404).

Jens


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk