diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 36dd6fa..f6092fa 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -429,28 +429,28 @@ function(assert_execute_process) ) if(DEFINED ARG_ERROR AND RES EQUAL 0) - string(REPLACE ";" " " ARG_COMMAND "${ARG_COMMAND}") - message( - FATAL_ERROR - "expected command '${ARG_COMMAND}' to fail" - ) + string(REPLACE ";" " " COMMAND "${ARG_COMMAND}") + _assert_internal_format_message( + MESSAGE "expected command:" "${COMMAND}" "to fail") + message(FATAL_ERROR "${MESSAGE}") elseif(NOT DEFINED ARG_ERROR AND NOT RES EQUAL 0) - string(REPLACE ";" " " ARG_COMMAND "${ARG_COMMAND}") - message( - FATAL_ERROR - "expected command '${ARG_COMMAND}' not to fail" - ) + string(REPLACE ";" " " COMMAND "${ARG_COMMAND}") + _assert_internal_format_message( + MESSAGE "expected command:" "${COMMAND}" "not to fail") + message(FATAL_ERROR "${MESSAGE}") elseif(DEFINED ARG_OUTPUT AND NOT "${OUT}" MATCHES "${ARG_OUTPUT}") - string(REPLACE ";" " " ARG_COMMAND "${ARG_COMMAND}") - message( - FATAL_ERROR - "expected the output of command '${ARG_COMMAND}' to match '${ARG_OUTPUT}'" - ) + string(REPLACE ";" " " COMMAND "${ARG_COMMAND}") + _assert_internal_format_message( + MESSAGE "expected the output:" "${OUT}" + "of command:" "${COMMAND}" + "to match:" "${ARG_OUTPUT}") + message(FATAL_ERROR "${MESSAGE}") elseif(DEFINED ARG_ERROR AND NOT "${ERR}" MATCHES "${ARG_ERROR}") - string(REPLACE ";" " " ARG_COMMAND "${ARG_COMMAND}") - message( - FATAL_ERROR - "expected the error of command '${ARG_COMMAND}' to match '${ARG_ERROR}'" - ) + string(REPLACE ";" " " COMMAND "${ARG_COMMAND}") + _assert_internal_format_message( + MESSAGE "expected the error:" "${ERR}" + "of command:" "${COMMAND}" + "to match:" "${ARG_ERROR}") + message(FATAL_ERROR "${MESSAGE}") endif() endfunction() diff --git a/test/cmake/AssertionTest.cmake b/test/cmake/AssertionTest.cmake index 3bcef98..9dc0ed0 100644 --- a/test/cmake/AssertionTest.cmake +++ b/test/cmake/AssertionTest.cmake @@ -213,48 +213,54 @@ function("Process execution assertions") end_mock_message() assert_message( FATAL_ERROR - "expected command '${CMAKE_COMMAND} -E true' to fail" - ) + "expected command:\n ${CMAKE_COMMAND} -E true\nto fail") mock_message() assert_execute_process(COMMAND "${CMAKE_COMMAND}" -E false) end_mock_message() assert_message( FATAL_ERROR - "expected command '${CMAKE_COMMAND} -E false' not to fail" - ) + "expected command:\n ${CMAKE_COMMAND} -E false\nnot to fail") assert_execute_process( COMMAND "${CMAKE_COMMAND}" -E echo "Hello world!" - OUTPUT "Hello.*!" - ) + OUTPUT "Hello.*!") mock_message() assert_execute_process( COMMAND "${CMAKE_COMMAND}" -E echo "Hello world!" - OUTPUT "Hi.*!" - ) + OUTPUT "Hi.*!") end_mock_message() - assert_message( - FATAL_ERROR - "expected the output of command '${CMAKE_COMMAND} -E echo Hello world!' to match 'Hi.*!'" - ) + string( + JOIN "\n" EXPECTED_MESSAGE + "expected the output:" + " Hello world!" + " " + "of command:" + " ${CMAKE_COMMAND} -E echo Hello world!" + "to match:" + " Hi.*!") + assert_message(FATAL_ERROR "${EXPECTED_MESSAGE}") assert_execute_process( - COMMAND "${CMAKE_COMMAND}" -E invalid - ERROR "CMake Error:.*Available commands:" - ) + COMMAND "${CMAKE_COMMAND}" -E touch / + ERROR "cmake -E touch: failed to update") mock_message() assert_execute_process( - COMMAND "${CMAKE_COMMAND}" -E invalid - ERROR "CMake Error:.*Unavailable commands:" - ) + COMMAND "${CMAKE_COMMAND}" -E touch / + ERROR "cmake -E touch: not failed to update") end_mock_message() - assert_message( - FATAL_ERROR - "expected the error of command '${CMAKE_COMMAND} -E invalid' to match 'CMake Error:.*Unavailable commands:'" - ) + string( + JOIN "\n" EXPECTED_MESSAGE + "expected the error:" + " cmake -E touch: failed to update \"/\"." + " " + "of command:" + " ${CMAKE_COMMAND} -E touch /" + "to match:" + " cmake -E touch: not failed to update") + assert_message(FATAL_ERROR "${EXPECTED_MESSAGE}") endfunction() function("Mock message")