Boost logo

Boost :

Subject: Re: [boost] CMake and Boost Build tests
From: paul (pfultz2_at_[hidden])
Date: 2017-07-27 15:00:44


On Thu, 2017-07-27 at 10:16 +0100, John Maddock via Boost wrote:
>
> On 26/07/2017 20:42, paul via Boost wrote:
> >
> > On Wed, 2017-07-26 at 14:49 -0400, Edward Diener via Boost wrote:
> > >
> > > Following John Maddock's appeal for practical solutions related to the
> > > move to CMake, I would like to know what the CMake equivalent is to the
> > > Boost Build unit test functionality.
> > >
> > > In other words what do I write for CMake in order to do a Boost Build
> > > compile, compile-fail, link, link-fail, run, and run-fail unit tests ?
> > For a run test, you would do, something like:
> >
> > add_executable(footest footest.cpp)
> > add_test(NAME footest COMMAND $<TARGET_FILE:footest>)
> >
> > For a compile/link test:
> >
> > add_library(footest STATIC EXCLUDE_FROM_ALL footest.cpp)
> > add_test(NAME footest COMMAND ${CMAKE_COMMAND} --build . --target footest
> > --
> > config $<CONFIGURATION> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
> I think I'm losing the will to live looking at that :(

It is low-level, which is why people just write a custom function for it.

>
> >
> >
> > To make the tests with expected failures, just set a property:
> >
> > set_tests_properties(footest PROPERTIES WILL_FAIL TRUE)
> >
> > You also can check for certain output, which nice for checking that the
> > compile fail tests has triggered the static assert.
> >
> > Ideally, the BCMTest module can make this simpler:
> >
> > http://bcm.readthedocs.io/en/latest/src/BCMTest.html
> >
> > Which you can write the equivalent tests like this:
> >
> > Run test:
> > bcm_test(NAME footest SOURCES footest.cpp)
> >
> > Run fail test:
> > bcm_test(NAME footest SOURCES footest.cpp WILL_FAIL)
> >
> > Compile test:
> > bcm_test(NAME footest SOURCES footest.cpp COMPILE_ONLY)
> >
> > Compile fail test:
> > bcm_test(NAME footest SOURCES footest.cpp COMPILE_ONLY WILL_FAIL)
> That looks way better!
>
> I assume we can also add annotation for things like:
>
> * Defines.
> * Configuration if-then-else logic.
> * Compiler specific flags (probably in conjunction with some 
> configuration test).

You mean add annotations to the function? You can do all those things directly
with cmake as the name is the name of the target and test, so you can just
write:

bcm_test(NAME footest SOURCES footest.cpp)
target_compile_options(footest -Wall)

You can see an example of how the tests would be written in cmake for
Boost.Config on PR#129 I have, here:

https://github.com/boostorg/config/pull/129/files#diff-15547c54d3d4898a882b4ab
7b3cee381

In addition to what is done in bjam, this also generates the tests from the
.ipp files so there is no need to commit generated files to the repo.


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