Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions test/FixFormatTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ function(check_source_codes_format)
)
endif()

message(STATUS "Getting the original source file hashes")
message(STATUS "Backing up the original source files")
foreach(SRC ${ARG_SRCS})
file(MD5 ${CMAKE_CURRENT_LIST_DIR}/sample/${SRC} ${SRC}_HASH)
set(DESTINATION ${CMAKE_CURRENT_LIST_DIR}/sample/build/original/${SRC})
get_filename_component(DESTINATION_DIR ${DESTINATION} DIRECTORY)
if(NOT EXISTS ${DESTINATION_DIR})
file(MAKE_DIRECTORY ${DESTINATION_DIR})
endif()
file(COPY_FILE ${CMAKE_CURRENT_LIST_DIR}/sample/${SRC} ${DESTINATION})
endforeach()

execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
macro(restore_source_files)
message(STATUS "Restoring the original source files")
foreach(SRC ${ARG_SRCS})
file(
COPY_FILE
${CMAKE_CURRENT_LIST_DIR}/sample/build/original/${SRC}
${CMAKE_CURRENT_LIST_DIR}/sample/${SRC}
)
endforeach()
endmacro()

message(STATUS "Copying the dirty source files")
foreach(SRC ${ARG_SRCS})
Expand Down Expand Up @@ -63,6 +77,7 @@ function(check_source_codes_format)
RESULT_VARIABLE RES
)
if(NOT RES EQUAL 0)
restore_source_files()
message(FATAL_ERROR "Failed to configure sample project")
endif()

Expand All @@ -78,6 +93,7 @@ function(check_source_codes_format)
RESULT_VARIABLE RES
)
if(NOT RES EQUAL 0)
restore_source_files()
message(FATAL_ERROR "Failed to format sample project")
endif()
else()
Expand All @@ -87,17 +103,22 @@ function(check_source_codes_format)
RESULT_VARIABLE RES
)
if(NOT RES EQUAL 0)
restore_source_files()
message(FATAL_ERROR "Failed to build sample project")
endif()
endif()

message(STATUS "Comparing the source file hashes")
foreach(SRC ${ARG_SRCS})
file(MD5 ${CMAKE_CURRENT_LIST_DIR}/sample/${SRC} HASH)
if(NOT HASH STREQUAL ${SRC}_HASH)
message(FATAL_ERROR "File hash of ${SRC} is different: got ${HASH}, should be ${${SRC}_HASH}")
file(MD5 ${CMAKE_CURRENT_LIST_DIR}/sample/build/original/${SRC} ORIGINAL_HASH)
if(NOT HASH STREQUAL ORIGINAL_HASH)
restore_source_files()
message(FATAL_ERROR "File hash of ${SRC} is different: got ${HASH}, should be ${ORIGINAL_HASH}")
endif()
endforeach()

restore_source_files()
endfunction()

if("Format sources files" MATCHES ${TEST_MATCHES})
Expand Down