test: several configurations from one project file
BuildAll builds configurations the test makes itself, on a fresh copy of its fixture outside the checkout. A library, a program built on it and an unrelated program all come out built, each in the record of the pass under its PcmDir, and a list that names one configuration twice builds it from nothing, what the build before left of it being removed first, and leaves it in the record of the pass once. A library built on another library of its own name, path and type, so that the two are built into one directory, builds, with both archives in that directory; returned beside a program that is built on it, the pair is refused, both by name, before the program is built or anything is recorded. Two libraries that are each built on a configuration of the other's directory are refused by name, and nothing of them is built or recorded. A wasm32 library that names no sysroot and a program for the host built on it leave the library in the record once, under the directory it has after the pass, and its refusal comes back once; it is refused for its -fno-exceptions, so the case needs no WASI sysroot. Of two programs built on a library that does not compile and a third that has nothing to do with it, the third is built, the two are not, and the library's error comes back once. Two configurations that would be built into one directory are refused, and neither is built. With a wasm executable that declares a variant among them, a program of one source is linked no earlier than the program and library given before it; the wasm one is refused for its -fno-exceptions before it builds anything, so the case needs no WASI sysroot. ProjectConfigurations loads fixture project files staged outside the checkout. A file with CrafterBuildConfigurations comes back as the three configurations it returns, with the pointer the file took from the second to the first intact, and as two when its args say so; LoadProject refuses it. A file with CrafterBuildProject comes back as a list of one whose test still depends on that Configuration, and that test builds and passes. A file with both entry points, one with neither, and ones whose CrafterBuildConfigurations returns nothing, a null pointer or one configuration twice are refused, each with a message that says which. Then crafter-build's verbs, through Run() and RunTests, on the file of three: a build builds all three; -r refuses to pick between its two executables, and runs the one executable there is when the file returns two configurations; RunTests runs the tests of the first and the third configuration in one run, and when the first declares the third's test as well, that test fails for both, naming the two, and is not built, while the first's own test passes, and a list that names the first configuration twice runs its test once; with a fourth configuration of the third's name and path, a test run and a build are each refused for the two that would be built into one directory, and neither writes the AGENTS.md that a build which is not refused writes from the template the test puts beside the project file; `run` reaches a script of the first and of the third configuration and hands each the configuration that declares it; install refuses the project while none of the three is packaged, bundle refuses it when two are, and with one packaged executable beside the library bundle does not take the library for the app. SiblingConfigurations loads such a file as another project's sibling. A spec without `configuration` gets the first, a spec that names one gets that one, and the three specs share one load: the dependency of the second is the first as LocalProject returned it. All three are rebased onto the sibling's directory. A name the sibling does not have throws with the names it has, and a name that two configurations of another fixture share throws too, while a spec without a name still gets the first of those two. Building the second builds the first with it and leaves the third unbuilt. A file that returns something a sibling keeps to itself is refused when it is loaded, the configuration and the sibling named: the library the sibling's program is built on, the configuration of that program's test, and a helper only that test is built on, none of which the sibling's file returns. A project that returns the sibling's third configuration beside one of its own builds both, cannot run the sibling's script and runs its own, and its test run leaves the sibling's test alone. DependencyNotes gains a project of two configurations and a fixture, outer, that builds against lib: two Direct configurations give what each of them names; a project a Direct one names is followed when a Transitive one leads to it; a configuration under None keeps out what only it is built against; with both under None, AGENTS.md is the template's text; and a returned configuration of another project is one of the projects the notes come from, followed further only under Transitive, which is also what a file that made no configuration gets. For outer's own AGENTS.md, written from the Configuration LocalProject returned and outer's project file, outer's own setting selects: lib under Direct, lib and base under Transitive, nothing under None. Script runs a script of each of two configurations, each handed the configuration that declares it, refuses a name both declare without running anything, and, given a list that names one configuration twice, runs the script asked for, which a name declared twice would have kept it from. Lint formats the sources of two configurations in one run, counts a rule both register as one, and runs a rule only one of them registers over the sources of both. Of two returned configurations that register a rule under one name the earlier one's runs, over the sources of all three, though the configuration returned ahead of both depends on the later one.
This commit is contained in:
parent
4283a3ecd2
commit
5795b666f5
42 changed files with 1427 additions and 5 deletions
|
|
@ -294,6 +294,86 @@ int main() {
|
|||
Check(Read(agents) == generated, "under None, AGENTS.md holds the template's text alone");
|
||||
cfg.dependencyNotes = DependencyNotes::Transitive;
|
||||
|
||||
// A project file that returns several configurations: each one's setting
|
||||
// selects among what that one is built against, and the notes are
|
||||
// merged. `second` stands in for a second configuration of app's project
|
||||
// file, and outer is a project that builds against lib, and so against
|
||||
// base one ring further out.
|
||||
{
|
||||
Configuration* outer = nullptr;
|
||||
try {
|
||||
outer = LocalProject({ .projectFile = scratch / "outer" / "project.cpp" });
|
||||
} catch (const std::exception& e) {
|
||||
std::println(std::cerr, "FAIL: loading outer threw: {}", e.what());
|
||||
return 1;
|
||||
}
|
||||
Configuration* const baseProject = cfg.dependencies[0]->dependencies[0];
|
||||
Configuration second;
|
||||
std::array<const Configuration*, 2> both = { &cfg, &second };
|
||||
// The projects the section names, in its order, once AGENTS.md is
|
||||
// written for `configurations`.
|
||||
const auto named = [&](std::span<const Configuration* const> configurations) {
|
||||
(void)UpdateAgentsMd(configurations, projectFile);
|
||||
const std::string now = Read(agents);
|
||||
constexpr std::string_view from = "<!-- from ";
|
||||
std::vector<std::string> names;
|
||||
for (std::size_t pos = now.find(from); pos != std::string::npos; pos = now.find(from, pos + 1)) {
|
||||
names.push_back(now.substr(pos + from.size(), now.find(" -->", pos) - pos - from.size()));
|
||||
}
|
||||
return names;
|
||||
};
|
||||
using Names = std::vector<std::string>;
|
||||
|
||||
cfg.dependencyNotes = DependencyNotes::Direct;
|
||||
second.dependencies = { outer };
|
||||
second.dependencyNotes = DependencyNotes::Direct;
|
||||
Check(named(both) == Names{"tool", "lib", "outer"}, std::format("two Direct configurations give what each of them names (got {})", named(both)));
|
||||
// lib is in the first ring through app, which asks for no more. The
|
||||
// second configuration reaches it through outer and asks for
|
||||
// everything, so what lib builds against is in.
|
||||
second.dependencyNotes = DependencyNotes::Transitive;
|
||||
Check(named(both) == Names{"tool", "lib", "outer", "base"}, std::format("a project a Direct configuration names is followed when a Transitive one leads to it (got {})", named(both)));
|
||||
cfg.dependencyNotes = DependencyNotes::None;
|
||||
second.dependencies = { baseProject };
|
||||
Check(named(both) == Names{"tool", "base"}, std::format("a configuration under None keeps out what only it is built against (got {})", named(both)));
|
||||
second.dependencyNotes = DependencyNotes::None;
|
||||
Check(named(both).empty() && Read(agents) == generated, "with every configuration under None, AGENTS.md holds the template's text alone");
|
||||
|
||||
// A configuration the file loaded from another project and returns
|
||||
// is one of the projects it is built against, and its own setting
|
||||
// counts for nothing here: it goes by the widest of the others.
|
||||
std::array<const Configuration*, 2> withOuter = { &cfg, outer };
|
||||
cfg.dependencyNotes = DependencyNotes::Direct;
|
||||
Check(named(withOuter) == Names{"tool", "lib", "outer"}, std::format("a returned configuration of another project is in the first ring, and under Direct no more of it (got {})", named(withOuter)));
|
||||
cfg.dependencyNotes = DependencyNotes::Transitive;
|
||||
Check(named(withOuter) == Names{"tool", "lib", "outer", "base"}, std::format("under Transitive what it builds against follows (got {})", named(withOuter)));
|
||||
std::array<const Configuration*, 1> onlyOuter = { outer };
|
||||
Check(named(onlyOuter) == Names{"tool", "outer", "lib", "base"}, std::format("a file that made no configuration itself gets everything (got {})", named(onlyOuter)));
|
||||
|
||||
// The same Configuration, for outer's own AGENTS.md: outer's project
|
||||
// file made it, so here its setting is the one that selects, though
|
||||
// a loader holds it. Told apart by being held, it was another
|
||||
// project's configuration to its own file, and got everything.
|
||||
const fs::path outerFile = scratch / "outer" / "project.cpp";
|
||||
const fs::path outerAgents = scratch / "outer" / "AGENTS.md";
|
||||
Write(scratch / "outer" / "AGENTS.template.md", templateText);
|
||||
const auto outerNamed = [&](DependencyNotes setting) {
|
||||
outer->dependencyNotes = setting;
|
||||
(void)UpdateAgentsMd(*outer, outerFile);
|
||||
const std::string now = Read(outerAgents);
|
||||
constexpr std::string_view from = "<!-- from ";
|
||||
Names names;
|
||||
for (std::size_t pos = now.find(from); pos != std::string::npos; pos = now.find(from, pos + 1)) {
|
||||
names.push_back(now.substr(pos + from.size(), now.find(" -->", pos) - pos - from.size()));
|
||||
}
|
||||
return names;
|
||||
};
|
||||
Check(outerNamed(DependencyNotes::Direct) == Names{"lib"}, std::format("a project loaded by another gets what its own Direct selects in its own AGENTS.md (got {})", outerNamed(DependencyNotes::Direct)));
|
||||
Check(outerNamed(DependencyNotes::Transitive) == Names{"lib", "base"}, std::format("and what its Transitive does (got {})", outerNamed(DependencyNotes::Transitive)));
|
||||
Check(outerNamed(DependencyNotes::None).empty() && Read(outerAgents) == generated, "and under None the template's text alone");
|
||||
outer->dependencyNotes = DependencyNotes::Transitive;
|
||||
}
|
||||
|
||||
// Linked to the template, AGENTS.md would have every build write the
|
||||
// file that is committed.
|
||||
fs::remove(agents);
|
||||
|
|
|
|||
Loading…
Reference in a new issue