Subject: [boost] Is there interest in unit testing both passing and failing BOOST_MPL_ASSERTs?
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-09-13 03:38:13
This submission would make it possible to write a complete set of unit tests
for meta-programs, to test both the positive, compiling statements, and the
negative, non-compiling statements. These tests will all compile, and the
negative tests can throw an exception instead of failing to compile.
After reading the recent interest submission from Abel Sinkovics, it
occurred to me that it should be possible to modify the four existing
BOOST_MPL_ASSERT_* macros to achieve this capability. This behavior would
only be enabled if a specific compile flag was defined. Here is a sample
code fragment which I have compiled and tested to work as described:
// This definition shuts off the BOOST_MPL_ASSERT compile errors, and
enables the run-time errors.
#define BOOST_MPL_UNITTEST_ASSERTS defined
BOOST_CHECK_NO_THROW( integers_only<char> passing0; );
BOOST_CHECK_NO_THROW( integers_only<short> passing1; );
BOOST_CHECK_NO_THROW( integers_only<int> passing2; );
BOOST_CHECK_NO_THROW( integers_only<unsigned int> passing3; );
// These test cases now actually compile, but then throw at runtime, which
BOOST_CHECK_THROW( integers_only<float> failing0;,
BOOST_CHECK_THROW( integers_only<double> failing1;,
As you can see, existing code which uses the four BOOST_MPL_ASSERT_* macros,
can now be unit tested, without modification, for both positive, and
negative use cases.
Is anybody interested in this capability, and/or my modifications to the
single file boost/mpl/assert.hpp which have enabled this capability?
Ben Robinson, Ph.D.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk