[lightweight_test] cpp_main convention

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[lightweight_test] cpp_main convention

Boost - Dev mailing list
Hi,

I noticed this as popular convention across Boost libraries (e.g. endian)
to deal with test cases  that may throw or leak exceptions:

int cpp_main( int argc, char* argv[] )
{
    test();
    return ::boost::report_errors();
}

int main( int argc, char* argv[] )
{
    try
    {
        return cpp_main( argc, argv );
    }
    catch( std::exception const & x )
    {
        BOOST_ERROR( x.what() );
        return boost::report_errors();
    }
}

Is there any reason to prefer that one over this one?

int main( int argc, char* argv[] )
{
    try
    {
        test();
    }
    catch( std::exception const & x )
    {
        BOOST_ERROR( x.what() );
    }
    return boost::report_errors();
}

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [lightweight_test] cpp_main convention

Boost - Dev mailing list
Mateusz Loskot wrote:
> Hi,
>
> I noticed this as popular convention across Boost libraries (e.g. endian)
> to deal with test cases  that may throw or leak exceptions:
>
> int cpp_main( int argc, char* argv[] )
...

> Is there any reason to prefer that one over this one?
>
> int main( int argc, char* argv[] )
...

cpp_main is not a convention. It's mostly useful when you already have a
common `main` provided by the test framework, whether inside the static test
framework library or in a header such as

https://github.com/boostorg/detail/blob/develop/include/boost/detail/lightweight_main.hpp

The current state of affairs in Endian is because it used to use
<boost/detail/lightweight_main.hpp> and I switched away from it to avoid
having to depend on Detail.

https://github.com/boostorg/endian/commit/3a50c15a9734439598b46442568b375a52c9d63d#diff-a722f1e609137ba8f239c06ae197a0a8

In a self-contained test, there is no need to use cpp_main. Just write
`main` the usual straightforward way.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [lightweight_test] cpp_main convention

Boost - Dev mailing list
On Thu, 26 Mar 2020 at 00:43, Peter Dimov via Boost
<[hidden email]> wrote:
> In a self-contained test, there is no need to use cpp_main. Just write
> `main` the usual straightforward way.

Good.
I still add try-catch to avoid ungraceful termination w/ core dump.

Thank you

--
Mateusz Loskot, http://mateusz.loskot.net

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost