mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-16 22:27:41 -05:00
* Add ASSERT_CONTENTS_EQUAL test macro in testing.cmake Checks if the contents of a file matches the given input * Use shorter hashes with CPM_SOURCE_CACHE (#624) Uses shorter hashes with CPM_SOURCE_CACHE. Falls back to a longer hash if necessary (ie, if there's a collision with an existing hash). See: https://github.com/cpm-cmake/CPM.cmake/issues/624 * Update integration tests to support shorter hashes * trigger ci * run cmake-format * if already available, use the legacy cache hash * create temporary file in current binary dir * add test case for legacy hash --------- Co-authored-by: Lars Melchior <lars.melchior@gmail.com> Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
95 lines
2.6 KiB
CMake
95 lines
2.6 KiB
CMake
function(ASSERT_EQUAL)
|
|
if(NOT ARGC EQUAL 2)
|
|
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
|
endif()
|
|
|
|
if(NOT "${ARGV0}" STREQUAL "${ARGV1}")
|
|
message(FATAL_ERROR "assertion failed: '${ARGV0}' != '${ARGV1}'")
|
|
else()
|
|
message(STATUS "test passed: '${ARGV0}' == '${ARGV1}'")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_NOT_EQUAL)
|
|
if(NOT ARGC EQUAL 2)
|
|
message(FATAL_ERROR "assertion failed: invalid argument count: ${ARGC}")
|
|
endif()
|
|
|
|
if("${ARGV0}" STREQUAL "${ARGV1}")
|
|
message(FATAL_ERROR "assertion failed: '${ARGV0}' == '${ARGV1}'")
|
|
else()
|
|
message(STATUS "test passed: '${ARGV0}' != '${ARGV1}'")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_EMPTY)
|
|
if(NOT ARGC EQUAL 0)
|
|
message(FATAL_ERROR "assertion failed: input ${ARGC} not empty: '${ARGV}'")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_DEFINED KEY)
|
|
if(DEFINED ${KEY})
|
|
message(STATUS "test passed: '${KEY}' is defined")
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: '${KEY}' is not defined")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_NOT_DEFINED KEY)
|
|
if(DEFINED ${KEY})
|
|
message(FATAL_ERROR "assertion failed: '${KEY}' is defined (${${KEY}})")
|
|
else()
|
|
message(STATUS "test passed: '${KEY}' is not defined")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_TRUTHY KEY)
|
|
if(${${KEY}})
|
|
message(STATUS "test passed: '${KEY}' is set truthy")
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: value of '${KEY}' is not truthy (${${KEY}})")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_FALSY KEY)
|
|
if(${${KEY}})
|
|
message(FATAL_ERROR "assertion failed: value of '${KEY}' is not falsy (${${KEY}})")
|
|
else()
|
|
message(STATUS "test passed: '${KEY}' is set falsy")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERTION_FAILED)
|
|
message(FATAL_ERROR "assertion failed: ${ARGN}")
|
|
endfunction()
|
|
|
|
function(ASSERT_EXISTS file)
|
|
if(EXISTS ${file})
|
|
message(STATUS "test passed: '${file}' exists")
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: file ${file} does not exist")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_NOT_EXISTS file)
|
|
if(NOT EXISTS ${file})
|
|
message(STATUS "test passed: '${file}' does not exist")
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: file ${file} exists")
|
|
endif()
|
|
endfunction()
|
|
|
|
function(ASSERT_CONTENTS_EQUAL file content)
|
|
if(EXISTS ${file})
|
|
file(READ ${file} file_content)
|
|
if(content STREQUAL file_content)
|
|
message(STATUS "test passed: '${file}' exists and contains '${content}'")
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: file '${file}' does not contain expected content.")
|
|
endif()
|
|
else()
|
|
message(FATAL_ERROR "assertion failed: file '${file} does not exist")
|
|
endif()
|
|
endfunction()
|