@@ -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.
42874296struct 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 }
0 commit comments