commit
3cac890ce9
57 files changed
+4043
No files matched your search
@@ -0,0 +1,17 @@
|
||||
add_executable(vbs_sdk_tests SdkDeclarations.cpp ExampleContexts.cpp)
|
||||
target_link_libraries(vbs_sdk_tests PRIVATE vbs_example_description)
|
||||
set_target_properties(vbs_sdk_tests PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
add_test(NAME vbs_sdk_tests COMMAND "${CMAKE_COMMAND}"
|
||||
"-DSDK_TESTS=$<TARGET_FILE:vbs_sdk_tests>" -P "${CMAKE_CURRENT_SOURCE_DIR}/RunSdkTests.cmake")
|
||||
void_add_tests(vbs_sdk_tests)
|
||||
|
||||
add_test(NAME vbs_sdk_registration COMMAND "${CMAKE_COMMAND}"
|
||||
"-DSDK_TESTS=$<TARGET_FILE:vbs_sdk_tests>" -P "${CMAKE_CURRENT_SOURCE_DIR}/SdkRegistration.cmake")
|
||||
add_test(NAME vbs_cli_contract COMMAND "${CMAKE_COMMAND}"
|
||||
"-DVBS=$<TARGET_FILE:vbs>" "-DVBS_VERSION=${PROJECT_VERSION}"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/CliContracts.cmake")
|
||||
add_test(NAME vbs_description_contract COMMAND "${CMAKE_COMMAND}"
|
||||
"-DDESCRIBE=$<TARGET_FILE:vbs_describe>"
|
||||
"-DEXPECTED_OS=${CMAKE_SYSTEM_NAME}" "-DEXPECTED_ARCH=${CMAKE_SYSTEM_PROCESSOR}"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/DescribeContracts.cmake")
|
||||
@@ -0,0 +1,28 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
function(check_process expected_code expected_stdout expected_stderr)
|
||||
execute_process(COMMAND "${VBS}" ${ARGN}
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 10)
|
||||
if(NOT "${code}" STREQUAL "${expected_code}" OR
|
||||
NOT "${out}" STREQUAL "${expected_stdout}" OR
|
||||
NOT "${err}" STREQUAL "${expected_stderr}")
|
||||
message(FATAL_ERROR "vbs ${ARGN}: expected exit ${expected_code}, got ${code}\nstdout=[${out}]\nstderr=[${err}]")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(help "Usage: vbs [--version]\n\nVoidBuildSystem bootstrap: help and version only.\nNative build, test, compdb, deps and watch commands are planned and unavailable.\n\nFlags:\n --version, -V show bootstrap version\n --help, -h show this help\n")
|
||||
check_process(0 "${help}" "")
|
||||
check_process(0 "${help}" "" --help)
|
||||
check_process(0 "${help}" "" -h)
|
||||
check_process(0 "vbs ${VBS_VERSION} (bootstrap)\n" "" --version)
|
||||
check_process(0 "vbs ${VBS_VERSION} (bootstrap)\n" "" -V)
|
||||
check_process(2 "" "vbs: unknown option: --invalid\n" --invalid)
|
||||
check_process(2 "" "vbs: unknown option: --invalid\n" --version --invalid)
|
||||
check_process(2 "" "vbs: unexpected positional argument: invalid\n" invalid)
|
||||
check_process(2 "" "vbs: --help must be used alone\n" --help --invalid)
|
||||
foreach(command IN ITEMS build test compdb deps watch)
|
||||
check_process(2 "" "vbs: native command '${command}' is not implemented in this bootstrap\n" "${command}")
|
||||
endforeach()
|
||||
check_process(2 "" "vbs: native command 'build' is not implemented in this bootstrap\n" build --profile debug)
|
||||
check_process(2 "" "vbs: native command 'compdb' is not implemented in this bootstrap\n" compdb watch)
|
||||
message(STATUS "16 CLI process contracts verified")
|
||||
@@ -0,0 +1,75 @@
|
||||
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")
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <vbs/build.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
Void::Testing::Test example_uses_runtime_compiler() {
|
||||
vbs::Profiles definitions;
|
||||
profiles(definitions);
|
||||
vbs::Project gcc{definitions.resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
vbs::Project clang{definitions.resolve("debug", vbs::CompilerFamily::clang, "linux", "x86_64")};
|
||||
build(gcc);
|
||||
build(clang);
|
||||
for (std::size_t index = 0; index < gcc.targets().size(); ++index) {
|
||||
Void::Testing::expect(std::ranges::contains(gcc.targets().at(index).compile_options,
|
||||
std::string{"-Wduplicated-cond"}));
|
||||
Void::Testing::expect(!std::ranges::contains(gcc.targets().at(index).compile_options,
|
||||
std::string{"-Wextra-semi"}));
|
||||
Void::Testing::expect(std::ranges::contains(clang.targets().at(index).compile_options,
|
||||
std::string{"-Wextra-semi"}));
|
||||
Void::Testing::expect(!std::ranges::contains(clang.targets().at(index).compile_options,
|
||||
std::string{"-Wduplicated-cond"}));
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test example_profile_options_are_separate() {
|
||||
vbs::Profiles definitions;
|
||||
profiles(definitions);
|
||||
vbs::Project debug{definitions.resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
vbs::Project release{
|
||||
definitions.resolve("release", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
build(debug);
|
||||
build(release);
|
||||
Void::Testing::expect(
|
||||
std::ranges::contains(debug.context().compile_options, std::string{"-g"}));
|
||||
Void::Testing::expect(
|
||||
std::ranges::contains(release.context().compile_options, std::string{"-O3"}));
|
||||
Void::Testing::expect(
|
||||
!std::ranges::contains(release.context().compile_options, std::string{"-g"}));
|
||||
Void::Testing::expect(debug.to_json() != release.to_json());
|
||||
}
|
||||
|
||||
Void::Testing::Test example_records_sources_links_and_pin() {
|
||||
vbs::Project project{
|
||||
vbs::default_profiles().resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64")};
|
||||
build(project);
|
||||
Void::Testing::expect_eq(project.targets().size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(project.targets().at(0).name, std::string{"vbs_sdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(0).sources.at(0).path,
|
||||
std::string{"src/build.cpp"});
|
||||
Void::Testing::expect_eq(project.targets().at(1).links.at(0).target, std::string{"vbs_sdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(1).links.at(1).target,
|
||||
std::string{"Void::Configuration"});
|
||||
Void::Testing::expect_eq(project.dependencies().at(0).revision,
|
||||
std::string{"9931c5ffc4844a5e09e1b1db35b3d29c5097c3a5"});
|
||||
Void::Testing::expect_eq(project.dependencies().at(0).builder, std::string{"cmake"});
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
execute_process(COMMAND "${SDK_TESTS}" --no-color
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 60)
|
||||
message("${out}")
|
||||
if(NOT "${code}" STREQUAL "0" OR NOT out MATCHES "17 tests:")
|
||||
message(FATAL_ERROR "SDK suite must execute all 17 cases and exit zero; got ${code}\n${err}")
|
||||
endif()
|
||||
@@ -0,0 +1,288 @@
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
#include <vbs/build.hpp>
|
||||
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace {
|
||||
vbs::ProfileContext context() {
|
||||
return vbs::default_profiles().resolve("debug", vbs::CompilerFamily::gcc, "linux", "x86_64");
|
||||
}
|
||||
constexpr auto revision = "9931c5ffc4844a5e09e1b1db35b3d29c5097c3a5";
|
||||
using Json = Void::Json::Strict::Value;
|
||||
const Json &member(const Json &value, const std::string &key) {
|
||||
return std::get<Json::Object>(value.value).at(key);
|
||||
}
|
||||
const Json &element(const Json &value, std::size_t index) {
|
||||
return std::get<Json::Array>(value.value).at(index);
|
||||
}
|
||||
std::string text(const Json &value) { return std::get<std::string>(value.value); }
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test default_profiles_and_overrides() {
|
||||
const auto profiles = vbs::default_profiles();
|
||||
const auto debug = profiles.resolve("debug", vbs::CompilerFamily::clang, "linux", "aarch64");
|
||||
const auto release = profiles.resolve("release", vbs::CompilerFamily::gcc, "linux", "x86_64");
|
||||
Void::Testing::expect_eq(profiles.records().size(), std::size_t{2});
|
||||
Void::Testing::expect(debug.compiler == vbs::CompilerFamily::clang);
|
||||
Void::Testing::expect_eq(debug.architecture, std::string{"aarch64"});
|
||||
Void::Testing::expect_eq(debug.compile_options.at(0), std::string{"-O0"});
|
||||
Void::Testing::expect_eq(release.compile_options.at(0), std::string{"-O3"});
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_invalid_profiles() {
|
||||
auto profiles = vbs::default_profiles();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add("debug"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { profiles.add("bad", {""}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)profiles.resolve("unknown", vbs::CompilerFamily::gcc, "linux", "x86_64"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([] { (void)vbs::parse_compiler("msvc"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)profiles.resolve("debug", vbs::CompilerFamily::gcc, "", "x86_64"); });
|
||||
}
|
||||
|
||||
Void::Testing::Test declaration_records_and_visibility() {
|
||||
vbs::Project project{context()};
|
||||
auto library = project.static_library("library");
|
||||
library.sources({"one.cpp", "two.cpp"})
|
||||
.include_directory("include", vbs::Visibility::public_)
|
||||
.compile_option("-Wall");
|
||||
auto executable = project.executable("app");
|
||||
executable.link(library).link(library, vbs::Visibility::interface_);
|
||||
Void::Testing::expect(library.record().kind == vbs::TargetKind::static_library);
|
||||
Void::Testing::expect_eq(library.record().sources.size(), std::size_t{2});
|
||||
Void::Testing::expect(library.record().include_directories.at(0).visibility ==
|
||||
vbs::Visibility::public_);
|
||||
Void::Testing::expect(executable.record().links.at(0).visibility == vbs::Visibility::private_);
|
||||
Void::Testing::expect(executable.record().links.at(1).visibility ==
|
||||
vbs::Visibility::interface_);
|
||||
}
|
||||
|
||||
Void::Testing::Test sources_are_symbolic() {
|
||||
vbs::Project project{context()};
|
||||
auto target = project.executable("symbolic");
|
||||
target.sources({"missing/../literal.cpp"}).sources(project.glob("nonexistent/**/*.cpp"));
|
||||
Void::Testing::expect_eq(target.record().sources.at(0).path,
|
||||
std::string{"missing/../literal.cpp"});
|
||||
Void::Testing::expect(target.record().sources.at(0).kind == vbs::SourceKind::file);
|
||||
Void::Testing::expect(target.record().sources.at(1).kind == vbs::SourceKind::glob);
|
||||
Void::Testing::expect_eq(target.record().sources.at(1).path,
|
||||
std::string{"nonexistent/**/*.cpp"});
|
||||
}
|
||||
|
||||
Void::Testing::Test handles_survive_record_growth() {
|
||||
vbs::Project project{context()};
|
||||
auto library = project.static_library("first");
|
||||
auto dependency = project.dependency("original");
|
||||
const auto imported = dependency.target("Original::Library");
|
||||
for (int i = 0; i != 256; ++i) {
|
||||
(void)project.executable("target" + std::to_string(i));
|
||||
(void)project.dependency("dependency" + std::to_string(i));
|
||||
}
|
||||
dependency.git("https://example.invalid/library.git", vbs::Commit{revision}).cmake();
|
||||
library.compile_option("-Wextra");
|
||||
auto app = project.executable("last");
|
||||
app.link(library).link(imported);
|
||||
Void::Testing::expect_eq(project.targets().front().compile_options.at(0),
|
||||
std::string{"-Wextra"});
|
||||
Void::Testing::expect_eq(app.record().links.at(0).target, std::string{"first"});
|
||||
Void::Testing::expect_eq(app.record().links.at(1).dependency, std::string{"original"});
|
||||
Void::Testing::expect_eq(project.dependencies().front().revision, std::string{revision});
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_cross_project_links() {
|
||||
vbs::Project first{context()};
|
||||
vbs::Project second{context()};
|
||||
auto app = first.executable("app");
|
||||
auto other = second.static_library("other");
|
||||
auto imported = second.dependency("remote").target("Remote::Library");
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.link(other); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.link(imported); });
|
||||
Void::Testing::expect(app.record().links.empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_expired_handles_and_owner_moves() {
|
||||
static_assert(!std::is_move_constructible_v<vbs::Project>);
|
||||
static_assert(!std::is_copy_constructible_v<vbs::Project>);
|
||||
std::optional<vbs::Target> target;
|
||||
std::optional<vbs::Dependency> dependency;
|
||||
std::optional<vbs::ImportedTarget> imported;
|
||||
{
|
||||
vbs::Project project{context()};
|
||||
target = project.executable("expired");
|
||||
dependency = project.dependency("expired");
|
||||
imported = dependency->target("Expired::Target");
|
||||
}
|
||||
vbs::Project replacement{context()};
|
||||
auto app = replacement.executable("new");
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { target->compile_option("-g"); });
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { dependency->cmake(); });
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { (void)target->record(); });
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { app.link(*target); });
|
||||
Void::Testing::expect_throw<std::logic_error>([&] { app.link(*imported); });
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_empty_and_duplicate_identifiers() {
|
||||
vbs::Project project{context()};
|
||||
auto app = project.executable("app");
|
||||
auto dep = project.dependency("dep");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { (void)project.static_library("app"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.dependency("dep"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.executable(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.dependency(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)dep.target(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.include_directory(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { app.compile_option(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([] { (void)vbs::SourceSet::file(""); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.glob(""); });
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_contradictory_providers() {
|
||||
vbs::Project project{context()};
|
||||
auto git = project.dependency("git");
|
||||
git.git("https://example.invalid/repo", vbs::Commit{revision}).cmake();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { git.package("pkg", "^1"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { git.git("url", vbs::Commit{revision}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { git.cmake(); });
|
||||
auto package = project.dependency("package");
|
||||
package.package("pkg", "^1");
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { package.git("url", vbs::Commit{revision}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { package.cmake(); });
|
||||
auto builder = project.dependency("builder");
|
||||
builder.cmake();
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { builder.package("pkg", "^1"); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[&] { builder.git("url", vbs::Commit{"main"}); });
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)project.to_json(); });
|
||||
}
|
||||
|
||||
Void::Testing::Test json_schema_types_and_escaping() {
|
||||
vbs::Project project{context()};
|
||||
std::string escaped = "quote\" slash\\ newline\n\r\t";
|
||||
for (char c = 0; c < 32; ++c)
|
||||
escaped += c;
|
||||
auto dep = project.dependency("dependency");
|
||||
dep.git("https://example.invalid/\"repo", vbs::Commit{revision})
|
||||
.cmake({{"string", escaped},
|
||||
{"literal", "text"},
|
||||
{"bool", false},
|
||||
{"integer", -42},
|
||||
{"maximum", std::numeric_limits<std::int64_t>::max()}});
|
||||
auto library = project.static_library("library");
|
||||
library.sources(vbs::SourceSet::file(escaped))
|
||||
.sources(project.glob("src/**/*.cpp"))
|
||||
.include_directory("include", vbs::Visibility::public_)
|
||||
.link(dep.target("Remote::Library"));
|
||||
auto app = project.executable("app");
|
||||
app.link(library, vbs::Visibility::public_).compile_option(escaped);
|
||||
project.dependency("package").package("org/pkg", ">=1.2 <2");
|
||||
const auto json = project.to_json();
|
||||
Void::Testing::expect_eq(json, project.to_json());
|
||||
const auto parsed = Void::Json::Strict::parse(json);
|
||||
Void::Testing::expect(parsed.has_value());
|
||||
if (!parsed)
|
||||
return;
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(member(*parsed, "schema_version").value),
|
||||
std::int64_t{1});
|
||||
const auto &dependency = element(member(*parsed, "dependencies"), 0);
|
||||
const auto &options = member(dependency, "options");
|
||||
Void::Testing::expect_eq(text(member(options, "string")), escaped);
|
||||
Void::Testing::expect_eq(text(member(options, "literal")), std::string{"text"});
|
||||
Void::Testing::expect(!std::get<bool>(member(options, "bool").value));
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(member(options, "integer").value),
|
||||
std::int64_t{-42});
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(member(options, "maximum").value),
|
||||
std::numeric_limits<std::int64_t>::max());
|
||||
const auto &target = element(member(*parsed, "targets"), 0);
|
||||
Void::Testing::expect_eq(text(member(element(member(target, "sources"), 0), "path")), escaped);
|
||||
Void::Testing::expect_eq(text(member(element(member(target, "sources"), 1), "kind")),
|
||||
std::string{"glob"});
|
||||
Void::Testing::expect_eq(text(member(element(member(target, "links"), 0), "dependency")),
|
||||
std::string{"dependency"});
|
||||
Void::Testing::expect_eq(
|
||||
text(member(member(element(member(*parsed, "dependencies"), 1), "source"), "package")),
|
||||
std::string{"org/pkg"});
|
||||
}
|
||||
|
||||
Void::Testing::Test json_preserves_valid_utf8() {
|
||||
// Boundary scalar values for every UTF-8 width, including either side of surrogates.
|
||||
const std::string unicode = "ASCII \xc2\x80\xdf\xbf\xe0\xa0\x80\xed\x9f\xbf"
|
||||
"\xee\x80\x80\xef\xbf\xbf\xf0\x90\x80\x80\xf4\x8f\xbf\xbf";
|
||||
vbs::Project project{context()};
|
||||
project.executable(unicode).sources(vbs::SourceSet::file(unicode));
|
||||
project.dependency("unicode").git("url", vbs::Commit{revision}).cmake({{unicode, unicode}});
|
||||
const auto json = project.to_json();
|
||||
Void::Testing::expect(json.find(unicode) != std::string::npos);
|
||||
const auto parsed = Void::Json::Strict::parse(json);
|
||||
Void::Testing::expect(parsed.has_value());
|
||||
if (!parsed)
|
||||
return;
|
||||
const auto &target = element(member(*parsed, "targets"), 0);
|
||||
Void::Testing::expect_eq(text(member(target, "name")), unicode);
|
||||
Void::Testing::expect_eq(text(member(element(member(target, "sources"), 0), "path")), unicode);
|
||||
const auto &options = member(element(member(*parsed, "dependencies"), 0), "options");
|
||||
Void::Testing::expect_eq(text(member(options, unicode)), unicode);
|
||||
}
|
||||
|
||||
Void::Testing::Test json_rejects_malformed_utf8() {
|
||||
const std::vector<std::string> invalid{
|
||||
"\x80", "\xbf", "\xc0\x80", "\xc1\xbf", "\xc2",
|
||||
"\xc2 ", "\xe0\x80\x80", "\xe0\x9f\xbf", "\xe1\x80", "\xe1 \x80",
|
||||
"\xe1\x80 ", "\xed\xa0\x80", "\xed\xbf\xbf", "\xf0\x80\x80\x80", "\xf0\x8f\xbf\xbf",
|
||||
"\xf0\x90\x80", "\xf1\x80\x80 ", "\xf4\x90\x80\x80", "\xf5\x80\x80\x80", "\xfe",
|
||||
"\xff"};
|
||||
for (const auto &bytes : invalid) {
|
||||
const auto malformed = "prefix" + bytes + "suffix";
|
||||
vbs::Project named{context()};
|
||||
(void)named.executable(bytes);
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)named.to_json(); });
|
||||
|
||||
vbs::Project sourced{context()};
|
||||
sourced.executable("source").sources(vbs::SourceSet::file(malformed));
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)sourced.to_json(); });
|
||||
|
||||
vbs::Project keyed{context()};
|
||||
keyed.dependency("key").git("url", vbs::Commit{revision}).cmake({{malformed, true}});
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)keyed.to_json(); });
|
||||
|
||||
vbs::Project valued{context()};
|
||||
valued.dependency("value").git("url", vbs::Commit{revision}).cmake({{"option", malformed}});
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)valued.to_json(); });
|
||||
|
||||
auto profile = context();
|
||||
profile.compile_options.push_back(malformed);
|
||||
vbs::Project configured{profile};
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { (void)configured.to_json(); });
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test independent_projects_and_contexts() {
|
||||
auto initial = context();
|
||||
vbs::Project first{initial};
|
||||
initial.name = "mutated";
|
||||
vbs::Project second{
|
||||
vbs::default_profiles().resolve("release", vbs::CompilerFamily::clang, "linux", "aarch64")};
|
||||
first.executable("first").compile_option("-g");
|
||||
Void::Testing::expect_eq(first.context().name, std::string{"debug"});
|
||||
Void::Testing::expect_eq(second.context().name, std::string{"release"});
|
||||
Void::Testing::expect(second.targets().empty());
|
||||
Void::Testing::expect(first.to_json() != second.to_json());
|
||||
}
|
||||
|
||||
Void::Testing::Test rejects_option_errors_without_mutation() {
|
||||
vbs::Project project{context()};
|
||||
auto dep = project.dependency("library");
|
||||
Void::Testing::expect_throw<std::invalid_argument>([&] { dep.cmake({{"", true}}); });
|
||||
Void::Testing::expect(dep.record().builder.empty());
|
||||
Void::Testing::expect_throw<std::invalid_argument>(
|
||||
[] { (void)vbs::OptionValue{std::numeric_limits<std::uint64_t>::max()}; });
|
||||
dep.cmake({{"enabled", true}}).git("url", vbs::Commit{revision});
|
||||
Void::Testing::expect_eq(dep.record().options.size(), std::size_t{1});
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
execute_process(COMMAND "${SDK_TESTS}" --list --no-color
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 20)
|
||||
if(NOT "${code}" STREQUAL "0" OR NOT "${err}" STREQUAL "")
|
||||
message(FATAL_ERROR "SDK test discovery failed: ${code}\n${out}\n${err}")
|
||||
endif()
|
||||
set(expected
|
||||
SdkDeclarations.default_profiles_and_overrides
|
||||
SdkDeclarations.rejects_invalid_profiles
|
||||
SdkDeclarations.declaration_records_and_visibility
|
||||
SdkDeclarations.sources_are_symbolic
|
||||
SdkDeclarations.handles_survive_record_growth
|
||||
SdkDeclarations.rejects_cross_project_links
|
||||
SdkDeclarations.rejects_expired_handles_and_owner_moves
|
||||
SdkDeclarations.rejects_empty_and_duplicate_identifiers
|
||||
SdkDeclarations.rejects_contradictory_providers
|
||||
SdkDeclarations.json_schema_types_and_escaping
|
||||
SdkDeclarations.json_preserves_valid_utf8
|
||||
SdkDeclarations.json_rejects_malformed_utf8
|
||||
SdkDeclarations.independent_projects_and_contexts
|
||||
SdkDeclarations.rejects_option_errors_without_mutation
|
||||
ExampleContexts.example_uses_runtime_compiler
|
||||
ExampleContexts.example_profile_options_are_separate
|
||||
ExampleContexts.example_records_sources_links_and_pin)
|
||||
string(REPLACE "\n" ";" discovered "${out}")
|
||||
list(FILTER discovered EXCLUDE REGEX "^$")
|
||||
foreach(name IN LISTS expected)
|
||||
if(NOT name IN_LIST discovered)
|
||||
message(FATAL_ERROR "Missing SDK regression case: ${name}\n${out}")
|
||||
endif()
|
||||
endforeach()
|
||||
list(LENGTH discovered count)
|
||||
if(count LESS 17)
|
||||
message(FATAL_ERROR "Expected at least 17 SDK cases, found ${count}")
|
||||
endif()
|
||||
# Observe that filtering executes a named registered body, rather than only listing it.
|
||||
execute_process(COMMAND "${SDK_TESTS}" --no-color --filter "^SdkDeclarations.json_schema_types_and_escaping$"
|
||||
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 20)
|
||||
if(NOT "${code}" STREQUAL "0" OR NOT out MATCHES "1 tests:" OR
|
||||
NOT out MATCHES "json_schema_types_and_escaping")
|
||||
message(FATAL_ERROR "Named SDK case did not execute successfully: ${code}\n${out}\n${err}")
|
||||
endif()
|
||||
message(STATUS "${count} SDK test registrations verified; named JSON case executed")
|
||||
Reference in new issue
Block a user