TestBuilder::Path after AddTest moves a test's outputs, not the sources it compiles #54

Open
opened 2026-11-27 09:24:49 +00:00 by jorijnvdgraaf · 0 comments

Summary

TestBuilder::Path is documented as "Override the path the test's sources resolve against" (interfaces/Crafter.Build-Test.cppm:35). By then AddTest has resolved them: it sets the test's path to ./ and calls GetInterfacesAndImplementations (implementations/Crafter.Build-Test.cpp:380 and :400), which makes each source absolute against the path at that call (implementations/Crafter.Build-Clang.cpp:479 and :484). Path (implementations/Crafter.Build-Test.cpp:434) then sets config.path alone, which decides where the test's build and bin directories go.

So cfg.AddTest("t").Path("sub") compiles tests/t/main.cpp, not sub/tests/t/main.cpp, and puts its program under sub/bin/ and its object under sub/build/…/objects-outside/, followed by the source's absolute path.

The same with 6.4.1 (the stable Flatpak) and with 578a1da (6.4.2). No project.cpp among the Catcrafts checkouts on the development machine calls Path on a test.

Line numbers refer to 578a1da (6.4.2).

Reproduce

A project with main.cpp, tests/t/main.cpp (int main() { return 0; }), sub/tests/t/main.cpp (int main() { return 1; }) and this project.cpp:

import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;

extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
    Configuration cfg;
    cfg.path = "./";
    cfg.name = "path-check";
    cfg.outputName = "path-check";
    ApplyStandardArgs(cfg, args);
    cfg.type = ConfigurationType::Executable;
    {
        std::array<fs::path, 0> ifaces = {};
        std::array<fs::path, 1> impls = { "main" };
        cfg.GetInterfacesAndImplementations(ifaces, impls);
    }
    cfg.AddTest("t").Path("sub");
    return cfg;
}

crafter-build test, with 578a1da (the project's directory written <project>):

[4/4] Compiling <project>/tests/t/main.cpp
[5/5] Linking t
✅ t (3ms)

1 passed

and the test's program and object:

./sub/bin/t-x86_64-pc-linux-gnu-native-native-70265063b80021eb/t
./sub/build/t-x86_64-pc-linux-gnu-native-native-70265063b80021eb/objects-outside/<project>/tests/t/main_impl.o

Proposal

Have Path resolve the test's sources against the new path: AddTest would keep them as they were named and resolve them again when Path changes. If Path is meant to move only the outputs, its comment should say that.

## Summary `TestBuilder::Path` is documented as "Override the path the test's sources resolve against" (`interfaces/Crafter.Build-Test.cppm:35`). By then `AddTest` has resolved them: it sets the test's path to `./` and calls `GetInterfacesAndImplementations` (`implementations/Crafter.Build-Test.cpp:380` and `:400`), which makes each source absolute against the path at that call (`implementations/Crafter.Build-Clang.cpp:479` and `:484`). `Path` (`implementations/Crafter.Build-Test.cpp:434`) then sets `config.path` alone, which decides where the test's build and bin directories go. So `cfg.AddTest("t").Path("sub")` compiles `tests/t/main.cpp`, not `sub/tests/t/main.cpp`, and puts its program under `sub/bin/` and its object under `sub/build/…/objects-outside/`, followed by the source's absolute path. The same with 6.4.1 (the stable Flatpak) and with `578a1da` (6.4.2). No `project.cpp` among the Catcrafts checkouts on the development machine calls `Path` on a test. Line numbers refer to `578a1da` (6.4.2). ## Reproduce A project with `main.cpp`, `tests/t/main.cpp` (`int main() { return 0; }`), `sub/tests/t/main.cpp` (`int main() { return 1; }`) and this `project.cpp`: ```cpp import std; import Crafter.Build; namespace fs = std::filesystem; using namespace Crafter; extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) { Configuration cfg; cfg.path = "./"; cfg.name = "path-check"; cfg.outputName = "path-check"; ApplyStandardArgs(cfg, args); cfg.type = ConfigurationType::Executable; { std::array<fs::path, 0> ifaces = {}; std::array<fs::path, 1> impls = { "main" }; cfg.GetInterfacesAndImplementations(ifaces, impls); } cfg.AddTest("t").Path("sub"); return cfg; } ``` `crafter-build test`, with `578a1da` (the project's directory written `<project>`): ``` [4/4] Compiling <project>/tests/t/main.cpp [5/5] Linking t ✅ t (3ms) 1 passed ``` and the test's program and object: ``` ./sub/bin/t-x86_64-pc-linux-gnu-native-native-70265063b80021eb/t ./sub/build/t-x86_64-pc-linux-gnu-native-native-70265063b80021eb/objects-outside/<project>/tests/t/main_impl.o ``` ## Proposal Have `Path` resolve the test's sources against the new path: `AddTest` would keep them as they were named and resolve them again when `Path` changes. If `Path` is meant to move only the outputs, its comment should say that.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Build#54
No description provided.