[CMake] testing with standard output

Henrique Almeida hdante at gmail.com
Tue Jul 14 15:20:57 EDT 2009


 This is quite crazy, but it may completelly solve the problem. I
wonder why there isn't a single line version of that. I'm even willing
to contribute a patch, but I'd need some guidance.

2009/7/14 James C. Sutherland <James.Sutherland at utah.edu>:
>
>
> I asked a similar question recently.  Here is the recipe for comparing files
> in a test.  You will need to adapt this to your own needs...
>
> 1. In your CMakeLists.txt file:
>
> #-------------------------------------------------
> set( test_cmd ${CMAKE_BINARY_DIR}/util/create_expr )
> set( args "--expr-name=test1 --patch-name=PatchT --field-type=FieldT" )
> add_test( createExprTest_1
>  ${CMAKE_COMMAND}
>  -D test_cmd=${test_cmd}
>  -D test_args:string=${args}
>  -D output_blessed=${CMAKE_SOURCE_DIR}/util/test/test1.h
>  -D output_test=${CMAKE_BINARY_DIR}/util/test1.h
>  -P ${CMAKE_SOURCE_DIR}/util/run_test.cmake
> )
> #-------------------------------------------------
>
>
> 2. In the new "run_test.cmake" file:
>
> #-------------------------------------------------
> # some argument checking:
> # test_cmd is the command to run with all its arguments
> if( NOT test_cmd )
>  message( FATAL_ERROR "Variable test_cmd not defined" )
> endif( NOT test_cmd )
>
> # output_blessed contains the name of the "blessed" output file
> if( NOT output_blessed )
>  message( FATAL_ERROR "Variable output_blessed not defined" )
> endif( NOT output_blessed )
>
> # output_test contains the name of the output file the test_cmd will produce
> if( NOT output_test )
>  message( FATAL_ERROR "Variable output_test not defined" )
> endif( NOT output_test )
>
> # convert the space-separated string to a list
> separate_arguments( test_args )
> message( ${test_args} )
>
> execute_process(
>  COMMAND ${test_cmd} ${test_args}
>  COMMAND ${CMAKE_COMMAND} -E compare_files ${output_blessed} ${output_test}
>  RESULT_VARIABLE test_not_successful
> )
>
> if( test_not_successful )
>  message( SEND_ERROR "${output_test} does not match ${output_blessed}!" )
> endif( test_not_successful )
> #-------------------------------------------------
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
 Henrique Dante de Almeida
 hdante at gmail.com


More information about the CMake mailing list