Skip to content

Commit bd9b389

Browse files
committed
test: a suite run as a case is counted by its cases on the program's line, as the summary counts it
1 parent 19d3272 commit bd9b389

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
not yet filled is absent. Before, only the declared directories were judged, by existence,
1515
so a reader beside a first fetch skipped the refresh and reported no local package index
1616
(mcpp#927, design 2026-11-12 §18 P3).
17+
- `mcpp test` counts a suite run as a case by its cases on the program's line as the summary
18+
does: an mtest program of one suite and seven cases read `8 cases` on its line and
19+
`7 passed` in the summary.
1720

1821
## [2026.11.21.1] - 2026-11-21
1922

‎src/build/execute.cppm‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5486,6 +5486,16 @@ static void test_resolve_runner(TestBuild& tb, const TestOptions& testOpts, bool
54865486
}
54875487
}
54885488

5489+
// A CASE THAT DECLARES CASES (a suite run as a case) is told by them: neither a
5490+
// program's line nor the run's summary counts it beside them, so that the two
5491+
// counts of one run agree (an mtest program of one suite and seven cases read
5492+
// `8 cases` on its line and `7 passed` in the summary).
5493+
bool declares_cases(const mcpp::build::test_protocol::Report& rep, const std::string& id) {
5494+
return std::ranges::any_of(rep.cases, [&](const auto& c) {
5495+
return c.id.size() > id.size() && c.id.starts_with(id) && c.id[id.size()] == '/';
5496+
});
5497+
}
5498+
54895499
// A failed test whose file imports a module no package of this build provides:
54905500
// the compiler says only that the module was not built. A test's framework is a
54915501
// `[dev-dependencies]` entry (docs/08), which a manifest written over the
@@ -6007,8 +6017,10 @@ static int test_run_member(TestBuild& tb, const TestOptions& testOpts,
60076017
report = {};
60086018
spoken = 0;
60096019
} else {
6010-
casesNote = std::format(", {} case{}", report.cases.size(),
6011-
report.cases.size() == 1 ? "" : "s");
6020+
const auto told = std::ranges::count_if(report.cases, [&](const auto& c) {
6021+
return !declares_cases(report, c.id);
6022+
});
6023+
casesNote = std::format(", {} case{}", told, told == 1 ? "" : "s");
60126024
if (exitCode == 0 && !timedOut && report.failed()) exitCode = 1;
60136025
}
60146026
}
@@ -6858,15 +6870,10 @@ static int test_run_member(TestBuild& tb, const TestOptions& testOpts,
68586870

68596871
// THE CASES, BESIDE THE PROGRAMS THE COUNT ABOVE IS OF. A case that
68606872
// declared cases (a suite run as a case) is told by them, not counted.
6861-
auto declares = [](const mcpp::build::test_protocol::Report& rep, const std::string& id) {
6862-
return std::ranges::any_of(rep.cases, [&](const auto& c) {
6863-
return c.id.size() > id.size() && c.id.starts_with(id) && c.id[id.size()] == '/';
6864-
});
6865-
};
68666873
int casesPassed = 0, casesFailed = 0, casesSkipped = 0;
68676874
for (auto& r : results)
68686875
for (const auto& c : r.report.cases) {
6869-
if (declares(r.report, c.id)) continue;
6876+
if (declares_cases(r.report, c.id)) continue;
68706877
if (c.status == "pass" || c.status == "xfail") ++casesPassed;
68716878
else if (c.status == "fail" || c.status == "xpass") ++casesFailed;
68726879
else if (c.status == "skip") ++casesSkipped;
@@ -6905,7 +6912,7 @@ static int test_run_member(TestBuild& tb, const TestOptions& testOpts,
69056912
continue;
69066913
std::println(" {}", r.name);
69076914
for (const auto& c : r.report.cases) {
6908-
if ((c.status != "fail" && c.status != "xpass") || declares(r.report, c.id)) continue;
6915+
if ((c.status != "fail" && c.status != "xpass") || declares_cases(r.report, c.id)) continue;
69096916
if (c.failures.empty())
69106917
std::println(" {} {}", c.id, c.status == "xpass" ? "passed, expected to fail"
69116918
: c.reason.empty() ? std::string("failed") : c.reason);

‎tests/e2e/test/protocol.cpp‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test programs that speak mtest's test protocol: their cases, live case records, the spec's
22
// launch, capabilities, checks and output (formerly tests/e2e/1035, 1065 and 1070); run fixtures;
3-
// the time the kit gives a command within its case.
3+
// the time the kit gives a command within its case; a suite counted by its cases.
44
import std;
55
import mcpplibs.mtest;
66
import mcpp.test.support;
@@ -470,6 +470,27 @@ int main() {{
470470
// the program without the case's report of a hung command: ten minutes bound it.
471471
expect(fatal(s::mcpp_command({"--version"}, s::case_dir()).timeout == std::chrono::minutes{10}));
472472
};
473+
474+
"1143 a suite is told by its cases on the program's line and in the summary"_test = [] {
475+
// An mtest program of one suite of two cases and one case alone reports four cases, the
476+
// suite among them; the suite is told by its cases, so the program's line and the run's
477+
// summary both count three (an mtest program of one suite and seven cases read `8 cases`
478+
// on its line and `7 passed` in the summary, 2026.11.21.1).
479+
auto p = s::project::scaffold("suites");
480+
for (const auto& f : s::glob(p.at("tests"), "*.cpp")) fs::remove(f);
481+
p.write("tests/cases.cpp", R"(import mcpplibs.mtest;
482+
using namespace mcpplibs::mtest;
483+
UTest suite{"suite", [] {
484+
"first"_test = [] { expect(eq(1, 1)); };
485+
"second"_test = [] { expect(eq(2, 2)); };
486+
}};
487+
UTest alone{"alone", [] { expect(eq(3, 3)); }};
488+
)");
489+
auto r = p.mcpp({"test"});
490+
expect(fatal(e2e::succeeded(r))) << s::text(r);
491+
expect(s::has_line(s::text(r), R"(cases \.\.\. ok \([0-9.]+s, 3 cases\))")) << "the program's line counts the suite: " << s::text(r);
492+
expect(e2e::contains(s::text(r), "cases: 3 passed, 0 failed, 0 skipped")) << s::text(r);
493+
};
473494
}};
474495

475496
} // namespace

0 commit comments

Comments
 (0)