// 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; namespace { std::int32_t Failures = 0; void Check(bool cond, std::string_view msg) { if (!cond) { std::println(std::cerr, "FAIL: {}", msg); ++Failures; } } } // `crafter-build install` and `bundle` refuse what they cannot export before // anything is built: whether the project's executable is packaged as a // Flatpak, and whether the host's flatpak can be reached, is known once the // project is loaded. Refused after the build, the likely first try, // `install` in a project that sets no packaging, would compile the whole // project into a directory nothing exports, and the retry with // --packaging=flatpak into another. The fixture is an executable that is // not packaged: Run() refuses both verbs, saying why, and no bin/ appears. int main() { const fs::path installedHome = GetCrafterBuildHome(); if (!fs::exists(installedHome / "Crafter.Build.cppm")) { std::println(std::cerr, "SKIP: no module sources at {}", installedHome.string()); return 77; } // Staged because LoadProject drops a build/ tree next to the project // file it compiles. const fs::path scratch = fs::temp_directory_path() / "crafter-build-flatpak-verb-refusal"; std::error_code ec; fs::remove_all(scratch, ec); fs::copy(fs::current_path() / "tests" / "FlatpakVerbRefusal" / "fixture", scratch, fs::copy_options::recursive); // From the project's own directory, as crafter-build runs it. const fs::path cwd = fs::current_path(); fs::current_path(scratch); for (const std::string_view verb : {"install", "bundle"}) { std::string tool = "crafter-build"; std::string word(verb); std::array argv = { tool.data(), word.data() }; std::ostringstream err; std::streambuf* const saved = std::cerr.rdbuf(err.rdbuf()); const std::int32_t status = Run(static_cast(argv.size()), argv.data()); std::cerr.rdbuf(saved); Check(status == 1, std::format("{} refuses (exit {}): {}", verb, status, err.str())); Check(err.str().contains("is not packaged as a Flatpak"), std::format("{} says why: {}", verb, err.str())); Check(!fs::exists(scratch / "bin"), std::format("{} refuses before anything is built: there is no bin/", verb)); } fs::current_path(cwd); fs::remove_all(scratch, ec); if (Failures > 0) { std::println(std::cerr, "{} assertions failed", Failures); return 1; } return 0; }