// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® import std; import Crafter.Build; namespace fs = std::filesystem; using namespace Crafter; // `--version` has to work from any directory, before a project file is // looked for, and must be answered rather than forwarded to project.cpp as // one more unknown argument. namespace { std::int32_t Failures = 0; void Check(bool cond, std::string_view msg) { if (!cond) { std::println(std::cerr, "FAIL: {}", msg); ++Failures; } } std::int32_t RunWith(std::vector args) { std::vector argv; for (std::string& arg : args) argv.push_back(arg.data()); return Run(static_cast(argv.size()), argv.data()); } } int main() { Check(!CrafterBuildVersion().empty(), "a version string is always baked in"); // An empty directory: no project.cpp to fall back to. const fs::path scratch = fs::temp_directory_path() / "crafter-build-version-flag"; std::error_code ec; fs::remove_all(scratch, ec); fs::create_directories(scratch); fs::current_path(scratch); Check(RunWith({"crafter-build", "--version"}) == 0, "--version exits 0 without a project file"); Check(RunWith({"crafter-build", "--version", "--some-project-flag"}) == 0, "--version is answered before unknown arguments are forwarded"); Check(RunWith({"crafter-build", "--some-project-flag", "--version"}) == 0, "--version is answered wherever it appears"); fs::current_path(fs::temp_directory_path()); fs::remove_all(scratch, ec); return Failures == 0 ? 0 : 1; }