# The ctest opt-in fixture: the cheapest possible registered tests -- no compiled
# test executable -- prove the invocation, the ordering (tests run before the
# staging) and the failure propagation (a failing suite produces no distribution).

cmake_minimum_required(VERSION 3.21)

enable_testing()

project(TestCMakePIPCtest)

option(FIXTURE_FAILING_TEST "register a test that fails, for the negative case" OFF)

find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
find_package(cmakepip REQUIRED)

python3_add_library(cmake_test MODULE WITH_SOABI
    src/python_header.hpp
    src/python_dummy_ext.cpp)

python_package_add_target(TARGET cmake_test
                          PYTHON_PACKAGE ctest_test
                          DESTINATION ext_with_ctest)

# the probe: its output string in the pip log is what the test asserts on
add_test(NAME cmakepip_probe
         COMMAND ${CMAKE_COMMAND} -E echo cmake_pip_ctest_probe)

if(FIXTURE_FAILING_TEST)
  # `cmake -E false` exists since 3.16, below the 3.21 floor of this project
  add_test(NAME cmakepip_failing COMMAND ${CMAKE_COMMAND} -E false)
endif()
