Skip to content

Commit c382ae0

Browse files
test: a pattern names a part of a program as the run names it; the Windows ACP check selects its cases by id
- `mcpp test <pattern>` matches a program or a part of one run as a process per file of its cases (`unit/test_home`): one rule (test_matches) for the plan's tests, a workspace's members and an archive. - check_windows_home_legacy.py runs its two cases with --case and reads mtest's lines. - The self-standing rule of the tests' graph lives in graph_edges.cpp (graph.cpp within its length). Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 472829a commit c382ae0

10 files changed

Lines changed: 73 additions & 45 deletions

‎.github/tools/check_windows_home_legacy.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414
assert original.count(marker) == 1, 'identify the test-only code-page setting explicitly'
1515

1616

17-
def run_case(pattern, passed_case):
18-
result = subprocess.run([os.environ['MCPP'], '--offline', 'test', pattern], cwd=root,
17+
def run_case(passed_case):
18+
# The case by its identifier (mtest's): it runs in the process of its file.
19+
result = subprocess.run([os.environ['MCPP'], '--offline', 'test', '--case', passed_case], cwd=root,
1920
capture_output=True, text=True, encoding='utf-8', errors='replace',
2021
timeout=600)
2122
sys.stdout.write(result.stdout)
2223
sys.stderr.write(result.stderr)
2324
assert result.returncode == 0, result.returncode
2425
output = re.sub(r'\x1b\[[0-9;]*m', '', result.stdout + result.stderr)
25-
assert '[ OK ] ' + passed_case in output, \
26+
assert re.search(r'^\s*ok\s+' + re.escape(passed_case) + r'\s*$', output, re.M), \
2627
'the legacy ACP case did not pass; a UTF-8-only skip is not proof'
2728

2829

2930
try:
3031
manifest.write_bytes(original.replace(marker, b'windows_code_page = "legacy"', 1))
31-
run_case('home', 'HomeSelection.UnicodeLocatorRoundTripDoesNotNarrowTheSelectedPath')
32-
run_case('bmi_cache', 'BMICacheMaintenance.RunnerCachePathDoesNotUseTheWindowsAnsiCodePage')
32+
run_case('HomeSelection/UnicodeLocatorRoundTripDoesNotNarrowTheSelectedPath')
33+
run_case('BMICacheMaintenance/RunnerCachePathDoesNotUseTheWindowsAnsiCodePage')
3334
finally:
3435
manifest.write_bytes(original)
3536
print('PASS: home and runner-cache paths ran under legacy Windows ACP; manifest restored')

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
`mtest report`, `analyze` and `graph`. The tests of an archive run by the
6060
same runner (`mcpp test --archive`): their protocol, recorded in
6161
`mcpp-tests.json`, a process per file of their cases, the workers and the
62-
store. mcpp's own unit tests are one program per directory: 166
62+
store. A pattern names a part as the run names it (`mcpp test unit/test_home`).
63+
mcpp's own unit tests are one program per directory: 166
6364
programs of 32 MB became one of 37 MB, run as 166 processes.
6465
- clang pairs with the MinGW-w64 payload for `x86_64-windows-gnu`: the payload
6566
is clang's sysroot and libstdc++ its C++ library, `import std` included.

‎docs/08-testing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ cases** (2026.11.9.1+): mcpp lists the cases of a program of several files, and
7272
each file's run selects its own (P4) and is scheduled across the workers as a program is, named
7373
`<program>/<file>` -- the isolation and the parallelism of a program per file,
7474
with one link. `[test] split = "case"` gives each case its own process, and
75-
`"none"` runs the program once.
75+
`"none"` runs the program once. A pattern names a program or a part of one as
76+
the run names it: `mcpp test unit/test_home` (or `home`) runs that file's part.
7677

7778
A test program keeps what it reaches (2026.11.9.1+): units are compiled with one
7879
section per function and per object, and a test links with `--gc-sections`

‎docs/zh/08-testing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ discover = ["checks/**/*.cpp", "!checks/fixtures/**"]
6161
使用测试协议的程序**按其用例所在文件各起一个进程**运行(2026.11.9.1+):mcpp 先列出多文件程序的用例,
6262
每个文件的那次运行只选取自己的用例(P4),像一个程序一样在各工作线程间调度,名为
6363
`<程序>/<文件>`——兼得每文件一个程序的隔离与并行,而只链接一次。`[test] split = "case"`
64-
使每个用例一个进程,`"none"` 只运行一次。
64+
使每个用例一个进程,`"none"` 只运行一次。模式按运行所用的名字指名程序或其一部分:`mcpp test unit/test_home`(或 `home`)
65+
运行该文件的那一部分。
6566

6667
测试程序只保留它用到的部分(2026.11.9.1+):各单元以每函数、每数据对象一个节编译,
6768
测试以 `--gc-sections` 链接(Mach-O 为 `-dead_strip`),测某一模块的测试不再带上整个包

‎src/build/execute.cppm‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,15 @@ static void print_test_guide(const BuildContext& ctx, bool json) {
42834283
// backend that drives it, how long planning and the build took, and how the
42844284
// test binaries are executed. One per configuration group of a `mcpp test`
42854285
// over several members; `run_tests` holds one for its one member.
4286+
// WHETHER A PATTERN NAMES A TEST: its program, or a part of one run as a
4287+
// process per file of its cases (`<program>/<file>'), as the run names them.
4288+
static bool test_matches(const LinkUnit& lu, std::string_view filter) {
4289+
if (filter.empty() || lu.targetName.find(filter) != std::string::npos) return true;
4290+
return std::ranges::any_of(lu.ownSources, [&](const std::filesystem::path& f) {
4291+
return std::format("{}/{}", lu.targetName, f.stem().generic_string()).find(filter) != std::string::npos;
4292+
});
4293+
}
4294+
42864295
// A TEST PROGRAM TO RUN: built by this command, or read from an archive.
42874296
struct TestRunnable {
42884297
std::string name;
@@ -4708,8 +4717,7 @@ static int test_run_member(TestBuild& tb, const TestOptions& testOpts,
47084717
return lu.kind == mcpp::build::LinkUnit::TestBinary
47094718
&& (owner.empty() || lu.memberOf == owner)
47104719
&& (!tb.affected || tb.affected->contains(lu.targetName))
4711-
&& (testOpts.filter.empty()
4712-
|| lu.targetName.find(testOpts.filter) != std::string::npos);
4720+
&& test_matches(lu, testOpts.filter);
47134721
};
47144722
std::vector<TestResult> results;
47154723
auto emit_json = [&](const TestResult& r) {
@@ -5397,11 +5405,14 @@ static int test_run_member(TestBuild& tb, const TestOptions& testOpts,
53975405
// The largest first, so the longest work starts first.
53985406
std::ranges::stable_sort(ordered, std::greater{}, [](auto const& g) { return g.second.size(); });
53995407
std::size_t n = 0;
5408+
// A pattern that named a part, not its program, keeps that part.
5409+
const bool whole = testOpts.filter.empty() || r.name.find(testOpts.filter) != std::string::npos;
54005410
for (auto& [key, ids] : ordered) {
54015411
Runnable part = r;
54025412
const auto label = split == "case" ? key
54035413
: std::filesystem::path(key).stem().generic_string();
54045414
part.name = std::format("{}/{}", r.name, label);
5415+
if (!whole && part.name.find(testOpts.filter) == std::string::npos) continue;
54055416
part.protocolDir = r.protocolDir / "split" / std::to_string(n++);
54065417
std::error_code ec;
54075418
std::filesystem::create_directories(part.protocolDir, ec);
@@ -5554,7 +5565,7 @@ int write_test_archive(const TestOptions& o, std::span<const ArchiveLeg> legs) {
55545565
leg.triple = l.triple;
55555566
for (auto const& lu : l.ctx->plan.linkUnits) {
55565567
if (lu.kind != LinkUnit::TestBinary) continue;
5557-
if (!o.filter.empty() && lu.targetName.find(o.filter) == std::string::npos) continue;
5568+
if (!test_matches(lu, o.filter)) continue;
55585569
const auto exe = l.ctx->outputDir / lu.output;
55595570
if (!fs::is_regular_file(exe, ec)) continue;
55605571
ta::Test t{lu.targetName, ta::test_dest(l.triple, lu.targetName, exe.filename().string()), {},
@@ -5882,8 +5893,7 @@ export int run_tests(std::span<const std::string> passthrough,
58825893
// filtered run must not clobber it down to one entry).
58835894
auto filter_match = [&](const mcpp::build::LinkUnit& lu) {
58845895
return lu.kind == mcpp::build::LinkUnit::TestBinary
5885-
&& (testOpts.filter.empty()
5886-
|| lu.targetName.find(testOpts.filter) != std::string::npos);
5896+
&& test_matches(lu, testOpts.filter);
58875897
};
58885898
if (!testOpts.filter.empty()) {
58895899
bool any = false;
@@ -6053,8 +6063,7 @@ export int run_test_legs(std::span<const std::string> passthrough,
60536063

60546064
auto filter_match = [&](const mcpp::build::LinkUnit& lu) {
60556065
return lu.kind == mcpp::build::LinkUnit::TestBinary
6056-
&& (testOpts.filter.empty()
6057-
|| lu.targetName.find(testOpts.filter) != std::string::npos);
6066+
&& test_matches(lu, testOpts.filter);
60586067
};
60596068

60606069
// ── built at the same time, a thread per leg ──
@@ -6225,9 +6234,16 @@ export void run_workspace_tests(std::span<const std::string> passthrough,
62256234
indexOf[members[i].path] = i;
62266235
if (!members[i].error.empty()) { slots[i].error = members[i].error; continue; }
62276236
if (members[i].targets.empty()) { slots[i].note = members[i].noTests; continue; }
6228-
if (!testOpts.filter.empty()
6229-
&& std::ranges::none_of(members[i].targets, [&](auto const& t) {
6230-
return t.name.find(testOpts.filter) != std::string::npos; })) {
6237+
// As `test_matches' asks of a planned test: the program, or a part of it.
6238+
auto names_it = [&](const mcpp::manifest::Target& t) {
6239+
if (t.name.find(testOpts.filter) != std::string::npos) return true;
6240+
auto part = [&](const std::string& f) {
6241+
return std::format("{}/{}", t.name, std::filesystem::path(f).stem().generic_string())
6242+
.find(testOpts.filter) != std::string::npos;
6243+
};
6244+
return part(t.main) || std::ranges::any_of(t.testSources, part);
6245+
};
6246+
if (!testOpts.filter.empty() && std::ranges::none_of(members[i].targets, names_it)) {
62316247
slots[i].noMatch = true;
62326248
continue;
62336249
}
@@ -6420,8 +6436,7 @@ export void run_workspace_tests(std::span<const std::string> passthrough,
64206436
test_bulk(tb, testOpts, [&](const mcpp::build::LinkUnit& lu) {
64216437
return lu.kind == mcpp::build::LinkUnit::TestBinary
64226438
&& runnable.contains(lu.memberOf)
6423-
&& (testOpts.filter.empty()
6424-
|| lu.targetName.find(testOpts.filter) != std::string::npos);
6439+
&& test_matches(lu, testOpts.filter);
64256440
});
64266441
if (!runnable.empty()) test_resolve_runner(tb, testOpts, json);
64276442
}

‎src/build/prepare/graph.cpp‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -824,28 +824,6 @@ step4b_resolve_identity(PrepareState& state, WorklistItemCtx& ctx) {
824824
return {};
825825
}
826826

827-
// THE PACKAGE BEING BUILT STANDS FOR ITSELF IN ITS TESTS' GRAPH. A dependency
828-
// reached through its `[dev-dependencies]` may name it: a library tested with a
829-
// framework that itself uses the library (mcpplibs.os under mtest). A second
830-
// copy from the index would provide every module of the package twice in one
831-
// program, and what is under test is the package as it is here; so the edge is
832-
// the root's, whatever version it asked for, and a version it did not ask for
833-
// is said. Outside the tests' graph such an edge is a cycle, refused as one.
834-
static bool step4b_names_the_root(PrepareState& state, const WorklistItemCtx& ctx) {
835-
const auto& item = ctx.item;
836-
const auto& root = state.m->package;
837-
if (!item.devOnly || item.consumerDepIndex == kMainConsumer || root.virtualRoot || !ctx.key.variant.empty()
838-
|| ctx.key.shortName != root.name || ctx.key.ns != root.namespace_)
839-
return false;
840-
recordDependencyEdge(state, item.consumerDepIndex, 0, item.spec, item.fromBuildTable, item.name);
841-
if (!item.originalConstraint.empty() && item.originalConstraint != root.version
842-
&& item.originalConstraint != "*")
843-
mcpp::ui::note(std::format(
844-
"{} asks for {} {}; it is the package being built, {}, which stands for itself",
845-
item.requestedBy, state.qualifiedKey(ctx.key), item.originalConstraint, root.version));
846-
return true;
847-
}
848-
849827
static std::expected<void, std::string>
850828
step4b_identity_version_merge(PrepareState& state, WorklistItemCtx& ctx,
851829
std::map<ResolvedKey, ResolvedRecord>::iterator it) {
@@ -2126,7 +2104,7 @@ static std::expected<void, std::string> step4b_cycle_check(PrepareState& state)
21262104
// build-only ones included, as the key walk counts them -- but the root's
21272105
// own `[dev-dependencies]`: they serve its tests, which no package
21282106
// depends on, so a framework that uses the package under test reaches its
2129-
// library and not back through the tests (step4b_names_the_root).
2107+
// library and not back through the tests (names_the_root, graph_edges.cpp).
21302108
{
21312109
mcpp::graph::AdjacencyList deps(state.packages.size());
21322110
for (auto const& e : state.dependencyEdges) {
@@ -2465,7 +2443,7 @@ std::expected<void, std::string> phase4b_graph_worklist(PrepareState& state) {
24652443

24662444
if (auto r = step4b_resolve_identity(state, ctx); !r)
24672445
return std::unexpected(r.error());
2468-
if (step4b_names_the_root(state, ctx)) continue;
2446+
if (names_the_root(state, ctx.item, ctx.key)) continue;
24692447

24702448
if (auto it = state.resolved.find(ctx.key); it != state.resolved.end()) {
24712449
if (auto r = step4b_handle_already_resolved(state, ctx, it); !r)

‎src/build/prepare/graph_edges.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import std;
1010
import mcpp.manifest;
1111
import mcpp.modgraph.graph;
1212
import mcpp.pm.dep_spec;
13+
import mcpp.ui;
1314

1415
namespace mcpp::build {
1516

@@ -136,6 +137,28 @@ void recordDependencyEdge(
136137
});
137138
}
138139

140+
// THE PACKAGE BEING BUILT STANDS FOR ITSELF IN ITS TESTS' GRAPH. A dependency
141+
// reached through its `[dev-dependencies]` may name it: a library tested with a
142+
// framework that itself uses the library (mcpplibs.os under mtest). A second
143+
// copy from the index would provide every module of the package twice in one
144+
// program, and what is under test is the package as it is here; so the edge is
145+
// the root's, whatever version it asked for, and a version it did not ask for
146+
// is said. Outside the tests' graph such an edge is a cycle, refused as one.
147+
bool names_the_root(PrepareState& state, const WorkItem& item, const ResolvedKey& key) {
148+
const auto& root = state.m->package;
149+
if (!item.devOnly || item.consumerDepIndex == kMainConsumer || root.virtualRoot || !key.variant.empty()
150+
|| key.shortName != root.name || key.ns != root.namespace_)
151+
return false;
152+
recordDependencyEdge(state, item.consumerDepIndex, 0, item.spec, item.fromBuildTable, item.name);
153+
if (!item.originalConstraint.empty() && item.originalConstraint != root.version
154+
&& item.originalConstraint != "*")
155+
mcpp::ui::note(std::format(
156+
"{} asks for {} {}; it is the package being built, {}, which stands for itself",
157+
item.requestedBy, state.qualifiedKey(key), item.originalConstraint, root.version));
158+
return true;
159+
}
160+
161+
139162
// The usage requirements every edge carries to its consumer: a dependency's
140163
// public usage reaches the consumer's own units (Private, Public), its users
141164
// (Public, Interface), or, on a dev edge, the consumer's tests only. A fixpoint

‎src/build/prepare/plan.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ static std::expected<void, std::string> step13_dependency_cache(PrepareState& st
17301730
// front standing in for the old in-progress guard.
17311731
// The root's own `[dev-dependencies]` serve its tests, not its
17321732
// library, which a framework that uses the package under test reaches
1733-
// (step4b_names_the_root): the root's key does not fold them in.
1733+
// (names_the_root, graph_edges.cpp): the root's key does not fold them in.
17341734
auto serves_root_tests = [](const auto& e) {
17351735
return e.consumerPackageIndex == 0 && e.devTable;
17361736
};

‎src/build/prepare/state.cppm‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ void recordDependencyEdge(PrepareState& state, std::size_t consumerDepIndex,
10131013
std::size_t dependencyPackageIndex,
10141014
const mcpp::manifest::DependencySpec& spec, bool buildTable,
10151015
const std::string& writtenKey);
1016+
// graph_edges.cpp: the package being built stands for itself in its tests'
1017+
// graph -- an edge reached through its `[dev-dependencies]` naming it is its
1018+
// own, recorded here; true when the request is so answered.
1019+
bool names_the_root(PrepareState& state, const WorkItem& item, const ResolvedKey& key);
10161020
// graph_edges.cpp: defines `PrepareState::computeUsageRequirements`.
10171021
void define_usage_requirements(PrepareState& state);
10181022
std::expected<void, std::string> phase4b_graph_worklist(PrepareState& state);

‎tests/e2e/1038_test_programs_of_a_directory_and_the_tests_a_change_affects.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ printf '\n[test]\nprograms = "directory"\n' >> mcpp.toml
5454
# A program that speaks the protocol runs as a process per file of its cases (`split = "file"`).
5555
grep -q 'unit/a \.\.\. ok (.*1 case)' a.log && grep -q 'unit/b \.\.\. ok (.*1 case)' a.log \
5656
|| fail "A: unit does not run as a process per file" a.log
57+
# A pattern names a part as the run names it.
58+
"$MCPP" test unit/b > a-part.log 2>&1 || fail "A: a part named by its pattern" a-part.log
59+
grep -q 'unit/b \.\.\. ok' a-part.log && ! grep -q 'unit/a \.\.\.' a-part.log \
60+
|| fail "A: the pattern of a part did not run that part alone" a-part.log
5761
printf 'split = "none"\n' >> mcpp.toml
5862
"$MCPP" test > a.log 2>&1 || fail "A: the directory programs, run once" a.log
5963
grep -q 'unit \.\.\. ok (.*2 cases)' a.log || fail "A: unit is not one program of two cases" a.log

0 commit comments

Comments
 (0)