Files
CMake/Tests/RunCMake/PackageInfo/Assertions.cmake
T
Matthew Woehlke 1a846c8849 Tests: Add tests for install(PACKAGE_INFO)
Add several test cases to verify that install(PACKAGE_INFO) is working
as expected. These cover validating the output for several scenarios,
improper use of the command, effects of command arguments, and a handful
of improper uses.

Tests that should still be added include one covering DESTINATION (both
the default and user-specified) and the CPS location and link_location
attributes. These have been skipped for now because the former requires
actually installing a test project, and the latter involves validating
attributes whose values are platform-dependent. (In particular, I don't
think link_location will appear on not-Windows.) Additionally, there is
no coverage of (other) common install-command arguments such as
PERMISSIONS, COMPONENT, etc.; however, because the logic implementing
these is shared, the tests covering them for other sub-commands is
probably sufficient.

Note that, because the files are generated in a location that includes a
hash of the install destination, and because the default destination is
platform dependent, the tests need to specify a fixed DESTINATION so
that the location of generated files (which we need to inspect and
validate) is predictable.
2024-08-14 15:25:27 -04:00

35 lines
1.2 KiB
CMake

macro(_expect entity op actual expected)
if(NOT "${actual}" ${op} "${expected}")
list(JOIN ARGN "." name)
set(RunCMake_TEST_FAILED
"Attribute '${name}' ${entity} '${actual}' does not match expected ${entity} '${expected}'" PARENT_SCOPE)
return()
endif()
endmacro()
function(expect_value content expected_value)
string(JSON actual_value GET "${content}" ${ARGN})
_expect("value" STREQUAL "${actual_value}" "${expected_value}" ${ARGN})
endfunction()
function(expect_array content expected_length)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "ARRAY" ${ARGN})
string(JSON actual_length LENGTH "${content}" ${ARGN})
_expect("length" EQUAL "${actual_length}" "${expected_length}" ${ARGN})
endfunction()
function(expect_null content)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "NULL" ${ARGN})
endfunction()
function(expect_missing content)
string(JSON value ERROR_VARIABLE error GET "${content}" ${ARGN})
if(NOT value MATCHES "^(.*-)?NOTFOUND$")
set(RunCMake_TEST_FAILED
"Attribute '${ARGN}' is unexpectedly present" PARENT_SCOPE)
endif()
endfunction()