vcpkg/scripts/test_ports/unit-test-cmake/portfile.cmake
nicole mazzuca 0e1dc12185
[rollup] Rollup PR 2021-07-16 (#19001)
* [rollup:2021-07-16 1/7] PR #18201 (@JackBoosY)

[vcpkg-cmake] Add check for unused cmake variables

* [rollup:2021-07-16 2/7] PR #18397 (@strega-nil)

[vcpkg_list] add new function

* [rollup:2021-07-16 3/7] PR #18782 (@strega-nil)

[scripts-audit] vcpkg_build_ninja

* [rollup:2021-07-16 4/7] PR #18784 (@strega-nil)

[scripts-audit] vcpkg_minimum_required

* [rollup:2021-07-16 5/7] PR #18785 (@strega-nil)

[scripts-audit] vcpkg_replace_string

* [rollup:2021-07-16 6/7] PR #18786 (@strega-nil)

[scripts-audit] windows scripts

* [rollup:2021-07-16 7/7] PR #18945 (@strega-nil)

[many ports] remove deprecated vcpkg_check_features call [1/5]

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Co-authored-by: PhoebeHui <20694052+PhoebeHui@users.noreply.github.com>
2021-07-20 10:24:58 -07:00

74 lines
2.4 KiB
CMake

function(set_fatal_error)
if(ARGC EQUAL 0)
set(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR "OFF" CACHE BOOL "" FORCE)
else()
set(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR "ON" CACHE BOOL "" FORCE)
set(Z_VCPKG_UNIT_TEST_FATAL_ERROR "${ARGV0}" CACHE STRING "" FORCE)
endif()
endfunction()
function(set_has_error)
set(Z_VCPKG_UNIT_TEST_HAS_ERROR ON CACHE BOOL "" FORCE)
endfunction()
macro(message level msg)
if("${level}" STREQUAL "FATAL_ERROR")
set_fatal_error("${msg}")
return()
else()
_message("${level}" "${msg}") # note: this results in incorrect printing, but that's fine
# message(STATUS "\${asdf}") will result in
# message(STATUS "${asdf}"), since that's how macro arguments work.
endif()
endmacro()
set(Z_VCPKG_UNIT_TEST_HAS_ERROR OFF CACHE BOOL "" FORCE)
set_fatal_error()
function(unit_test_check_variable_equal utcve_test utcve_variable utcve_value)
cmake_language(EVAL CODE "${utcve_test}")
if(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
set_fatal_error()
set_has_error()
message(STATUS "${utcve_test} had an unexpected FATAL_ERROR;
expected: \"${utcve_value}\"")
message(STATUS "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
return()
endif()
if(NOT DEFINED "${utcve_variable}")
message(STATUS "${utcve_test} failed to set ${utcve_variable};
expected: \"${utcve_value}\"")
set_has_error()
return()
endif()
if(NOT "${${utcve_variable}}" STREQUAL "${utcve_value}")
message(STATUS "${utcve_test} resulted in the wrong value for ${utcve_variable};
expected: \"${utcve_value}\"
actual : \"${${utcve_variable}}\"")
set_has_error()
return()
endif()
endfunction()
function(unit_test_ensure_fatal_error utcve_test)
cmake_language(EVAL CODE "${utcve_test}")
if(NOT Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
set_has_error()
message(STATUS "${utcve_test} was expected to be a FATAL_ERROR.")
endif()
set_fatal_error()
endfunction()
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
if("list" IN_LIST FEATURES)
include("${CMAKE_CURRENT_LIST_DIR}/test-vcpkg_list.cmake")
endif()
if("function-arguments" IN_LIST FEATURES)
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_function_arguments.cmake")
endif()
if(Z_VCPKG_UNIT_TEST_HAS_ERROR)
_message(FATAL_ERROR "At least one test failed")
endif()