Tests/instrumentation: Simplify some conditionals

This commit is contained in:
Tyler Yankee
2026-04-24 14:24:54 -04:00
parent 811bf8fb89
commit 703eaf5ca2
5 changed files with 19 additions and 19 deletions
@@ -23,7 +23,7 @@ foreach(snippet IN LISTS snippets)
# Verify target
string(JSON target ERROR_VARIABLE noTarget GET "${contents}" target)
if (NOT target MATCHES NOTFOUND)
if (target)
set(targets "main;lib;customTarget;TARGET_NAME")
if (ARGS_FAIL)
list(APPEND targets "dummy")
@@ -120,7 +120,7 @@ foreach(snippet IN LISTS snippets)
endif()
# Verify the overall result, in addition to the sub-commands above.
if (filename MATCHES "^cmakeInstall|^cmakeBuild|^ctest")
if (filename MATCHES "^(cmakeInstall|cmakeBuild|ctest)")
string(JSON result GET "${contents}" result)
if (ARGS_FAIL AND result EQUAL 0)
json_error("${snippet}"
@@ -134,7 +134,7 @@ foreach(snippet IN LISTS snippets)
endif()
# Verify that Config is Debug
if (filename MATCHES "^test|^compile|^link|^custom|^install")
if (filename MATCHES "^(test|compile|link|custom|install)")
string(JSON config GET "${contents}" config)
if (NOT config STREQUAL "Debug")
json_error(${snippet} "Unexpected config: ${config}")
@@ -142,7 +142,7 @@ foreach(snippet IN LISTS snippets)
endif()
# Verify command args were passed
if (filename MATCHES "^cmakeBuild|^ctest")
if (filename MATCHES "^(cmakeBuild|ctest)")
string(JSON command GET "${contents}" command)
if (NOT command MATCHES "Debug")
json_error(${snippet} "Command value missing passed arguments")
@@ -5,7 +5,7 @@ if (NOT EXISTS ${v1}/preBuild.hook)
set(RunCMake_TEST_FAILED "preBuild hook did not run\n")
else()
file(READ ${v1}/preBuild.hook preBuildErrors)
if (NOT preBuildErrors MATCHES "^$")
if (preBuildErrors)
string(APPEND RunCMake_TEST_FAILED "Errors found in data during preBuild hook:\n${preBuildErrors}\n")
endif()
endif()
@@ -36,7 +36,7 @@ if (NOT postBuildRan)
string(APPEND RunCMake_TEST_FAILED "postBuild hook did not run\n")
else()
file(READ ${v1}/postBuild.hook postBuildErrors)
if (NOT postBuildErrors MATCHES "^$")
if (postBuildErrors)
string(APPEND RunCMake_TEST_FAILED "Errors found in data during postBuild hook:\n${postBuildErrors}\n")
endif()
endif()
+1 -1
View File
@@ -200,6 +200,6 @@ if (EXISTS ${v1}/${hook}.hook)
endif()
file(WRITE ${v1}/${hook}.hook "${ERROR_MESSAGE}")
if (NOT ERROR_MESSAGE MATCHES "^$")
if (ERROR_MESSAGE)
message(FATAL_ERROR ${ERROR_MESSAGE})
endif()
+4 -4
View File
@@ -25,9 +25,9 @@ function(json_has_key file json key)
cmake_parse_arguments(ARG "UNEXPECTED" "" "" ${ARGN})
unset(missingKey)
string(JSON ${key} ERROR_VARIABLE missingKey GET "${json}" ${key})
if (NOT ARG_UNEXPECTED AND NOT missingKey MATCHES NOTFOUND)
if (NOT ARG_UNEXPECTED AND missingKey)
json_error("${file}" "Missing key \'${key}\':\n${json}")
elseif (ARG_UNEXPECTED AND missingKey MATCHES NOTFOUND)
elseif (ARG_UNEXPECTED AND NOT missingKey)
json_error("${file}" "\nUnexpected key \'${key}\':\n${json}")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE ${key})
@@ -36,7 +36,7 @@ endfunction()
# Check if the JSON string `json` does not have `key`.
function(json_missing_key file json key)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (missingKey MATCHES NOTFOUND)
if (NOT missingKey)
json_error("${file}" "Has unexpected ${key}.")
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
@@ -46,7 +46,7 @@ endfunction()
# If successful, return its value in `key`.
function(json_assert_key file json key expected)
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
if (NOT missingKey MATCHES NOTFOUND)
if (missingKey)
json_error("${file}" "Missing ${key}.")
endif()
if (NOT ${data} MATCHES ${expected})
@@ -41,20 +41,20 @@ function(snippet_has_fields snippet contents)
if(ARGS_DYNAMIC_QUERY)
json_has_key("${snippet}" "${contents}" dynamicSystemInformation)
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
if (noInfo MATCHES NOTFOUND)
json_has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
json_has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
if (NOT noInfo)
json_has_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
json_has_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
json_has_key("${snippet}" ${dynamicSystemInfo} afterCPULoadAverage)
json_has_key("${snippet}" ${dynamicSystemInfo} afterHostMemoryUsed)
endif()
else()
json_missing_key("${snippet}" "${contents}" dynamicSystemInformation)
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
if (noInfo MATCHES NOTFOUND)
json_missing_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
json_missing_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
if (NOT noInfo)
json_missing_key("${snippet}" ${dynamicSystemInfo} beforeCPULoadAverage)
json_missing_key("${snippet}" ${dynamicSystemInfo} beforeHostMemoryUsed)
json_missing_key("${snippet}" ${dynamicSystemInfo} afterCPULoadAverage)
json_missing_key("${snippet}" ${dynamicSystemInfo} afterHostMemoryUsed)
endif()
endif()
return(PROPAGATE RunCMake_TEST_FAILED ERROR_MESSAGE)
@@ -87,11 +87,11 @@ function(verify_snippet_data snippet contents)
json_error("${snippet}" "Result must be integer, got: ${result}")
endif()
string(JSON outputs ERROR_VARIABLE noOutputs GET "${contents}" outputs)
if (NOT outputs MATCHES NOTFOUND)
if (outputs)
string(JSON outputSizes ERROR_VARIABLE noOutputSizes GET "${contents}" outputSizes)
list(LENGTH outputs outputsLen)
list(LENGTH outputSizes outputSizesLen)
if (outputSizes MATCHES NOTFOUND OR NOT outputsLen EQUAL outputSizesLen)
if (NOT outputSizes OR NOT outputsLen EQUAL outputSizesLen)
json_error("${snippet}" "outputs and outputSizes do not match")
endif()
endif()