2026-07-22 18:16:38 +02:00
|
|
|
//SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
|
|
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
|
|
|
import std;
|
|
|
|
|
import Crafter.Build;
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
// Build a tiny module-only static library and confirm libgreet.a lands in
|
|
|
|
|
// BinDir(). Exercises ConfigurationType::LibraryStatic, interface module
|
|
|
|
|
// parsing via GetInterfacesAndImplementations, and the ar/llvm-lib archive
|
|
|
|
|
// step in Crafter.Build-Clang.cpp.
|
|
|
|
|
int main() {
|
|
|
|
|
Configuration cfg;
|
|
|
|
|
cfg.path = fs::current_path() / "tests" / "StaticLib" / "fixture";
|
|
|
|
|
cfg.name = "greet";
|
|
|
|
|
cfg.outputName = "greet";
|
|
|
|
|
cfg.target = HostTarget();
|
|
|
|
|
cfg.type = ConfigurationType::LibraryStatic;
|
|
|
|
|
|
|
|
|
|
std::array<fs::path, 1> ifaces = { "Greet" };
|
|
|
|
|
std::array<fs::path, 0> impls = {};
|
|
|
|
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
|
|
|
|
|
|
|
|
|
if (cfg.interfaces.size() != 1) {
|
|
|
|
|
std::println(std::cerr, "expected 1 interface, got {}", cfg.interfaces.size());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (cfg.interfaces[0]->name != "Greet") {
|
|
|
|
|
std::println(std::cerr, "expected interface 'Greet', got '{}'", cfg.interfaces[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 archive = cfg.BinDir() / "libgreet.a";
|
|
|
|
|
if (!fs::exists(archive)) {
|
|
|
|
|
std::println(std::cerr, "archive not produced at {}", archive.string());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (fs::file_size(archive) == 0) {
|
|
|
|
|
std::println(std::cerr, "archive {} is empty", archive.string());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|