mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-14 05:20:50 -05:00
instrumentation: Update tests so that snippet verification runs
Corrects regex matching in Tests/RunCMake/instrumentation so that snippet verification tests aren't skipped over.
This commit is contained in:
@@ -8,6 +8,8 @@ endif()
|
||||
|
||||
set(FOUND_SNIPPETS "")
|
||||
foreach(snippet ${snippets})
|
||||
get_filename_component(filename ${snippet} NAME)
|
||||
|
||||
read_json(${snippet} contents)
|
||||
|
||||
# Verify snippet file is valid
|
||||
@@ -19,7 +21,7 @@ foreach(snippet ${snippets})
|
||||
endif()
|
||||
|
||||
# Verify target
|
||||
string(JSON target ERROR_VARIABLE noTarget GET ${contents} target)
|
||||
string(JSON target ERROR_VARIABLE noTarget GET "${contents}" target)
|
||||
if (NOT target MATCHES NOTFOUND)
|
||||
set(targets "main;lib;customTarget;TARGET_NAME")
|
||||
if (NOT ${target} IN_LIST targets)
|
||||
@@ -28,16 +30,16 @@ foreach(snippet ${snippets})
|
||||
endif()
|
||||
|
||||
# Verify output
|
||||
string(JSON result GET ${contents} result)
|
||||
string(JSON result GET "${contents}" result)
|
||||
if (NOT ${result} EQUAL 0)
|
||||
snippet_error(${snippet} "Compile command had non-0 result")
|
||||
endif()
|
||||
|
||||
# Verify contents of compile-* Snippets
|
||||
if (snippet MATCHES ^compile-)
|
||||
string(JSON target GET ${contents} target)
|
||||
string(JSON source GET ${contents} source)
|
||||
string(JSON language GET ${contents} language)
|
||||
if (filename MATCHES ^compile-)
|
||||
string(JSON target GET "${contents}" target)
|
||||
string(JSON source GET "${contents}" source)
|
||||
string(JSON language GET "${contents}" language)
|
||||
if (NOT language MATCHES "C\\+\\+")
|
||||
snippet_error(${snippet} "Expected C++ compile language")
|
||||
endif()
|
||||
@@ -47,9 +49,9 @@ foreach(snippet ${snippets})
|
||||
endif()
|
||||
|
||||
# Verify contents of link-* Snippets
|
||||
if (snippet MATCHES ^link-)
|
||||
string(JSON target GET ${contents} target)
|
||||
string(JSON targetType GET ${contents} targetType)
|
||||
if (filename MATCHES ^link-)
|
||||
string(JSON target GET "${contents}" target)
|
||||
string(JSON targetType GET "${contents}" targetType)
|
||||
if (target MATCHES main)
|
||||
if (NOT targetType MATCHES "EXECUTABLE")
|
||||
snippet_error(${snippet} "Expected EXECUTABLE, target type was ${targetType}")
|
||||
@@ -63,17 +65,17 @@ foreach(snippet ${snippets})
|
||||
endif()
|
||||
|
||||
# Verify contents of custom-* Snippets
|
||||
if (snippet MATCHES ^custom-)
|
||||
string(JSON outputs GET ${contents} outputs)
|
||||
if (filename MATCHES ^custom-)
|
||||
string(JSON outputs GET "${contents}" outputs)
|
||||
if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2")
|
||||
snippet_error(${snippet} "Custom command missing outputs")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Verify contents of test-* Snippets
|
||||
if (snippet MATCHES ^test-)
|
||||
string(JSON testName GET ${contents} testName)
|
||||
if (NOT testName EQUAL "test")
|
||||
if (filename MATCHES ^test-)
|
||||
string(JSON testName GET "${contents}" testName)
|
||||
if (NOT testName STREQUAL "test")
|
||||
snippet_error(${snippet} "Unexpected testName: ${testName}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -6,7 +6,7 @@ if (NOT ${CMAKE_ARGV3})
|
||||
set(hasStaticInfo "UNEXPECTED")
|
||||
endif()
|
||||
read_json(${index} contents)
|
||||
string(JSON hook GET ${contents} hook)
|
||||
string(JSON hook GET "${contents}" hook)
|
||||
|
||||
# Output is verified by *-stdout.txt files that the HOOK is run
|
||||
message(STATUS ${hook})
|
||||
@@ -19,7 +19,7 @@ endmacro()
|
||||
macro(has_key key json)
|
||||
cmake_parse_arguments(ARG "UNEXPECTED" "" "" ${ARGN})
|
||||
unset(missingKey)
|
||||
string(JSON ${key} ERROR_VARIABLE missingKey GET ${json} ${key})
|
||||
string(JSON ${key} ERROR_VARIABLE missingKey GET "${json}" ${key})
|
||||
if (NOT ARG_UNEXPECTED AND NOT "${missingKey}" MATCHES NOTFOUND)
|
||||
add_error("\nKey \"${key}\" not in index:\n${json}")
|
||||
elseif(ARG_UNEXPECTED AND "${missingKey}" MATCHES NOTFOUND)
|
||||
@@ -39,7 +39,7 @@ endif()
|
||||
string(JSON length LENGTH ${snippets})
|
||||
math(EXPR length ${length}-1)
|
||||
foreach(i RANGE ${length})
|
||||
string(JSON filename GET ${snippets} ${i})
|
||||
string(JSON filename GET "${snippets}" ${i})
|
||||
if (NOT EXISTS ${dataDir}/${filename})
|
||||
add_error("Listed snippet: ${dataDir}/${filename} does not exist")
|
||||
endif()
|
||||
|
||||
@@ -9,44 +9,45 @@ macro(snippet_error snippet error)
|
||||
endmacro()
|
||||
|
||||
macro(has_key snippet json key)
|
||||
string(JSON data ERROR_VARIABLE missingKey GET ${json} ${key})
|
||||
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
|
||||
if (NOT ${missingKey} MATCHES NOTFOUND)
|
||||
snippet_error(${snippet} "Missing ${key}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(has_not_key snippet json key)
|
||||
string(JSON data ERROR_VARIABLE missingKey GET ${json} ${key})
|
||||
string(JSON data ERROR_VARIABLE missingKey GET "${json}" ${key})
|
||||
if (${missingKey} MATCHES NOTFOUND)
|
||||
snippet_error(${snippet} "Has unexpected ${key}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(snippet_has_fields snippet contents)
|
||||
get_filename_component(filename ${snippet} NAME)
|
||||
has_key(${snippet} ${contents} command)
|
||||
has_key(${snippet} ${contents} role)
|
||||
has_key(${snippet} ${contents} result)
|
||||
if (snippet MATCHES ^link-*)
|
||||
if (filename MATCHES ^link-*)
|
||||
has_key(${snippet} ${contents} target)
|
||||
has_key(${snippet} ${contents} outputs)
|
||||
has_key(${snippet} ${contents} outputSizes)
|
||||
has_key(${snippet} ${contents} targetType)
|
||||
elseif (snippet MATCHES ^compile-*)
|
||||
elseif (filename MATCHES ^compile-*)
|
||||
has_key(${snippet} ${contents} target)
|
||||
has_key(${snippet} ${contents} outputs)
|
||||
has_key(${snippet} ${contents} outputSizes)
|
||||
has_key(${snippet} ${contents} source)
|
||||
has_key(${snippet} ${contents} language)
|
||||
elseif (snippet MATCHES ^custom-*)
|
||||
elseif (filename MATCHES ^custom-*)
|
||||
has_key(${snippet} ${contents} target)
|
||||
has_key(${snippet} ${contents} outputs)
|
||||
has_key(${snippet} ${contents} outputSizes)
|
||||
elseif (snippet MATCHES ^test-*)
|
||||
elseif (filename MATCHES ^test-*)
|
||||
has_key(${snippet} ${contents} testName)
|
||||
endif()
|
||||
if(ARGS_DYNAMIC_QUERY)
|
||||
has_key(${snippet} ${contents} dynamicSystemInformation)
|
||||
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET ${contents} dynamicSystemInformation)
|
||||
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
|
||||
if (noInfo MATCHES NOTFOUND)
|
||||
has_key(${snippet} ${dynamicSystemInfo} beforeCPULoadAverage)
|
||||
has_key(${snippet} ${dynamicSystemInfo} beforeHostMemoryUsed)
|
||||
@@ -55,7 +56,7 @@ macro(snippet_has_fields snippet contents)
|
||||
endif()
|
||||
else()
|
||||
has_not_key(${snippet} ${contents} dynamicSystemInformation)
|
||||
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET ${contents} dynamicSystemInformation)
|
||||
string(JSON dynamicSystemInfo ERROR_VARIABLE noInfo GET "${contents}" dynamicSystemInformation)
|
||||
if (noInfo MATCHES NOTFOUND)
|
||||
has_not_key(${snippet} ${dynamicSystemInfo} beforeCPULoadAverage)
|
||||
has_not_key(${snippet} ${dynamicSystemInfo} beforeHostMemoryUsed)
|
||||
@@ -66,8 +67,8 @@ macro(snippet_has_fields snippet contents)
|
||||
endmacro()
|
||||
|
||||
macro(snippet_valid_timing contents)
|
||||
string(JSON start GET ${contents} timeStart)
|
||||
string(JSON duration GET ${contents} duration)
|
||||
string(JSON start GET "${contents}" timeStart)
|
||||
string(JSON duration GET "${contents}" duration)
|
||||
if (${start} LESS 0)
|
||||
snippet_error(${snippet} "Negative time start: ${start}")
|
||||
endif()
|
||||
@@ -79,18 +80,18 @@ endmacro()
|
||||
macro(verify_snippet snippet contents)
|
||||
snippet_has_fields(${snippet} ${contents})
|
||||
snippet_valid_timing(${contents})
|
||||
string(JSON version GET ${contents} version)
|
||||
string(JSON version GET "${contents}" version)
|
||||
if (NOT ${version} EQUAL 1)
|
||||
snippet_error(${snippet} "Version must be 1, got: ${version}")
|
||||
endif()
|
||||
string(JSON role GET ${contents} role)
|
||||
string(JSON role GET "${contents}" role)
|
||||
get_filename_component(filename ${snippet} NAME)
|
||||
if (NOT ${filename} MATCHES ^${role}-)
|
||||
snippet_error(${snippet} "Role \"${role}\" doesn't match snippet filename")
|
||||
endif()
|
||||
string(JSON outputs ERROR_VARIABLE noOutputs GET ${contents} outputs)
|
||||
string(JSON outputs ERROR_VARIABLE noOutputs GET "${contents}" outputs)
|
||||
if (NOT outputs MATCHES NOTFOUND)
|
||||
string(JSON outputSizes ERROR_VARIABLE noOutputSizes GET ${contents} outputSizes)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user