Crafter.Build/tests/Script/fixture/project.cpp

30 lines
1.3 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
using namespace Crafter;
// Scripts that report what they were handed. The test that loads this file
// drives the real command line and can only observe a script through its
// exit code and through what it leaves in the project directory.
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration cfg;
cfg.path = "./";
cfg.name = "script-fixture";
cfg.outputName = "script-fixture";
// Applied so that a script argument which leaked into the project's
// args would be visible: in cfg.projectArgs, or as cfg.debug.
ApplyStandardArgs(cfg, args);
cfg.scripts.push_back({"record", [](ScriptContext& ctx) {
std::ofstream out(ctx.projectDir / "record.txt");
for (const std::string& arg : ctx.args) std::println(out, "arg:{}", arg);
for (const std::string& arg : ctx.project.projectArgs) std::println(out, "projectArg:{}", arg);
std::println(out, "debug:{}", ctx.project.debug);
std::println(out, "project:{}", ctx.project.name);
return 42;
}});
cfg.scripts.push_back({"shell", [](ScriptContext& ctx) { return ctx.Run("exit 7"); }});
return cfg;
}