Tests: Ensure project() clears unspecified properties

Add a unit test to ensure that various project-related variables are set
to empty when values are not provided in the project() call.
This commit is contained in:
Matthew Woehlke
2025-06-10 15:07:29 -04:00
parent 6171e2da90
commit 04dadd0138
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
function(_expect_empty NAME)
if(NOT DEFINED ${NAME})
message(SEND_ERROR "Variable '${NAME}' is not defined")
elseif(NOT "${${NAME}}" STREQUAL "")
message(SEND_ERROR
"Variable '${NAME}' has value '${${NAME}}' (expected: empty)")
endif()
endfunction()
function(expect_empty SUFFIX)
_expect_empty(PROJECT_${SUFFIX})
_expect_empty(CMAKE_PROJECT_${SUFFIX})
_expect_empty(${PROJECT_NAME}_${SUFFIX})
endfunction()
project(Omissions LANGUAGES)
expect_empty(VERSION)
expect_empty(VERSION_MAJOR)
expect_empty(VERSION_MINOR)
expect_empty(VERSION_PATCH)
expect_empty(VERSION_TWEAK)
expect_empty(COMPAT_VERSION)
expect_empty(DESCRIPTION)
expect_empty(HOMEPAGE_URL)

View File

@@ -45,6 +45,7 @@ run_cmake(ProjectIsTopLevel)
run_cmake(ProjectIsTopLevelMultiple)
run_cmake(ProjectIsTopLevelSubdirectory)
run_cmake(ProjectTwice)
run_cmake(Omissions)
run_cmake(VersionAndLanguagesEmpty)
run_cmake(VersionEmpty)
run_cmake(VersionInvalid)