Files
Build-System/tests/DescribeContracts.cmake
T
2026-11-27 06:51:43 +03:00

106 lines
5.1 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(VoidBuildSdk 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(VoidBuildCore targets 1 name)
expect_json(static_library targets 1 kind)
expect_json(VoidBuildSdk targets 1 links 0 target)
expect_json(public targets 1 links 0 visibility)
expect_json(VoidLibrary targets 1 links 1 dependency)
expect_json(Void::Configuration targets 1 links 1 target)
expect_json(GenerateBootstrapConfig targets 2 name)
expect_json(custom_action targets 2 kind)
expect_json(vbs targets 3 name)
expect_json(executable targets 3 kind)
expect_json(VoidBuildCore targets 3 links 0 target)
expect_json(private targets 3 links 0 visibility)
expect_json(VoidBuildRegistry targets 4 name)
expect_json(static_library targets 4 kind)
expect_json(vbs-registry targets 5 name)
expect_json(executable targets 5 kind)
expect_json(vbs_self_smoke targets 6 name)
expect_json(test targets 6 kind)
expect_json(vbs_benchmarks targets 7 name)
expect_json(executable targets 7 kind)
expect_json(vbs_sdk_tests targets 8 name)
expect_json(test targets 8 kind)
expect_json(vbs_core_tests targets 9 name)
expect_json(test targets 9 kind)
expect_json(vbs_v1_tests targets 10 name)
expect_json(test targets 10 kind)
expect_json(vbs_registry_tests targets 11 name)
expect_json(test targets 11 kind)
expect_json(vbs_selfhost_tests targets 12 name)
expect_json(test targets 12 kind)
foreach(index IN ITEMS 0 1 3 4 5 6 7 8 9 10 11 12)
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(3e254055e081a104f08df68dde39711bc7813518 dependencies 0 source revision)
expect_json(native 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()
execute_process(COMMAND "${DESCRIBE}" --help
RESULT_VARIABLE help_code OUTPUT_VARIABLE help_out ERROR_VARIABLE help_err TIMEOUT 10)
if(NOT "${help_code}" STREQUAL "0" OR NOT "${help_err}" STREQUAL "" OR
NOT help_out MATCHES "Usage: vbs_describe")
message(FATAL_ERROR "vbs_describe --help failed: code=${help_code}\nstdout=[${help_out}]\nstderr=[${help_err}]")
endif()
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)
message(STATUS "Four runtime profile/compiler contexts, generated help, and five error contracts verified")