Files
Build-System/tests/CliContracts.cmake
T
faumaray 8fd8c34525
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 18s
feat(cli): add vbs binaries list and fetch
2026-12-03 21:10:20 +03:00

158 lines
7.6 KiB
CMake

cmake_minimum_required(VERSION 4.0)
function(check_process expected_code expected_out_regex expected_err_regex)
execute_process(COMMAND "${VBS}" ${ARGN}
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 15)
if(NOT "${code}" STREQUAL "${expected_code}")
message(FATAL_ERROR "vbs ${ARGN}: expected exit ${expected_code}, got ${code}\nstdout=[${out}]\nstderr=[${err}]")
endif()
if(NOT "${expected_out_regex}" STREQUAL "" AND NOT out MATCHES "${expected_out_regex}")
message(FATAL_ERROR "vbs ${ARGN}: stdout did not match [${expected_out_regex}]\nactual=[${out}]")
endif()
if(NOT "${expected_err_regex}" STREQUAL "" AND NOT err MATCHES "${expected_err_regex}")
message(FATAL_ERROR "vbs ${ARGN}: stderr did not match [${expected_err_regex}]\nactual=[${err}]")
endif()
endfunction()
check_process(0 "Usage: vbs .*<command>.*Commands:" "" )
check_process(0 "Usage: vbs .*<command>.*Commands:" "" --help)
check_process(0 "Usage: vbs .*<command>.*Commands:" "" -h)
check_process(0 "^vbs ${VBS_VERSION}\n$" "" --version)
check_process(0 "^vbs ${VBS_VERSION}\n$" "" -V)
check_process(2 "" "unknown option: --invalid" --version --invalid)
check_process(2 "" "--version cannot be combined with subcommands" --version build)
check_process(2 "" "unknown subcommand: invalid" invalid)
check_process(0 "Usage: vbs build .*--native-foreign.*--profile.*\\(repeatable\\)" "" build --help)
check_process(0 "Usage: vbs test " "" test --help)
check_process(0 "Usage: vbs init " "" init --help)
check_process(0 "Usage: vbs clean " "" clean --help)
check_process(0 "Usage: vbs doctor " "" doctor --help)
check_process(0 "Usage: vbs graph " "" graph --help)
check_process(2 "" "unsupported --format" graph --format xml)
check_process(2 "" "multi-profile build requires --editor-profile" build --profile debug --profile release)
check_process(2 "" "must be one of the requested profiles" build --profile debug --profile release --editor-profile custom)
check_process(0 "Usage: vbs compdb <command>.*Commands:.*use.*show.*export.*watch" "" compdb --help)
check_process(0 "Usage: vbs compdb use " "" compdb use --help)
check_process(2 "" "missing subcommand for 'vbs compdb'" compdb)
check_process(2 "" "unknown subcommand: bogus" compdb bogus)
check_process(0 "Usage: vbs deps <command>.*Commands:.*resolve.*update" "" deps --help)
check_process(0 "Usage: vbs deps resolve " "" deps resolve --help)
check_process(2 "" "missing subcommand for 'vbs deps'" deps)
check_process(2 "" "--request and --output are required" bridge)
check_process(0 "Usage: vbs install " "" install --help)
check_process(2 "" "--prefix is required" install)
check_process(2 "" "--prefix is required" uninstall)
check_process(2 "" "--input and --output-dir are required" gen-tests)
check_process(0 "Usage: vbs publish " "" publish --help)
check_process(0 "Usage: vbs publish-binary " "" publish-binary --help)
check_process(0 "Usage: vbs binaries <command>.*Commands:.*list.*fetch" "" binaries --help)
check_process(0 "Usage: vbs binaries list " "" binaries list --help)
check_process(0 "Usage: vbs binaries fetch " "" binaries fetch --help)
check_process(2 "" "--registry, --name, and --version are required" binaries list)
check_process(2 "" "--variant and --output are required" binaries fetch --registry http://127.0.0.1:1 --name p --version 1.0.0)
check_process(2 "" "--registry, --name, --version, --variant, and --file are required" publish-binary)
check_process(2 "" "--registry, --name, and --version are required" publish)
check_process(0 "Usage: vbs daemon <command>.*Commands:.*run.*status.*stop.*recover.*gc.*describe" "" daemon --help)
check_process(0 "Usage: vbs daemon run " "" daemon run --help)
check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --help)
check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemon build --help)
check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query --help)
check_process(0 "Usage: vbs daemon compdb export .*--profile" "" daemon compdb export --help)
check_process(0 "Usage: vbs daemon ide generate .*--profile.*--editor.*--force" "" daemon ide generate --help)
check_process(0 "Usage: vbs daemon ide poll " "" daemon ide poll --help)
check_process(0 "Usage: vbs daemon ide wait .*--timeout-ms" "" daemon ide wait --help)
check_process(2 "" "missing subcommand for 'vbs daemon'" daemon)
# Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over
# the Unix socket, then stop it. The daemon is Unix-only, matching the rest of this suite.
set(daemon_contract_root "${CMAKE_CURRENT_BINARY_DIR}/daemon_contract")
file(REMOVE_RECURSE "${daemon_contract_root}")
file(MAKE_DIRECTORY "${daemon_contract_root}/project")
file(WRITE "${daemon_contract_root}/project/build.cpp" [=[#include <Void/Build.hpp>
void build(Void::Build::Project &project) {
auto app = project.executable("app");
app.sources({"main.cpp"});
}
]=])
file(WRITE "${daemon_contract_root}/project/main.cpp" "int main() { return 0; }\n")
set(daemon_contract_script [=[
set -u
vbs="$1"
project="$2"
build="$3"
out="$4"
log="$5"
"$vbs" daemon run -C "$project" -B "$build" --max-requests 2 >"$log" 2>&1 &
pid=$!
cleanup() {
kill "$pid" 2>/dev/null || true
}
trap cleanup EXIT
socket="$build/.vbs/vbs-daemon.sock"
i=0
while [ ! -S "$socket" ]; do
i=$((i + 1))
if [ "$i" -gt 400 ]; then
echo "daemon socket did not appear" >&2
exit 1
fi
sleep 0.05
done
"$vbs" daemon describe -C "$project" -B "$build" >"$out"
status=$?
"$vbs" daemon stop -C "$project" -B "$build" >/dev/null 2>&1 || true
i=0
while kill -0 "$pid" 2>/dev/null; do
i=$((i + 1))
if [ "$i" -gt 100 ]; then
break
fi
sleep 0.05
done
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
trap - EXIT
exit "$status"
]=])
execute_process(
COMMAND sh -c "${daemon_contract_script}" sh "${VBS}"
"${daemon_contract_root}/project" "${daemon_contract_root}/build"
"${daemon_contract_root}/describe.json" "${daemon_contract_root}/daemon.log"
RESULT_VARIABLE daemon_contract_code
TIMEOUT 180)
set(daemon_contract_log "")
if(EXISTS "${daemon_contract_root}/daemon.log")
file(READ "${daemon_contract_root}/daemon.log" daemon_contract_log)
endif()
if(NOT "${daemon_contract_code}" STREQUAL "0")
message(FATAL_ERROR "vbs daemon describe failed: exit ${daemon_contract_code}\ndaemon log=[${daemon_contract_log}]")
endif()
file(READ "${daemon_contract_root}/describe.json" daemon_describe_out)
if(NOT daemon_describe_out MATCHES "\"ok\":true" OR
NOT daemon_describe_out MATCHES "\"op\":\"describe\"" OR
NOT daemon_describe_out MATCHES "\"target_names\":\\[[^]]*\"app\"")
message(FATAL_ERROR "vbs daemon describe: unexpected response [${daemon_describe_out}]")
endif()
message(STATUS "daemon describe response: ${daemon_describe_out}")
check_process(0 "Usage: vbs ide <command>.*Commands:.*generate.*query" "" ide --help)
check_process(0 "Usage: vbs ide generate " "" ide generate --help)
check_process(0 "Usage: vbs ide query " "" ide query --help)
check_process(2 "" "missing subcommand for 'vbs ide'" ide)
check_process(2 "" "unknown IDE kind" ide generate --editor invalid_ide)
execute_process(COMMAND "${VBS_REGISTRY}" --help
RESULT_VARIABLE reg_code OUTPUT_VARIABLE reg_out ERROR_VARIABLE reg_err TIMEOUT 15)
if(NOT "${reg_code}" STREQUAL "0" OR NOT reg_out MATCHES "Usage: vbs-registry")
message(FATAL_ERROR "vbs-registry --help failed: code=${reg_code}\nstdout=[${reg_out}]\nstderr=[${reg_err}]")
endif()
message(STATUS "CLI and auto-generated Argparse help contracts verified (including daemon describe round-trip)")