[CMake] Establishing TDD workflow

Michael Jackson mike.jackson at bluequartz.net
Sun Nov 30 10:37:13 EST 2008


I think you are looking for CTest. You build your unit test executable  
then have CTest run and report the results.

enable_testing()
add_test(ut ${EXECUTABLE_OUTPUT_PATH}/ut)

then you run "make" and if that builds ok, then "make test"


Mike

On Nov 30, 2008, at 6:38 AM, Slava Tutushkin wrote:

> Hi all,
>
> I'm only starting with cmake, so my question can be quite lame.
> However, I have read the "Mastering Cmake" and googled a lot about it
> already.
>
> I have executable running the tests built with cmake. Now I need to
> execute it as a part of build process.
>
> I'm building the exec with the following:
>
> add_executable(ut TestUnittest.cpp stdafx.cpp SomeSuite.cpp  
> SecondSuite.cpp)
> target_link_libraries(ut UnitTest++.vsnet2008)
>
> In the search for solution I have tried two approaches:
> 1. Adding
> add_custom_command(TARGET ut POST_BUILD COMMAND ut COMMENT Testing)
> As a result, command runs after succesfull build. Problem here is if
> the test fails, they are not runs again after next build (since the
> executable is not changed and rebuild). But I need it to run each
> build until the tests are succesfull.
>
> 2. When I add
> add_custom_target(ut_test ALL DEPENDS ut COMMAND ut)
> The tests starts running all time, even if previous run was successful
> and the exec was not rebuilt. If I'm not adding "ALL", it is not
> running at all.
> It's ok for now, but it unacceptable in the long term.
>
>
> So, to sum up, what I need:
> 1. If exec dependencies was changed, rebuild exec
> 2. If exec was changed, run exec. If exec was not changed, but last
> exec run was failed, run exec. If exec was not changed and exec
> during last built was successful, don't run exec.
>
>
> I suspect, I shall rewrite the exec so it shall output some file in
> the case of succesfull run so I can add something in the filesystem
> for cmake to look for.
>
> People, please help me!
>
> -- 
> Best regards,
> Slava                          mailto:info at eskosoft.com



More information about the CMake mailing list