Some checks failed
CI / build-test-release (push) Failing after 7m15s
63 lines
2.4 KiB
C++
63 lines
2.4 KiB
C++
// 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;
|
|
|
|
// Build an executable that imports a project-local .cppm module, then run
|
|
// it and check the produced output. Exercises the within-project module
|
|
// dependency path (main.cpp imports Greeter, resolved through cfg.interfaces).
|
|
int main() {
|
|
Configuration cfg;
|
|
cfg.path = fs::current_path() / "tests" / "ModuleInterface" / "fixture";
|
|
cfg.name = "greeter-app";
|
|
cfg.outputName = "greeter-app";
|
|
cfg.target = HostTarget();
|
|
cfg.type = ConfigurationType::Executable;
|
|
|
|
std::array<fs::path, 1> ifaces = { "Greeter" };
|
|
std::array<fs::path, 1> impls = { "main" };
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
|
|
|
// Implementation should have picked up the import Greeter; through the
|
|
// interface list resolution in GetInterfacesAndImplementations.
|
|
if (cfg.implementations.size() != 1) {
|
|
std::println(std::cerr, "expected 1 implementation, got {}", cfg.implementations.size());
|
|
return 1;
|
|
}
|
|
if (cfg.implementations[0].moduleDependencies.size() != 1) {
|
|
std::println(std::cerr, "expected main.cpp to depend on 1 module, got {}", cfg.implementations[0].moduleDependencies.size());
|
|
return 1;
|
|
}
|
|
if (cfg.implementations[0].moduleDependencies[0]->name != "Greeter") {
|
|
std::println(std::cerr, "expected dep 'Greeter', got '{}'", cfg.implementations[0].moduleDependencies[0]->name);
|
|
return 1;
|
|
}
|
|
|
|
std::unordered_map<fs::path, std::shared_future<BuildResult>> depResults;
|
|
std::mutex depMutex;
|
|
BuildResult r = Build(cfg, depResults, depMutex);
|
|
if (!r.result.empty()) {
|
|
std::println(std::cerr, "build failed: {}", r.result);
|
|
return 1;
|
|
}
|
|
|
|
fs::path bin = cfg.BinDir() / "greeter-app";
|
|
if (!fs::exists(bin)) {
|
|
std::println(std::cerr, "binary not produced at {}", bin.string());
|
|
return 1;
|
|
}
|
|
|
|
auto run = RunCommandWithTimeout(bin.string(), std::chrono::seconds(10));
|
|
if (run.exitCode != 0 || run.timedOut || run.crashed) {
|
|
std::println(std::cerr, "binary did not exit cleanly: exit={} output={}", run.exitCode, run.output);
|
|
return 1;
|
|
}
|
|
if (run.output != "ok-from-module") {
|
|
std::println(std::cerr, "unexpected output: '{}'", run.output);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|