[CMake] compare two files - testing
James C. Sutherland
James.Sutherland at utah.edu
Mon Jul 6 18:10:07 EDT 2009
On Jul 6, 2009, at 11:54 AM, James C. Sutherland wrote:
>>
>> execute_command(
>> COMMAND ${test_cmd}
>> COMMAND ${CMAKE_COMMAND} -E compare_files ${output_blessed} $
>> {output_test}
>> RESULT_VARIABLE test_not_successful
>> OUTPUT_QUIET
>> ERROR_QUIET
>> )
>>
>> if( test_not_successful )
>> message( SEND_ERROR "${output_test} does not match $
>> {output_blessed}!" )
>> endif( test_not_successful )
>>
>>
>>
>> and then in your CMakeLists.txt:
>>
>> add_test( "someImportantTest"
>> ${CMAKE_COMMAND}
>> -Dtest_cmd="${CMAKE_BINARY_DIR}/tests/someImportantTestProgram --
>> with arguments"
>> -Doutput_blessed="${CMAKE_SOURCE_DIR}/tests/output/
>> someImportatanTestProgram.output"
>> -Doutput_test="${CMAKE_BINARY_DIR}/someImportatanTestProgram.output"
>> -P ${CMAKE_SOURCE_DIR}/CMake/run_test.cmake
>> )
>>
>
> I have noticed that if I use
> -Dtest_cmd="${CMAKE_BINARY_DIR}/tests/someImportantTestProgram --
> with arguments"
> it results in errors - it appears that the test_cmd variable is not
> interpreted properly because the resulting process does not get
> executed. For executables without arguments, removing quotes seems
> to work to set test_cmd properly.
>
> For example
>
> # in CMakeLists.txt
> add_test( dummy_1
> ${CMAKE_COMMAND}
> -Dtest_cmd="ls -lah"
> -P ${CMAKE_SOURCE_DIR}/util/try.cmake
> )
>
>
> # in try.cmake
> if( NOT test_cmd )
> message( FATAL_ERROR "Variable test_cmd not defined" )
> endif( NOT test_cmd )
>
> execute_process( COMMAND ${test_cmd} )
>
The solution is to use something like:
# in CMakeLists.txt
set( test_args "-la -lh" )
add_test( dummy_1
${CMAKE_COMMAND}
-D test_cmd:string=ls
-D test_args=${test_args}
-P ${CMAKE_SOURCE_DIR}/util/try.cmake
)
#in try.cmake
separate_arguments( test_args )
execute_process(
COMMAND ${test_cmd} ${test_args}
RESULT_VARIABLE test_not_successful
)
More information about the CMake
mailing list