# ~~~
# Copyright (c) 2026-2026 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~

find_package(Python3 REQUIRED COMPONENTS Interpreter)

function(add_vulkan_python_test TARGET_NAME SCRIPT_FILENAME)
    set(REGISTRY_PATH "${VULKAN_HEADERS_INSTALL_DIR}/${CMAKE_INSTALL_DATADIR}/vulkan/registry")
    set(FULL_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT_FILENAME}")

    # Register the script as a CTest test case
    add_test(NAME ${TARGET_NAME}
        COMMAND ${Python3_EXECUTABLE} "${FULL_SCRIPT_PATH}" --registry "${REGISTRY_PATH}/vk.xml"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
    )

    # Cleanly inject environment variables into the test environment
    set_tests_properties(${TARGET_NAME} PROPERTIES
        ENVIRONMENT "PYTHONPATH=${REGISTRY_PATH}"
    )
endfunction()

if(NOT APPLE) # macOS doesn't handle dynamically loading Python jsonschema'
    add_vulkan_python_test(VpTestVulkanProfilesUtil test_util.py)
    #add_vulkan_python_test(VpTestVulkanObjectEmpty   test_init.py) requires Header 357
    #add_vulkan_python_test(VpTestVulkanObjectUtils   test_vulkan_object_utils.py) requires Header 357
    add_vulkan_python_test(VpTestVulkanObjectDepends test_vulkan_object_expression_parsing.py)
    add_vulkan_python_test(VpTestVulkanProfilesJson  test_vulkan_profiles.py)
endif()
