From 703eaf5ca2dd684786a25531cdbfca85d96d35ac Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Fri, 24 Apr 2026 14:24:33 -0400 Subject: [PATCH] Tests/instrumentation: Simplify some conditionals --- .../Instrumentation/check-data-dir.cmake | 8 ++++---- .../check-make-program-hooks.cmake | 4 ++-- Tests/RunCMake/Instrumentation/hook.cmake | 2 +- Tests/RunCMake/Instrumentation/json.cmake | 8 ++++---- .../Instrumentation/verify-snippet.cmake | 16 ++++++++-------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/RunCMake/Instrumentation/check-data-dir.cmake b/Tests/RunCMake/Instrumentation/check-data-dir.cmake index bb3f4ec7e0..6faa0860fe 100644 --- a/Tests/RunCMake/Instrumentation/check-data-dir.cmake +++ b/Tests/RunCMake/Instrumentation/check-data-dir.cmake @@ -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") diff --git a/Tests/RunCMake/Instrumentation/check-make-program-hooks.cmake b/Tests/RunCMake/Instrumentation/check-make-program-hooks.cmake index 01336e70d3..60c05152b8 100644 --- a/Tests/RunCMake/Instrumentation/check-make-program-hooks.cmake +++ b/Tests/RunCMake/Instrumentation/check-make-program-hooks.cmake @@ -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() diff --git a/Tests/RunCMake/Instrumentation/hook.cmake b/Tests/RunCMake/Instrumentation/hook.cmake index 412ef4a094..d9638a2963 100644 --- a/Tests/RunCMake/Instrumentation/hook.cmake +++ b/Tests/RunCMake/Instrumentation/hook.cmake @@ -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() diff --git a/Tests/RunCMake/Instrumentation/json.cmake b/Tests/RunCMake/Instrumentation/json.cmake index d45e769df0..1c59475490 100644 --- a/Tests/RunCMake/Instrumentation/json.cmake +++ b/Tests/RunCMake/Instrumentation/json.cmake @@ -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}) diff --git a/Tests/RunCMake/Instrumentation/verify-snippet.cmake b/Tests/RunCMake/Instrumentation/verify-snippet.cmake index b169f52759..a784cf9b89 100644 --- a/Tests/RunCMake/Instrumentation/verify-snippet.cmake +++ b/Tests/RunCMake/Instrumentation/verify-snippet.cmake @@ -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()