Files
Build-System/tests/DescribeContracts.cmake
T
faumaray 3cac890ce9 bootstrap
Signed-off-by: faumaray <faumaray@gmail.com>
2026-11-25 01:32:43 +03:00

76 lines
3.6 KiB
CMake

cmake_minimum_required(VERSION 4.0)
function(expect_json expected)
string(JSON actual GET "${graph}" ${ARGN})
if(NOT "${actual}" STREQUAL "${expected}")
message(FATAL_ERROR "JSON ${ARGN}: expected [${expected}], got [${actual}]")
endif()
endfunction()
foreach(profile IN ITEMS debug release)
foreach(compiler IN ITEMS gcc clang)
execute_process(COMMAND "${DESCRIBE}" --profile "${profile}" --compiler "${compiler}"
RESULT_VARIABLE code OUTPUT_VARIABLE graph ERROR_VARIABLE err TIMEOUT 10)
if(NOT "${code}" STREQUAL "0" OR NOT "${err}" STREQUAL "")
message(FATAL_ERROR "Description ${profile}/${compiler} failed: ${code}\n${err}")
endif()
expect_json(1 schema_version)
string(JSON schema_type TYPE "${graph}" schema_version)
if(NOT schema_type STREQUAL "NUMBER")
message(FATAL_ERROR "schema_version must be an integer JSON number")
endif()
expect_json("${profile}" profile name)
expect_json("${compiler}" profile compiler)
expect_json("${EXPECTED_OS}" profile os)
expect_json("${EXPECTED_ARCH}" profile architecture)
if(profile STREQUAL "debug")
expect_json(-O0 profile compile_options 0)
expect_json(-g profile compile_options 1)
else()
expect_json(-O3 profile compile_options 0)
expect_json(-DNDEBUG profile compile_options 1)
endif()
expect_json(vbs_sdk targets 0 name)
expect_json(static_library targets 0 kind)
expect_json(file targets 0 sources 0 kind)
expect_json(src/build.cpp targets 0 sources 0 path)
expect_json(public targets 0 include_directories 0 visibility)
expect_json(vbs targets 1 name)
expect_json(executable targets 1 kind)
expect_json(vbs_sdk targets 1 links 0 target)
expect_json(private targets 1 links 0 visibility)
expect_json(VoidLibrary targets 1 links 1 dependency)
expect_json(Void::Configuration targets 1 links 1 target)
foreach(index IN ITEMS 0 1)
if(compiler STREQUAL "gcc")
expect_json(-Wduplicated-cond targets "${index}" compile_options 2)
else()
expect_json(-Wextra-semi targets "${index}" compile_options 2)
endif()
endforeach()
expect_json(git dependencies 0 source kind)
expect_json(9931c5ffc4844a5e09e1b1db35b3d29c5097c3a5 dependencies 0 source revision)
expect_json(cmake dependencies 0 builder)
string(JSON option_type TYPE "${graph}" dependencies 0 options BUILD_SHARED_LIBS)
if(NOT option_type STREQUAL "BOOLEAN")
message(FATAL_ERROR "CMake bool option lost its type")
endif()
endforeach()
endforeach()
function(expect_error expected)
execute_process(COMMAND "${DESCRIBE}" ${ARGN}
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 10)
if(NOT "${code}" STREQUAL "2" OR NOT "${out}" STREQUAL "" OR
NOT "${err}" STREQUAL "vbs_describe: ${expected}\n")
message(FATAL_ERROR "Description error ${ARGN}: ${code}\nstdout=[${out}]\nstderr=[${err}]")
endif()
endfunction()
expect_error("unknown profile 'unknown'" --profile unknown)
expect_error("unknown compiler 'msvc' (expected gcc or clang)" --compiler msvc)
expect_error("option '--profile' requires a value" --profile)
expect_error("unknown option: --invalid" --invalid)
expect_error("unexpected positional argument: invalid" invalid)
expect_error("--help must be used alone" --help --invalid)
message(STATUS "Four runtime profile/compiler contexts and six error contracts verified")